├── VERSION ├── lib ├── ratch.yml ├── ratch │ ├── core_ext.rb │ ├── core_ext │ │ ├── to_yamlfrag.rb │ │ ├── to_list.rb │ │ ├── to_actual_filename.rb │ │ ├── unfold_paragraphs.rb │ │ ├── facets.rb │ │ ├── filetest.rb │ │ └── to_console.rb │ ├── utils │ │ ├── pom.rb │ │ ├── cli.rb │ │ ├── xdg.rb │ │ ├── zlib.rb │ │ ├── rdoc.rb │ │ ├── config.rb │ │ ├── tar.rb │ │ └── ftp.rb │ ├── system.rb │ ├── script │ │ └── help.rb │ ├── script.rb │ ├── shellutils.rb │ ├── console.rb │ └── shell_utils0.rb └── ratch.rb ├── spec ├── 04_system.rdoc ├── applique │ ├── array.rb │ └── setup.rb ├── 02_script.rdoc ├── 03_batch.rdoc └── 01_shell.rdoc ├── site ├── .htaccess ├── assets │ ├── images │ │ ├── icon.png │ │ ├── logo.png │ │ ├── head1.jpg │ │ ├── head2.jpg │ │ ├── mnu_bkg.jpg │ │ ├── ruby-sm.png │ │ ├── toolbox.jpg │ │ ├── abstract.jpg │ │ ├── icon │ │ │ ├── book.jpg │ │ │ ├── logo.png │ │ │ ├── license.png │ │ │ ├── source.png │ │ │ ├── logohover.png │ │ │ ├── development.png │ │ │ └── download_arrow.gif │ │ ├── ratch-bg.png │ │ ├── ratch-sm.png │ │ └── rivet │ │ │ ├── doc.png │ │ │ ├── gears.png │ │ │ ├── star.png │ │ │ └── wizard.png │ └── styles │ │ └── style.css ├── .rsync-filter └── index.html ├── test ├── utils │ ├── case_cli.rb │ ├── case_ftp.rb │ ├── case_tar.rb │ ├── fixtures │ │ ├── pom_sample │ │ │ └── Profile │ │ └── rdoc_sample │ │ │ ├── README.rdoc │ │ │ └── lib │ │ │ └── rdoc_sample │ │ │ └── rdoc_sample.rb │ ├── case_email.rb │ ├── case_zlib.rb │ ├── case_config.rb │ ├── case_pom.rb │ └── case_rdoc.rb ├── helper.rb ├── case_shell.rb └── case_batch.rb ├── .gitignore ├── work ├── ideas │ ├── phase-based-build-tasks │ │ └── task │ │ │ ├── dummy.rtc │ │ │ ├── rdoc.rtc │ │ │ ├── box.rtc │ │ │ └── main.rtc │ ├── system-wide-batch-commands │ │ ├── plugins │ │ │ └── rbat │ │ │ │ ├── demo │ │ │ │ └── help │ │ └── bin │ │ │ ├── rbat │ │ │ └── rbat2 │ ├── class-per-file-object │ │ └── lib │ │ │ └── ratch │ │ │ ├── socket.rb │ │ │ ├── pipe.rb │ │ │ ├── errors.rb │ │ │ ├── device.rb │ │ │ ├── link.rb │ │ │ ├── finder.rb │ │ │ ├── file.rb │ │ │ ├── dir.rb │ │ │ └── entry.rb │ ├── extension-plugin │ │ ├── service.rb │ │ ├── ratchet.rb │ │ ├── serviceX.rb │ │ └── plugin.rb │ └── task-extension │ │ ├── test_task.rb │ │ ├── task.rb │ │ └── task2.rb ├── consider │ ├── bin │ │ └── lt │ ├── pathglob.rb │ └── lib │ │ ├── ratch │ │ └── utils │ │ │ ├── box.rb │ │ │ ├── zip.rb │ │ │ ├── ui.rb │ │ │ ├── rcov.rb │ │ │ ├── md5.rb │ │ │ ├── log.rb │ │ │ ├── xdg.rb │ │ │ └── rdoc.rb │ │ ├── pathlist.rb │ │ └── fileable.rb ├── trash │ └── DONE │ │ ├── commands │ │ ├── rdoc.rb │ │ ├── zip.rb │ │ ├── gzip.rb │ │ ├── xdg.rb │ │ ├── tar.rb │ │ ├── ftp.rb │ │ └── email.rb │ │ ├── pathname.rb │ │ ├── vendor │ │ └── xdg.rb │ │ └── pathlist.rb ├── deprecated │ ├── runmode.rb │ ├── cli.rb │ ├── io.rb │ └── batch.rb └── reference │ ├── layout.xsl │ ├── started.xml │ └── console.rb ├── bin ├── ratch └── ludo ├── try ├── tryme-task.ratch └── tryme1.ratch ├── man └── ratch.1 ├── PROFILE ├── HISTORY.rdoc ├── task └── test.watchr ├── MANIFEST ├── Assembly ├── .ruby ├── README.rdoc └── .gemspec /VERSION: -------------------------------------------------------------------------------- 1 | 1.2.0 2 | -------------------------------------------------------------------------------- /lib/ratch.yml: -------------------------------------------------------------------------------- 1 | ../.ruby -------------------------------------------------------------------------------- /spec/04_system.rdoc: -------------------------------------------------------------------------------- 1 | = Ratch::System 2 | 3 | 4 | -------------------------------------------------------------------------------- /site/.htaccess: -------------------------------------------------------------------------------- 1 | DirectoryIndex index.xml index.html 2 | 3 | -------------------------------------------------------------------------------- /test/utils/case_cli.rb: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | KO.case "Ratch::CLI" do 4 | 5 | end 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | doc/rdoc 3 | doc/ri 4 | log 5 | pkg 6 | tmp 7 | site/documentation 8 | -------------------------------------------------------------------------------- /test/utils/case_ftp.rb: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | KO.case "Ratch::FTPUtils" do 4 | 5 | end 6 | 7 | -------------------------------------------------------------------------------- /test/utils/case_tar.rb: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | KO.case "Ratch::TarUtils" do 4 | 5 | end 6 | 7 | -------------------------------------------------------------------------------- /work/ideas/phase-based-build-tasks/task/dummy.rtc: -------------------------------------------------------------------------------- 1 | analyize: 2 | puts "Happy Days!" 3 | 4 | -------------------------------------------------------------------------------- /bin/ratch: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'ratch/script' 3 | Ratch::Script.execute(ARGV.shift) 4 | -------------------------------------------------------------------------------- /site/assets/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon.png -------------------------------------------------------------------------------- /site/assets/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/logo.png -------------------------------------------------------------------------------- /site/assets/images/head1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/head1.jpg -------------------------------------------------------------------------------- /site/assets/images/head2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/head2.jpg -------------------------------------------------------------------------------- /site/assets/images/mnu_bkg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/mnu_bkg.jpg -------------------------------------------------------------------------------- /site/assets/images/ruby-sm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/ruby-sm.png -------------------------------------------------------------------------------- /site/assets/images/toolbox.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/toolbox.jpg -------------------------------------------------------------------------------- /lib/ratch/core_ext.rb: -------------------------------------------------------------------------------- 1 | Dir[File.dirname(__FILE__) + '/core_ext/**/*.rb'].each do |file| 2 | require file 3 | end 4 | -------------------------------------------------------------------------------- /site/assets/images/abstract.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/abstract.jpg -------------------------------------------------------------------------------- /site/assets/images/icon/book.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon/book.jpg -------------------------------------------------------------------------------- /site/assets/images/icon/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon/logo.png -------------------------------------------------------------------------------- /site/assets/images/ratch-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/ratch-bg.png -------------------------------------------------------------------------------- /site/assets/images/ratch-sm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/ratch-sm.png -------------------------------------------------------------------------------- /site/assets/images/rivet/doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/rivet/doc.png -------------------------------------------------------------------------------- /test/helper.rb: -------------------------------------------------------------------------------- 1 | puts "Ruby v#{RUBY_VERSION}" 2 | 3 | $LOAD_PATH.unshift(File.dirname('__FILE__') + '/../lib') 4 | 5 | -------------------------------------------------------------------------------- /test/utils/fixtures/pom_sample/Profile: -------------------------------------------------------------------------------- 1 | --- 2 | name : pom_sample 3 | title : POM Sample 4 | version : 1.0 5 | -------------------------------------------------------------------------------- /site/assets/images/icon/license.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon/license.png -------------------------------------------------------------------------------- /site/assets/images/icon/source.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon/source.png -------------------------------------------------------------------------------- /site/assets/images/rivet/gears.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/rivet/gears.png -------------------------------------------------------------------------------- /site/assets/images/rivet/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/rivet/star.png -------------------------------------------------------------------------------- /site/assets/images/rivet/wizard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/rivet/wizard.png -------------------------------------------------------------------------------- /site/.rsync-filter: -------------------------------------------------------------------------------- 1 | - .svn 2 | - scrap 3 | P wiki 4 | P robot.txt 5 | P robots.txt 6 | P statcvs 7 | P statsvn 8 | P usage 9 | -------------------------------------------------------------------------------- /site/assets/images/icon/logohover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon/logohover.png -------------------------------------------------------------------------------- /site/assets/images/icon/development.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon/development.png -------------------------------------------------------------------------------- /site/assets/images/icon/download_arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubyworks/ratch/master/site/assets/images/icon/download_arrow.gif -------------------------------------------------------------------------------- /test/utils/fixtures/rdoc_sample/README.rdoc: -------------------------------------------------------------------------------- 1 | = RDOC Sample 2 | 3 | This is a sample RDoc document used to test the RDoc utility. 4 | 5 | -------------------------------------------------------------------------------- /work/ideas/system-wide-batch-commands/plugins/rbat/demo: -------------------------------------------------------------------------------- 1 | # demo -- silly demo script 2 | # ========================= 3 | 4 | puts "DEMO!" 5 | 6 | -------------------------------------------------------------------------------- /test/utils/case_email.rb: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | KO.case "Ratch::EMailUtils" do 4 | 5 | setup do 6 | #p Dir.pwd 7 | end 8 | 9 | end 10 | 11 | -------------------------------------------------------------------------------- /lib/ratch/core_ext/to_yamlfrag.rb: -------------------------------------------------------------------------------- 1 | class Object 2 | 3 | # 4 | def to_yamlfrag 5 | to_yaml.sub("---",'').rstrip 6 | end 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /spec/applique/array.rb: -------------------------------------------------------------------------------- 1 | class ::Array 2 | 3 | # Helper extension for comparison tests. 4 | def to_pathnames 5 | map{ |f| Pathname.new(f) } 6 | end 7 | 8 | end 9 | -------------------------------------------------------------------------------- /test/utils/case_zlib.rb: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | KO.case "Ratch::RDocUtils" do 4 | 5 | test "foo" do |val| 6 | val 7 | end 8 | 9 | ok true 10 | end 11 | 12 | -------------------------------------------------------------------------------- /try/tryme-task.ratch: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ratch 2 | 3 | task :hello do 4 | puts "Hello" 5 | end 6 | 7 | task :world => [:hello] do 8 | puts "World" 9 | end 10 | 11 | run :world 12 | 13 | -------------------------------------------------------------------------------- /try/tryme1.ratch: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ratch 2 | 3 | puts "Hello World" 4 | 5 | p arguments 6 | p quiet? 7 | p debug? 8 | 9 | define_method :okay do 10 | "okay" 11 | end 12 | 13 | p okay 14 | -------------------------------------------------------------------------------- /test/utils/case_config.rb: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | KO.case "Ratch::ConfigUtils" do 4 | 5 | #test "#configuration" do 6 | #end 7 | 8 | #test "configuration!" do 9 | #end 10 | 11 | end 12 | 13 | -------------------------------------------------------------------------------- /work/ideas/phase-based-build-tasks/task/rdoc.rtc: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | document: 4 | rdoc "README.rdoc", "lib", :output=>"doc/rdoc" 5 | 6 | clean: 7 | touch "doc/rdoc" 8 | 9 | reset: 10 | rm_r "doc/rdoc" 11 | 12 | -------------------------------------------------------------------------------- /work/consider/bin/lt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'ratch/help' 4 | 5 | dir = ARGV[0] || '.' 6 | 7 | if File.directory?(dir) 8 | Ratch.list(dir) 9 | else 10 | puts "#{dir} is not a directory" 11 | end 12 | 13 | -------------------------------------------------------------------------------- /work/ideas/phase-based-build-tasks/task/box.rtc: -------------------------------------------------------------------------------- 1 | package: 2 | box "gem", :output=>'pkg' 3 | box "tar", :output=>'pkg' 4 | #box "zip", :output=>'pkg' 5 | 6 | clean: 7 | rm_r "pkg/*.gem" 8 | rm_r "pkg/*.tar.gz" 9 | rm_r "pkg/*.zip 10 | 11 | -------------------------------------------------------------------------------- /work/ideas/class-per-file-object/lib/ratch/socket.rb: -------------------------------------------------------------------------------- 1 | require 'folio/fileobject' 2 | 3 | module Folio 4 | 5 | class Socket < FileObject 6 | 7 | def initialize(path) 8 | raise 'Sockets not yet supported.' 9 | end 10 | 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /test/utils/fixtures/rdoc_sample/lib/rdoc_sample/rdoc_sample.rb: -------------------------------------------------------------------------------- 1 | # This is dummy module for testing the rdoc utility. 2 | module RDocSample 3 | 4 | # This is a dummy method for testing the rdoc utility. 5 | def self.hello_world 6 | puts "Hello World" 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /test/utils/case_pom.rb: -------------------------------------------------------------------------------- 1 | require 'ratch' 2 | 3 | KO.case "Ratch::POMUtils" do 4 | 5 | def initialize 6 | stage_copy 'fixtures/pom_sample' 7 | 8 | @shell = Ratch::Shell.new 9 | @shell.extend(Ratch::POMUtils) 10 | end 11 | 12 | test :project do 13 | @shell.project.is_a?(::POM::Project) 14 | end 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /work/consider/pathglob.rb: -------------------------------------------------------------------------------- 1 | require 'ratch/ruby/pathname' 2 | 3 | # = Pathglob 4 | # 5 | # A lazy resolution variation of Pathname. 6 | # 7 | # TODO: Is there any way to integrate this into Pathname itself 8 | # as a mode of operation? 9 | class Pathglob < Pathname 10 | 11 | def to_s 12 | Dir.glob(super).first 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /bin/ludo: -------------------------------------------------------------------------------- 1 | #! /usr/bin/ruby1.8 2 | 3 | # for FileTest.root? 4 | require 'facets/filetest' 5 | 6 | name = ARGV[0] 7 | 8 | if name 9 | Dir.chdir '..' until FileTest.executable?(name) or FileTest.root?(Dir.pwd) 10 | if FileTest.executable?( name ) 11 | system name 12 | end 13 | else 14 | puts "Script #{name} not found." 15 | end 16 | 17 | -------------------------------------------------------------------------------- /work/ideas/class-per-file-object/lib/ratch/pipe.rb: -------------------------------------------------------------------------------- 1 | require 'folio/fileobject' 2 | 3 | module Folio 4 | 5 | # = Pipe 6 | # 7 | # Is this the same as a FIFO? 8 | # 9 | class Pipe < FileObject 10 | 11 | def initialize(path) 12 | raise 'Pipes not yet supported.' 13 | end 14 | 15 | def pipe? ; true ; end 16 | 17 | end 18 | 19 | end 20 | 21 | -------------------------------------------------------------------------------- /lib/ratch/utils/pom.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # Methods for utilizing Ruby POM. 4 | module POMUtils 5 | 6 | def self.included(base) 7 | require 'pom' 8 | end 9 | 10 | def self.extended(base) 11 | included(base) 12 | end 13 | 14 | # 15 | def project 16 | @project ||= ::POM::Project.new 17 | end 18 | 19 | end 20 | 21 | end 22 | 23 | -------------------------------------------------------------------------------- /lib/ratch/system.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # TODO: Build it! 4 | # 5 | # The System class provides a robust interface for interacting with 6 | # system commands. It is essenatially a wrapper around popen3 or popen4. 7 | # 8 | # Having a separate class rather integrating this into Shell (as 9 | # Ruby's standard Shell class does) provides a better SOC. 10 | # 11 | class System 12 | 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /work/ideas/phase-based-build-tasks/task/main.rtc: -------------------------------------------------------------------------------- 1 | stage :document 2 | 3 | rdoc :output => 'site/rdoc' 4 | ridoc :output => 'doc/ri' 5 | stats 6 | notes 7 | 8 | stage :validate 9 | 10 | respect "test/*" 11 | 12 | stage :package 13 | 14 | box tar 15 | box gem 16 | 17 | stage :release 18 | 19 | rubyforge.release 20 | 21 | stage :promote 22 | 23 | rubyforge.announce 24 | # email ruby-talk@ruby-lang.org 25 | 26 | -------------------------------------------------------------------------------- /work/ideas/class-per-file-object/lib/ratch/errors.rb: -------------------------------------------------------------------------------- 1 | module Folio 2 | 3 | class FileNotFound < ::IOError 4 | def initialize(path=nil) 5 | @path = path 6 | super 7 | end 8 | 9 | def to_str 10 | if @path 11 | "file not found -- #{@path}" 12 | else 13 | "file not found" 14 | end 15 | end 16 | end 17 | 18 | class DirNotFound < ::IOError 19 | end 20 | 21 | class LinkNotFound < ::IOError 22 | end 23 | 24 | end 25 | 26 | -------------------------------------------------------------------------------- /work/ideas/extension-plugin/service.rb: -------------------------------------------------------------------------------- 1 | require 'ratch/script' 2 | 3 | module Ratch 4 | 5 | # = Service 6 | 7 | class Service < Script 8 | 9 | private 10 | 11 | # 12 | def initialize(options=nil) 13 | options ||= {} 14 | 15 | initialize_defaults 16 | 17 | options.each do |k, v| 18 | send("#{k}=", v) if respond_to?("#{k}=") 19 | end 20 | end 21 | 22 | # 23 | def initialize_defaults 24 | end 25 | 26 | end 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /lib/ratch/core_ext/to_list.rb: -------------------------------------------------------------------------------- 1 | class Array 2 | 3 | def to_list 4 | self 5 | end 6 | 7 | end 8 | 9 | class NilClass 10 | 11 | def to_list 12 | [] 13 | end 14 | 15 | end 16 | 17 | class String 18 | 19 | # Helper method for cleaning list options. 20 | # This will split the option on ':' or ';' 21 | # if it is a string, rather than an array. 22 | # And it will make sure there are no nil elements. 23 | 24 | def to_list 25 | split(/[:;,\n]/) 26 | end 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /work/ideas/extension-plugin/ratchet.rb: -------------------------------------------------------------------------------- 1 | require 'ratch/plugin' 2 | 3 | module Ratchet 4 | extend self 5 | 6 | # 7 | class Plugin < Ratch::Plugin 8 | 9 | def self.context 10 | @context ||= Script.new 11 | end 12 | 13 | # Not sure if we should cache plugins, but it's worth a shot. 14 | def self.new(options,&block) 15 | options = options.merge(block.to_h) if block 16 | @plugins[options] ||= super(context, options) 17 | end 18 | 19 | end 20 | 21 | end 22 | 23 | -------------------------------------------------------------------------------- /work/ideas/class-per-file-object/lib/ratch/device.rb: -------------------------------------------------------------------------------- 1 | require 'folio/fileobject' 2 | 3 | module Folio 4 | 5 | # Device base class 6 | class Device < FileObject 7 | 8 | def initialize(path) 9 | raise 'Devices not yet supported.' 10 | end 11 | 12 | end 13 | 14 | # Character device 15 | class CharacterDevice < Device 16 | 17 | def chardev? ; true ; end 18 | 19 | end 20 | 21 | # Block device 22 | class BlockDevice < Device 23 | 24 | def blockdev? ; true ; end 25 | 26 | end 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /work/trash/DONE/commands/rdoc.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | class Shell 4 | 5 | # 6 | def rdoc(*files_options) 7 | options = Hash===options.last ? options.pop : {} 8 | options.rekey! 9 | 10 | options[:debug] ||= debug? 11 | options[:quiet] ||= quiet? 12 | options[:verbose] ||= verbose? 13 | 14 | files = files_options 15 | 16 | locally do 17 | rdoc = RDoc::RDoc.new 18 | rdoc.document(options.to_argv + files) 19 | end 20 | end 21 | 22 | end 23 | 24 | end 25 | 26 | -------------------------------------------------------------------------------- /lib/ratch/core_ext/to_actual_filename.rb: -------------------------------------------------------------------------------- 1 | class String 2 | 3 | # Find actual filename (casefolding) and returns it. 4 | # Returns nil if no file is found. 5 | 6 | def to_actual_filename 7 | Dir.glob(self, File::FNM_CASEFOLD).first 8 | end 9 | 10 | # Find actual filename (casefolding) and replace string with it. 11 | # If file not found, string remains the same and method returns nil. 12 | 13 | def to_actual_filename! 14 | filename = to_actual_filename 15 | replace(filename) if filename 16 | end 17 | 18 | end 19 | 20 | -------------------------------------------------------------------------------- /test/utils/case_rdoc.rb: -------------------------------------------------------------------------------- 1 | require 'ratch' 2 | 3 | KO.case "Ratch::RDocUtils" do 4 | 5 | def initialize #before :all do 6 | @shell = Ratch::Shell.new 7 | @shell.extend(Ratch::RDocUtils) 8 | end 9 | 10 | setup do 11 | stage_copy 'fixtures/rdoc_sample' 12 | end 13 | 14 | test "#rdoc" do 15 | @shell.rdoc('README.rdoc', 'lib') 16 | File.directory?('doc') && 17 | File.directory?('doc/classes') && 18 | File.directory?('doc/files') && 19 | File.file?('doc/classes/RDocSample.html') 20 | end 21 | 22 | end 23 | 24 | -------------------------------------------------------------------------------- /spec/applique/setup.rb: -------------------------------------------------------------------------------- 1 | require 'fileutils' 2 | 3 | Before :demo do 4 | clear_working_directory! 5 | end 6 | 7 | When "consisting of the following entires" do |text| 8 | text.split(/\s+/).each do |file| 9 | if /\/$/ =~ file 10 | FileUtils.mkdir_p(file) unless File.directory?(file) 11 | else 12 | File.open(file, 'w+'){ |f| f << "SAMPLE #{file}".upcase } 13 | end 14 | end 15 | end 16 | 17 | When "Let's say we have a Ratch script called '(((.*?)))'" do |file, text| 18 | File.open(file, 'w'){ |f| f << text } 19 | end 20 | 21 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/box.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Generate Packages using Box packaging tool. 3 | # 4 | def box(options) 5 | require 'box' 6 | 7 | opts = options.rekey 8 | 9 | types = opts.delete(:types) 10 | 11 | # TODO: Add MANIFEST generation here if requested. 12 | 13 | options[:types].each do |type| 14 | case type 15 | when 'zip' 16 | Box::Zip.new(loc, opts).package 17 | when 'tar' 18 | Box::Tar.new(loc, opts).package 19 | when 'gem' 20 | Box::Gem.new(loc, opts).package 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/ratch/core_ext/unfold_paragraphs.rb: -------------------------------------------------------------------------------- 1 | # TODO: Replace with facets/string/unfold 2 | 3 | class String 4 | 5 | # 6 | def unfold_paragraphs 7 | blank = false 8 | text = '' 9 | split(/\n/).each do |line| 10 | if /\S/ !~ line 11 | text << "\n\n" 12 | blank = true 13 | else 14 | if /^(\s+|[*])/ =~ line 15 | text << (line.rstrip + "\n") 16 | else 17 | text << (line.rstrip + " ") 18 | end 19 | blank = false 20 | end 21 | end 22 | text = text.gsub("\n\n\n","\n\n") 23 | return text 24 | end 25 | 26 | end 27 | 28 | -------------------------------------------------------------------------------- /work/ideas/system-wide-batch-commands/bin/rbat: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | path = ARGV.shift 4 | 5 | require 'plugin' 6 | name = ARGV.shift 7 | path = Dir['~/.config/rb/#{name}'].first 8 | path = path || Plugin.find("rb/#{name}").first # TODO: this is slow! 9 | loop do 10 | abort "command not found -- #{name}" unless path 11 | if File.directory?(path) 12 | name = File.join(name, ARGV.shift) 13 | path = Dir['~/.config/rb/#{name}'].first || Plugin.find("rb/#{name}").first 14 | else 15 | break 16 | end 17 | end 18 | $0 = path # bug in 1.8.7-p246 puts a size limit on $0 19 | require 'ratch/script' 20 | script = Ratch::Script.new 21 | script.instance_eval(File.read(path), path) 22 | -------------------------------------------------------------------------------- /lib/ratch/core_ext/facets.rb: -------------------------------------------------------------------------------- 1 | # I know some people will be deterred by the dependency on Facets b/c they 2 | # see it as a "heavy" dependency. But really that is far from true, consider 3 | # the facet that the following libs are all that it used. 4 | 5 | require 'facets/array/not_empty' 6 | require 'facets/dir/multiglob' # DEPRECATE: when new #glob is working. 7 | require 'facets/module/basename' 8 | require 'facets/module/alias_accessor' 9 | require 'facets/kernel/yes' # pulls in #ask and #no? too. 10 | require 'facets/kernel/silence' # FIXME ??? 11 | require 'facets/kernel/disable_warnings' 12 | 13 | require 'facets/pathname' 14 | require 'facets/filetest' 15 | require 'facets/fileutils' 16 | -------------------------------------------------------------------------------- /man/ratch.1: -------------------------------------------------------------------------------- 1 | .\" NAME 2 | .\" ratch - ruby-based batch files 3 | .\" 4 | .\" SYNOPSIS 5 | .\" reap [-n] [-h] [file] 6 | .\" 7 | .\" DESCRIPTION 8 | .\" Ratch is batch file system using a Ruby=based DSL. 9 | .\" 10 | .\" OPTIONS 11 | .\" -h help This option displays help. 12 | .\" -n dryrun Dry-run/no-harm mode. 13 | .\" 14 | .\" ENVIRONMENT 15 | .\" PAGER name of paging command, usually more(1), or less(1). If not set 16 | .\" falls back to more(1). 17 | .\" 18 | .\" EXAMPLES 19 | .\" Try this command to format this text itself: 20 | .\" 21 | .\" $ txt2man -h 2>&1 | txt2man -T 22 | .\" 23 | .\" SEE ALSO: 24 | .\" ruby(1). 25 | .\" 26 | .\" AUTHOR: 27 | .\" 7rans 28 | 29 | -------------------------------------------------------------------------------- /lib/ratch.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | # Access to project metadata. 3 | def self.metadata 4 | @metadata ||= ( 5 | require 'yaml' 6 | YAML.load(File.dirname(__FILE__) + '/ratch.yml') 7 | ) 8 | end 9 | 10 | # Access to project metadata via constants. 11 | def self.const_missing(name) 12 | metadata[name.to_s.downcase] || super(name) 13 | end 14 | 15 | # TODO: Only here b/c of issue with Ruby 1.8.x. 16 | VERSION = metadata['version'] 17 | end 18 | 19 | require 'ratch/script' 20 | 21 | # Load utility extension modules. 22 | require 'ratch/utils/cli' 23 | require 'ratch/utils/pom' 24 | require 'ratch/utils/rdoc' 25 | require 'ratch/utils/email' 26 | #require 'ratch/utils/tar' 27 | #require 'ratch/utils/zlib' 28 | 29 | -------------------------------------------------------------------------------- /work/ideas/system-wide-batch-commands/bin/rbat2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'plugin' 4 | 5 | name = ARGV.shift 6 | 7 | path = Dir['~/.config/rb/#{name}'].first 8 | 9 | path = path || Plugin.find("rb/#{name}").first # TODO: this is slow! 10 | 11 | loop do 12 | abort "command not found -- #{name}" unless path 13 | if File.directory?(path) 14 | name = File.join(name, ARGV.shift) 15 | path = Dir['~/.config/rb/#{name}'].first || Plugin.find("rb/#{name}").first 16 | else 17 | break 18 | end 19 | end 20 | 21 | $0 = path # bug in 1.8.7-p246 puts a size limit on $0 22 | 23 | require 'ratch/script' 24 | 25 | script = Ratch::Script.new 26 | 27 | script.instance_eval(File.read(path), path) 28 | 29 | #require 'ratch/script2' 30 | #load path 31 | -------------------------------------------------------------------------------- /lib/ratch/core_ext/filetest.rb: -------------------------------------------------------------------------------- 1 | module FileTest 2 | 3 | # Return a cached list of the PATH environment variable. 4 | # This is a support method used by #bin? 5 | def command_paths 6 | @command_paths ||= ENV['PATH'].split(/[:;]/) 7 | end 8 | 9 | # Is a file a bin/ executable? 10 | # 11 | # TODO: Make more robust. Probably needs to be fixed for Windows. 12 | def bin?(fname) 13 | is_bin = command_paths.any? do |f| 14 | FileTest.exist?(File.join(f, fname)) 15 | end 16 | #is_bin ? File.basename(fname) : false 17 | is_bin ? fname : false 18 | end 19 | 20 | ## Is a file a task? 21 | # 22 | #def task?(path) 23 | # task = File.dirname($0) + "/#{path}" 24 | # task.chomp!('!') 25 | # task if FileTest.file?(task) && FileTest.executable?(task) 26 | #end 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /work/ideas/system-wide-batch-commands/plugins/rbat/help: -------------------------------------------------------------------------------- 1 | # help(1) -- display available rb commands 2 | # ========================================= 3 | # 4 | # ## SYNOPSIS 5 | # 6 | # `rb help` 7 | # `rb help` [] 8 | # 9 | # ## DESCRIPTION 10 | # 11 | # **help** displays the available list of rb commands. 12 | # If `` is given, then the full help header for 13 | # that command will be displayed. 14 | 15 | require 'ratch/help' 16 | 17 | command = ARGV.shift 18 | 19 | if command 20 | file = nil 21 | file ||= Dir[File.expand_path("~/.config/rb/#{command}")].first 22 | file ||= Plugin.find("rb/#{command}").first 23 | 24 | puts Ratch::Help.header(file) 25 | else 26 | dirs = [] 27 | dirs << File.expand_path("~/.config/rb/") 28 | dirs << Plugin.find("rb") 29 | 30 | Ratch::Help.list(dirs, :all=>true) 31 | end 32 | -------------------------------------------------------------------------------- /PROFILE: -------------------------------------------------------------------------------- 1 | --- 2 | title : Ratch 3 | summary: Ruby-based Batch Scripting 4 | contact: trans 5 | 6 | requires: 7 | - facets 2.9.1+ 8 | - minitar 0.5.3+ 9 | - ko 1.2.0~ (test) 10 | - qed (test) 11 | - syckle (build) 12 | 13 | description: 14 | Ratch is a Ruby-based batch scripting language. 15 | It's a DSL over regular Ruby to make the life 16 | of the batch script writter easier. 17 | 18 | resources: 19 | home: http://rubyworks.github.org/ratch 20 | code: http://github.org/rubyworks/ratch 21 | mail: http://groups.gooogle.com/group/rubyworks-mailinglist 22 | 23 | repositories: 24 | public: git://github.com/rubyworks/ratch.git 25 | 26 | authors: 27 | - Trans 28 | 29 | created : 2009-09-22 30 | organization : RubyWorks 31 | license : Apache 2.0 32 | copyright : Copyright (c) 2009 Thomas Sawyer 33 | 34 | -------------------------------------------------------------------------------- /HISTORY.rdoc: -------------------------------------------------------------------------------- 1 | = RELEASE HISTORY 2 | 3 | == 1.2.0 | 2011-01-24 4 | 5 | Ratch has remerged with the Path gem (formerly Folio), and will be taking over 6 | for its services from here on. In the process the library has been further 7 | refined. 8 | 9 | Changes: 10 | 11 | * Essentially, the Path library has become Ratch. 12 | * Primary class are now Script and Shell. 13 | 14 | 15 | == 1.1.0 | 2008-11-21 16 | 17 | This is the second public release of Ratch. Folio is now used a Ratch's backend. 18 | Folio handles a great deal of what Ratch requires, so much of Ratch is now just 19 | a thin wrapper around Folio. 20 | 21 | Changes: 22 | 23 | * Overhauled system to use Folio on the backend. 24 | 25 | 26 | == 1.0.0 | 2009-09-22 27 | 28 | This is the initial stand-alone release of Path, a collection 29 | of Path-related classes partially spun-off from Ruby Facets 30 | and briefly called Folio. 31 | 32 | Changes: 33 | 34 | * Happy Birthday! 35 | 36 | -------------------------------------------------------------------------------- /work/ideas/extension-plugin/serviceX.rb: -------------------------------------------------------------------------------- 1 | require 'ratch/script' 2 | 3 | module Ratch 4 | 5 | # = Folio Service 6 | # 7 | # The Service class is a convenience base class 8 | # for other classes that require extensive access 9 | # to the file system. 10 | # 11 | # It creates a shell object and uses method_missing 12 | # to delegate to it. 13 | # 14 | class Service 15 | 16 | attr_accessor :noop, :verbose, :dryrun 17 | 18 | alias_method :noop?, :noop 19 | alias_method :verbose?, :verbose 20 | alias_method :dryrun?, :dryrun 21 | 22 | # Shell 23 | def shell 24 | @fio ||= Folio::Shell.new(:noop => noop, :verbose => verbose) 25 | end 26 | 27 | # Delegate to +shell+ if it responds to the missing method. 28 | def method_missing(s, *a, &b) 29 | if shell.respond_to?(s) 30 | shell.__send__(s, *a, &b) 31 | else 32 | super 33 | end 34 | end 35 | 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /test/case_shell.rb: -------------------------------------------------------------------------------- 1 | require 'ratch/shell' 2 | 3 | KO.case 'Shell' do 4 | 5 | test 'with no path given current working directory is used' do 6 | sh = Ratch::Shell.new 7 | sh.work == Pathname.new(Dir.pwd) 8 | end 9 | 10 | test :quiet? do |options| 11 | o = Hash[*options] 12 | sh = Ratch::Shell.new(o) 13 | sh.quiet? 14 | end 15 | 16 | ok [:quiet, true] 17 | 18 | test :trace? do |options| 19 | o = Hash[*options] 20 | sh = Ratch::Shell.new(o) 21 | sh.trace? 22 | end 23 | 24 | ok [:trace, true] 25 | 26 | test :noop? do |options| 27 | o = Hash[*options] 28 | sh = Ratch::Shell.new(o) 29 | sh.noop? 30 | end 31 | 32 | ok [:noop, true] 33 | 34 | test :dryrun? do |options| 35 | o = Hash[*options] 36 | sh = Ratch::Shell.new(o) 37 | sh.dryrun? 38 | end 39 | 40 | ok [:noop, true, :trace, true] 41 | ok [:dryrun, true] 42 | 43 | no [:noop, true] 44 | no [:verbose, true] 45 | 46 | end 47 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/zip.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # Method for zipping and unzipping files. 4 | # 5 | # TODO: replace with a pure ruby zip library 6 | module Zip 7 | 8 | # Zip 9 | # 10 | def zip(folder, file=nil, options={}) 11 | noop, verbose = *util_options(options) 12 | 13 | raise ArgumentError if folder == '.*' 14 | 15 | file ||= File.basename(File.expand_path(folder)) + '.zip' 16 | 17 | folder = localize(folder) 18 | file = localize(file) 19 | 20 | cmd = "zip -rqu #{file} #{folder}" 21 | puts cmd if verbose 22 | system cmd if !noop 23 | 24 | return file 25 | end 26 | 27 | # Unzip 28 | # 29 | def unzip(file, options={}) 30 | noop, verbose = *util_options(options) 31 | 32 | file = localize(file) 33 | 34 | cmd = "unzip #{file}" 35 | puts cmd if verbose 36 | system cmd if !noop 37 | end 38 | 39 | end 40 | 41 | end 42 | 43 | -------------------------------------------------------------------------------- /lib/ratch/utils/cli.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # TODO: How best to support CLI interface? 4 | module CLI 5 | 6 | # 7 | def self.included(base) 8 | require 'facets/argvector' 9 | end 10 | 11 | # 12 | def self.extended(base) 13 | require 'facets/argvector' 14 | end 15 | 16 | # 17 | def initialize(*args) 18 | argv = ArgVector.new(ARGV) 19 | 20 | @arguments, parameters = *argv.parameters 21 | 22 | args << {} unless Hash === args.last 23 | 24 | opts = args.last 25 | 26 | opts.merge!(parameters) 27 | 28 | super(*args) 29 | end 30 | 31 | # 32 | def arguments 33 | @arguments 34 | end 35 | 36 | # DEPRECATE! 37 | #alias_method :commandline, :cli 38 | 39 | # DEPRECATE! 40 | #alias_method :command, :cli 41 | 42 | # 43 | #def commandline 44 | # #@commandline ||= ArgVector.new(ARGV) 45 | # @commandline 46 | #end 47 | end 48 | 49 | end 50 | -------------------------------------------------------------------------------- /work/trash/DONE/commands/zip.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # TODO: Find way to zip without shelling-out. 3 | #++ 4 | module Ratch 5 | 6 | class Shell 7 | 8 | # Zip 9 | # 10 | # TODO: replace with a pure ruby zip library 11 | # 12 | def zip(folder, file=nil, options={}) 13 | noop, verbose = *util_options(options) 14 | 15 | raise ArgumentError if folder == '.*' 16 | 17 | file ||= File.basename(File.expand_path(folder)) + '.zip' 18 | 19 | folder = localize(folder) 20 | file = localize(file) 21 | 22 | cmd = "zip -rqu #{file} #{folder}" 23 | puts cmd if verbose 24 | system cmd if !noop 25 | 26 | return file 27 | end 28 | 29 | # Unzip 30 | # 31 | def unzip(file, options={}) 32 | noop, verbose = *util_options(options) 33 | 34 | file = localize(file) 35 | 36 | cmd = "unzip #{file}" 37 | puts cmd if verbose 38 | system cmd if !noop 39 | end 40 | 41 | end 42 | 43 | end 44 | 45 | -------------------------------------------------------------------------------- /lib/ratch/utils/xdg.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # The XDG utility module provides access ot the XDG library functions. 4 | # This module requires the `xdg` gem. 5 | # 6 | # This module simply maps the #xdg method to the XDG function module. 7 | # 8 | # NOTE: This module is non-essential since one can just use 9 | # the XDG module directly, however we want to encourage the 10 | # use XDG, so it's been provided to encourage that in the context 11 | # of a Ratch script. 12 | # 13 | module XDGUtils 14 | 15 | def self.included(base) 16 | begin 17 | require 'xdg' 18 | rescue 19 | $stderr << "The `xdg` gem is needed to use the XDGUtils module." 20 | exit -1 21 | end 22 | end 23 | 24 | def self.extended(base) 25 | included(base) 26 | end 27 | 28 | # Simple access to XDG function module. 29 | # 30 | # xdg.config.home #=> "~/.config" 31 | # 32 | def xdg 33 | XDG 34 | end 35 | 36 | end 37 | 38 | end 39 | 40 | -------------------------------------------------------------------------------- /spec/02_script.rdoc: -------------------------------------------------------------------------------- 1 | = Ratch::Script 2 | 3 | The Ratch::Script class is the context used for evaluating Ratch-based 4 | batch files, aka shell scripts. 5 | 6 | require 'ratch/script' 7 | 8 | In most every respect the Script class behaves like Ratch::Shell, except that 9 | its initializer takes a file name to be evaluated. 10 | 11 | Let's say we have a Ratch script called 'foo.ratch': 12 | 13 | #!/usr/bin/env ratch 14 | 15 | @test_message = "Hello World!" 16 | 17 | We can load the script via Ratch::Script.new. 18 | 19 | script = Ratch::Script.new('foo.ratch') 20 | 21 | The file name can be accessed from the script using #script_file. 22 | 23 | script.script_file.assert == 'foo.ratch' 24 | 25 | To execute a script, use the `#execute!` method, or it's alias `#run!`. 26 | 27 | script.execute! 28 | 29 | We can see that the script did indeed execute by plubming for the instance 30 | variable it set. 31 | 32 | msg = script.instance_variable_get('@test_message') 33 | msg.assert == "Hello World!" 34 | 35 | -------------------------------------------------------------------------------- /work/ideas/class-per-file-object/lib/ratch/link.rb: -------------------------------------------------------------------------------- 1 | require 'folio/fileobject' 2 | 3 | module Folio 4 | 5 | class Link < FileObject 6 | 7 | def initialize(path) 8 | super 9 | raise LinkNotFound, "#{path}" unless ::File.symlink?(@path) 10 | 11 | dir = ::File.dirname(@path) 12 | name = ::File.readlink(@path) 13 | file = File.join(dir, name) 14 | 15 | @target = Folio.file(file) 16 | end 17 | 18 | attr :target 19 | 20 | #-- 21 | # Am I write to think any file object can be linked? 22 | #++ 23 | 24 | def symlink? 25 | ::File.symlink?(path) 26 | end 27 | alias_method :link?, :symlink? 28 | 29 | def readlink 30 | ::File.readlink(path) 31 | end 32 | 33 | def lchmod(mode) 34 | ::File.lchmod(mode, path) 35 | end 36 | 37 | def lchown(own, grp) 38 | ::File.lchown(own, grp, path) 39 | end 40 | 41 | def lstat 42 | ::File.lstat(path) 43 | end 44 | 45 | # 46 | def method_missing(s, *a, &b) 47 | @target.send(s, *a, &b) 48 | end 49 | 50 | end 51 | 52 | end 53 | -------------------------------------------------------------------------------- /task/test.watchr: -------------------------------------------------------------------------------- 1 | # Run me with: 2 | # $ watchr task/test.watchr 3 | 4 | # -------------------------------------------------- 5 | # Rules 6 | # -------------------------------------------------- 7 | watch('^test.*/case_.*\.rb') { |m| ko m[0] } 8 | 9 | watch( '^lib/(.*)\.rb') do |m| 10 | dir, file = File.split(m[1]) 11 | dir = '' if dir == '.' 12 | ko File.join('test', dir, "case_#{file}.rb") 13 | end 14 | 15 | #watch( '^test/helper\.rb' ) { ko tests } 16 | 17 | # -------------------------------------------------- 18 | # Signal Handling 19 | # -------------------------------------------------- 20 | Signal.trap('QUIT') { ko tests } # Ctrl-\ 21 | Signal.trap('INT' ) { abort("\n") } # Ctrl-C 22 | 23 | # -------------------------------------------------- 24 | # Helpers 25 | # -------------------------------------------------- 26 | def ko(*paths) 27 | run "ko #{gem_opt} -Ilib:test #{paths.flatten.join(' ')}" 28 | end 29 | 30 | def tests 31 | Dir['test/**/*_case.rb'] 32 | end 33 | 34 | def run( cmd ) 35 | puts cmd 36 | system cmd 37 | end 38 | 39 | def gem_opt 40 | defined?(Gem) ? "-rubygems" : "" 41 | end 42 | -------------------------------------------------------------------------------- /work/trash/DONE/commands/gzip.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | class Shell 4 | 5 | # Create a gzip file. 6 | # 7 | def gzip(file, tofile=nil, options={}) 8 | require 'zlib' 9 | 10 | noop, verbose = *util_options(options) 11 | 12 | tofile ||= File.basename(file) + '.gz' 13 | 14 | puts "gzip #{file}" if verbose 15 | 16 | file = localize(file) 17 | tofile = localize(tofile) 18 | 19 | Zlib::GzipWriter.open(tofile) do |gz| 20 | gz.write(File.read(file)) 21 | end unless noop 22 | 23 | return tofile 24 | end 25 | 26 | # Unpack a gzip file. 27 | # 28 | def ungzip(file, options={}) 29 | require 'zlib' 30 | 31 | noop, verbose = *util_options(options) 32 | 33 | fname = File.basename(file).chomp(File.extname(file)) 34 | 35 | puts "ungzip #{file}" if verbose 36 | 37 | fname = localize(fname) 38 | file = localize(file) 39 | 40 | Zlib::GzipReader.open(file) do |gz| 41 | File.open(fname, 'wb'){ |f| f << gz.read } 42 | end unless noop 43 | 44 | return fname 45 | end 46 | 47 | end 48 | 49 | end 50 | 51 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/ui.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | module UI 4 | 5 | # 6 | def yes?(question) 7 | case ask(question).downcase 8 | when 'y', 'yes' 9 | true 10 | else 11 | false 12 | end 13 | end 14 | 15 | # 16 | def no?(question) 17 | case ask(question).downcase 18 | when 'n', 'no' 19 | true 20 | else 21 | false 22 | end 23 | end 24 | 25 | # TODO: Until we have better support for getting input acorss platforms 26 | # we are using #ask only. 27 | def password(prompt=nil) 28 | ask(prompt || "Enter Password: ") 29 | end 30 | 31 | # Ask for a password. (FIXME: only for unix so far) 32 | #def password(prompt=nil) 33 | # prompt ||= "Enter Password: " 34 | # inp = '' 35 | # stdout << "#{prompt} " 36 | # stdout.flush 37 | # begin 38 | # #system "stty -echo" 39 | # #inp = gets.chomp 40 | # until inp = $stdin.gets 41 | # sleep 1 42 | # end 43 | # ensure 44 | # #system "stty echo" 45 | # end 46 | # return inp.chomp 47 | #end 48 | 49 | end 50 | 51 | end 52 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/rcov.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # 4 | module RCov 5 | 6 | # rcov command. 7 | # 8 | # :call-seq: 9 | # rcov(script1, script2, ..., :opt1 => val1, ...) 10 | # 11 | # NOTE: This command shells out. 12 | # 13 | def rcov(*files_options) 14 | require 'rdoc/rdoc' 15 | 16 | options = Hash===options.last ? options.pop : {} 17 | options.rekey!(&:to_s) 18 | 19 | files = files_options 20 | 21 | options['output'] ||= options.delete('o') 22 | 23 | #options['debug'] = options['debug'] || debug? 24 | #options['quiet'] = options['quiet'] || quiet? 25 | #options['verbose'] = options['verbose'] || verbose? 26 | 27 | options['output'] ||= project.log + 'rcov' 28 | 29 | # apply pom 30 | #opts = metadata.select('title').merge(opts) 31 | 32 | # apply defaults 33 | options = defaults.rcov.to_h.merge(options) 34 | 35 | # shell-out 36 | sh 'rcov' + (options.to_argv + files).join(' ') 37 | 38 | #locally do 39 | # rcov = ? 40 | # rcov.document(options.to_argv + files) 41 | #end 42 | end 43 | 44 | end 45 | 46 | end 47 | 48 | -------------------------------------------------------------------------------- /work/ideas/task-extension/test_task.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + '/test_helper' 2 | 3 | require 'ratch/task' 4 | 5 | class TestTaskable < Test::Unit::TestCase 6 | 7 | RESULT_CACHE = [] 8 | 9 | class Example #< Ratch::DSL 10 | 11 | include Taskable 12 | 13 | task :task_with_no_requisites do 14 | RESULT_CACHE << "task_with_no_requisites" 15 | end 16 | 17 | task :task_with_one_requisite => [:task_with_no_requisites] do 18 | RESULT_CACHE << "task_with_one_requisite" 19 | end 20 | 21 | end 22 | 23 | 24 | def setup 25 | RESULT_CACHE.replace([]) 26 | @example = Example.new 27 | end 28 | 29 | def teardown 30 | end 31 | 32 | # Replace this with your real tests. 33 | def test_task_with_no_requisite 34 | @example.run :task_with_no_requisites 35 | #@example.task_with_no_requisites_trigger 36 | assert_equal(["task_with_no_requisites"], RESULT_CACHE) 37 | end 38 | 39 | def test_task_with_one_requisite 40 | @example.run :task_with_one_requisite 41 | #@example.task_with_one_requisite_trigger 42 | assert_equal(["task_with_no_requisites", "task_with_one_requisite"], RESULT_CACHE) 43 | end 44 | 45 | end 46 | 47 | -------------------------------------------------------------------------------- /lib/ratch/utils/zlib.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # 4 | module ZlibUtils 5 | 6 | # 7 | def self.included(base) 8 | require 'zlib' 9 | end 10 | 11 | def self.extended(base) 12 | included(base) 13 | end 14 | 15 | # Create a gzip file. 16 | def gzip(file, tofile=nil, options={}) 17 | noop, verbose = *util_options(options) 18 | 19 | tofile ||= File.basename(file) + '.gz' 20 | 21 | puts "gzip #{file}" if verbose 22 | 23 | file = localize(file) 24 | tofile = localize(tofile) 25 | 26 | Zlib::GzipWriter.open(tofile) do |gz| 27 | gz.write(File.read(file)) 28 | end unless noop 29 | 30 | return tofile 31 | end 32 | 33 | # Unpack a gzip file. 34 | def ungzip(file, options={}) 35 | noop, verbose = *util_options(options) 36 | 37 | fname = File.basename(file).chomp(File.extname(file)) 38 | 39 | puts "ungzip #{file}" if verbose 40 | 41 | fname = localize(fname) 42 | file = localize(file) 43 | 44 | Zlib::GzipReader.open(file) do |gz| 45 | File.open(fname, 'wb'){ |f| f << gz.read } 46 | end unless noop 47 | 48 | return fname 49 | end 50 | 51 | end 52 | 53 | end 54 | 55 | -------------------------------------------------------------------------------- /work/trash/DONE/pathname.rb: -------------------------------------------------------------------------------- 1 | require 'facets/pathname' 2 | require 'ratch/pathlist' 3 | 4 | class Pathname 5 | 6 | # Like directory? but return self if true, otherwise nil. 7 | def dir? 8 | directory? ? self : nil 9 | end 10 | 11 | # 12 | def [](*globs) 13 | Pathlist.new(self)[*globs] 14 | end 15 | 16 | # NOT SURE ABOUT THIS IDEA 17 | #def mkdir_p 18 | # FileUtils.mkdir_p(to_s) 19 | #end 20 | 21 | 22 | # Already in Facets 23 | 24 | # def glob(*opts) 25 | # flags = 0 26 | # opts.each do |opt| 27 | # case opt when Symbol, String 28 | # flags += File.const_get("FNM_#{opt}".upcase) 29 | # else 30 | # flags += opt 31 | # end 32 | # end 33 | # self.class.glob(self.to_s, flags).collect{ |path| self.class.new(path) } 34 | # end 35 | # 36 | # # 37 | # def first(*opts) 38 | # flags = 0 39 | # opts.each do |opt| 40 | # case opt when Symbol, String 41 | # flags += File.const_get("FNM_#{opt}".upcase) 42 | # else 43 | # flags += opt 44 | # end 45 | # end 46 | # file = self.class.glob(self.to_s, flags).first 47 | # file ? self.class.new(file) : nil 48 | # end 49 | 50 | end 51 | 52 | -------------------------------------------------------------------------------- /lib/ratch/utils/rdoc.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # Provides a pure-Ruby method for generating RDocs. 4 | module RDocUtils 5 | 6 | DEFAULT_RDOC_OPTIONS = { 7 | :quiet => true 8 | } 9 | 10 | # RDoc command. 11 | # 12 | # :call-seq: 13 | # rdoc(file1, file2, ..., :opt1 => val1, ...) 14 | # 15 | def rdoc(*files) 16 | require 'rdoc/rdoc' 17 | 18 | options = Hash===files.last ? files.pop : {} 19 | options.rekey!(&:to_s) 20 | 21 | options['title'] ||= options.delete('T') 22 | 23 | options['debug'] = options['debug'] #|| debug? 24 | options['quiet'] = options['quiet'] #|| quiet? 25 | options['verbose'] = options['verbose'] #|| verbose? 26 | 27 | # apply pom (todo?) 28 | #options['title'] ||= metadata.title 29 | 30 | options = DEFAULT_RDOC_OPTIONS.merge(options) 31 | 32 | locally do 33 | rdoc = RDoc::RDoc.new 34 | opts = options.to_argv + files 35 | $stderr.puts("rdoc " + opts.join(' ')) if ($VERBOSE || $DEBUG) 36 | disable_warnings do 37 | rdoc.document(options.to_argv + files) 38 | end 39 | end 40 | end 41 | 42 | # 43 | # TODO: Implement ri doc generator. 44 | 45 | end 46 | 47 | end 48 | 49 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/md5.rb: -------------------------------------------------------------------------------- 1 | require 'fileutils' 2 | require 'digest/md5' 3 | 4 | module FileTest 5 | module_function 6 | 7 | BUF_SIZE = 1024*1024 8 | 9 | # Are two files identical? This compares size and then checksum. 10 | def identical?(file1, file2) 11 | size(file1) == size(file2) && md5(file1) == md5(file2) 12 | end 13 | 14 | # Return an md5 checkum. If a directory is given, will 15 | # return a nested array of md5 checksums for all entries. 16 | 17 | def md5(path) 18 | if File.directory?(path) 19 | md5_list = [] 20 | crt_dir = Dir.new(path) 21 | crt_dir.each do |file_name| 22 | next if file_name == '.' || file_name == '..' 23 | md5_list << md5("#{crt_dir.path}#{file_name}") 24 | end 25 | md5_list 26 | else 27 | hasher = Digest::MD5.new 28 | open(path, "r") do |io| 29 | counter = 0 30 | while (!io.eof) 31 | readBuf = io.readpartial(BUF_SIZE) 32 | counter+=1 33 | #putc '.' if ((counter+=1) % 3 == 0) 34 | hasher.update(readBuf) 35 | end 36 | end 37 | return hasher.hexdigest 38 | end 39 | end 40 | 41 | # Show diff of two files. 42 | 43 | def diff(file1, file2) 44 | `diff #{file1} #{file2}`.strip 45 | end 46 | 47 | end 48 | -------------------------------------------------------------------------------- /test/case_batch.rb: -------------------------------------------------------------------------------- 1 | require 'ratch/batch' 2 | 3 | KO.case Ratch::Batch do 4 | 5 | def initialize 6 | stage_clear 7 | stage_fake %w{a.txt b.txt d/x.txt d/y.txt} 8 | 9 | @batch1 = Ratch::Batch.new('.') 10 | @batch2 = Ratch::Batch.new('.', '*') 11 | @batch3 = Ratch::Batch.new('.', '**/*') 12 | end 13 | 14 | test :local do 15 | @batch1.local == Pathname.new('.') 16 | end 17 | 18 | test :list do 19 | @batch1.list.is_a?(Array) 20 | end 21 | 22 | test :file_list do 23 | @batch1.file_list.is_a?(Ratch::FileList) 24 | end 25 | 26 | test :each do 27 | r = [] 28 | @batch2.each{ |pn| r << pn } 29 | r.map(&:to_s).sort == %w{a.txt b.txt d} 30 | end 31 | 32 | test "passes #each thru to Enumerable methods" do 33 | @batch2.all?{ |pn| pn.is_a? Pathname } 34 | end 35 | 36 | test :size do 37 | batch = Ratch::Batch.new('.', '*') 38 | batch.size == 3 39 | end 40 | 41 | test :directory? do 42 | batch = Ratch::Batch.new('.', '*') 43 | not batch.directory? 44 | end 45 | 46 | test :file? do 47 | not @batch2.file? 48 | end 49 | 50 | test :directory! do 51 | batch = Ratch::Batch.new('.', '*') 52 | batch.directory! 53 | batch.filenames == %w{d} 54 | end 55 | 56 | test :file! do 57 | batch = Ratch::Batch.new('.', '*') 58 | batch.file! 59 | batch.filenames.sort == %w{a.txt b.txt} 60 | end 61 | 62 | end 63 | 64 | -------------------------------------------------------------------------------- /work/trash/DONE/commands/xdg.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require 'xdg' 3 | rescue LoadError 4 | require 'ratch/vendor/xdg' 5 | end 6 | 7 | module Ratch 8 | 9 | class Shell 10 | 11 | # Look up a config file. 12 | def config(path) 13 | file(XDG.xdg_config_file(path)) 14 | end 15 | 16 | # Look up a data file. 17 | def data(path) 18 | file(XDG.xdg_data_file(path)) 19 | end 20 | 21 | # Look up a cache file. 22 | def cache(path) 23 | file(XDG.xdg_cache_file(path)) 24 | end 25 | 26 | # Return a enumertor of system config directories. 27 | def root_config() #_directories 28 | XDG.xdg_config_dirs.to_enum(:each){ |f| dir(f) } 29 | end 30 | 31 | # Return a enumertor of system data directories. 32 | def root_data() #_directories 33 | XDG.xdg_data_dirs.to_enum(:each){ |f| dir(f) } 34 | end 35 | 36 | # Return the home config directory. 37 | def home_config 38 | dir(XDG.xdg_config_home) 39 | end 40 | 41 | # Return the home data directory. 42 | def home_data 43 | dir(XDG.xdg_data_home) 44 | end 45 | 46 | # Return the home cache directory. 47 | def home_cache 48 | dir(XDG.xdg_cache_home) 49 | end 50 | 51 | # Return the work config directory. 52 | def work_config 53 | dir(XDG.xdg_config_work) 54 | end 55 | 56 | # Return the work cache directory. 57 | def work_cache 58 | dir(XDG.xdg_cache_work) 59 | end 60 | 61 | end 62 | 63 | end 64 | -------------------------------------------------------------------------------- /work/ideas/class-per-file-object/lib/ratch/finder.rb: -------------------------------------------------------------------------------- 1 | # NOT USED. Expiremental. 2 | 3 | module Folio 4 | 5 | require 'pathname' 6 | 7 | =begin 8 | class Pathname 9 | 10 | def glob(*options) 11 | opts = 0 12 | options.each do |option| 13 | case option 14 | when :nocase 15 | opts += File::FNM_CASEFOLD 16 | else 17 | opts += option 18 | end 19 | end 20 | 21 | self.class.glob(to_s, opts).collect{ |f| Pathname.new(f) } 22 | end 23 | 24 | end 25 | =end 26 | 27 | # This is similar to Rake's FileList. 28 | # 29 | class Finder 30 | 31 | # 32 | attr :patterns 33 | attr :options 34 | 35 | def <<(pattern) 36 | patterns << pattern 37 | end 38 | 39 | # 40 | def match?(path) 41 | patterns.find{ |pattern| File.fnmatch?(pattern, path) } 42 | end 43 | 44 | # 45 | def match(*options) 46 | opts = 0 47 | options.each do 48 | case options 49 | when :nocase 50 | opts += File::FNM_CASEFOLD 51 | end 52 | end 53 | patterns.collect{ |pattern| File.glob(pattern, opts) }.flatten 54 | end 55 | 56 | def file?(*options) 57 | match(options).all?{ |f| File.file?(f) } 58 | end 59 | 60 | def directory?(*options) 61 | match(options).all?{ |f| File.directory?(f) } 62 | end 63 | 64 | private 65 | 66 | def initialize(*patterns) 67 | @patterns = patterns 68 | end 69 | 70 | def self.[](*patterns) 71 | new(*patterns) 72 | end 73 | 74 | end 75 | 76 | end 77 | 78 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | #!mast -x Syckfile -x Profile .ruby bin demo lib man spec test [A-Z]* 2 | .ruby 3 | bin/ludo 4 | bin/ratch 5 | lib/ratch/batch.rb 6 | lib/ratch/console.rb 7 | lib/ratch/core_ext/facets.rb 8 | lib/ratch/core_ext/filetest.rb 9 | lib/ratch/core_ext/to_actual_filename.rb 10 | lib/ratch/core_ext/to_console.rb 11 | lib/ratch/core_ext/to_list.rb 12 | lib/ratch/core_ext/to_yamlfrag.rb 13 | lib/ratch/core_ext/unfold_paragraphs.rb 14 | lib/ratch/core_ext.rb 15 | lib/ratch/file_list.rb 16 | lib/ratch/script/help.rb 17 | lib/ratch/script.rb 18 | lib/ratch/shell.rb 19 | lib/ratch/system.rb 20 | lib/ratch/utils/cli.rb 21 | lib/ratch/utils/config.rb 22 | lib/ratch/utils/email.rb 23 | lib/ratch/utils/ftp.rb 24 | lib/ratch/utils/pom.rb 25 | lib/ratch/utils/rdoc.rb 26 | lib/ratch/utils/tar.rb 27 | lib/ratch/utils/xdg.rb 28 | lib/ratch/utils/zlib.rb 29 | lib/ratch.rb 30 | lib/ratch.yml 31 | man/ratch.1 32 | spec/01_shell.rdoc 33 | spec/02_script.rdoc 34 | spec/03_batch.rdoc 35 | spec/04_system.rdoc 36 | spec/applique/array.rb 37 | spec/applique/setup.rb 38 | test/case_batch.rb 39 | test/case_shell.rb 40 | test/core_ext/case_pathname.rb 41 | test/helper.rb 42 | test/utils/case_cli.rb 43 | test/utils/case_config.rb 44 | test/utils/case_email.rb 45 | test/utils/case_ftp.rb 46 | test/utils/case_pom.rb 47 | test/utils/case_rdoc.rb 48 | test/utils/case_tar.rb 49 | test/utils/case_zlib.rb 50 | test/utils/fixtures/pom_sample/Profile 51 | test/utils/fixtures/rdoc_sample/README.rdoc 52 | test/utils/fixtures/rdoc_sample/lib/rdoc_sample/rdoc_sample.rb 53 | README.rdoc 54 | History.rdoc 55 | Version 56 | License.txt 57 | COPYING 58 | -------------------------------------------------------------------------------- /lib/ratch/utils/config.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # Utility extensions for working with configuration files. 4 | #-- 5 | # TODO: Perhaps utilize confectionary gem in future? 6 | #++ 7 | module ConfigUtils 8 | 9 | # 10 | def self.included(base) 11 | require 'yaml' 12 | end 13 | 14 | def self.extended(base) 15 | included(base) 16 | end 17 | 18 | # Load configuration data from a file. Results are cached and an empty 19 | # Hash is returned if the file is not found. 20 | # 21 | # Since they are YAML files, they can optionally end with '.yaml' or '.yml'. 22 | def configuration(file) 23 | @configuration ||= {} 24 | @configuration[file] ||= ( 25 | begin 26 | configuration!(file) 27 | rescue LoadError 28 | Hash.new{ |h,k| h[k] = {} } 29 | end 30 | ) 31 | end 32 | 33 | # Load configuration data from a file. The "bang" version will raise an error 34 | # if file is not found. It also does not cache the results. 35 | # 36 | # Since they are YAML files, they can optionally end with '.yaml' or '.yml'. 37 | def configuration!(file) 38 | @configuration ||= {} 39 | patt = file + "{.yml,.yaml,}" 40 | path = Dir.glob(patt, File::FNM_CASEFOLD).find{ |f| File.file?(f) } 41 | if path 42 | # The || {} is in case the file is empty. 43 | data = YAML::load(File.open(path)) || {} 44 | @configuration[file] = data 45 | else 46 | raise LoadError, "Missing file -- #{path}" 47 | end 48 | end 49 | 50 | end 51 | 52 | end 53 | -------------------------------------------------------------------------------- /Assembly: -------------------------------------------------------------------------------- 1 | --- 2 | email: 3 | service : Email 4 | file : ~ 5 | subject : ~ 6 | mailto : ruby-talk@ruby-lang.org 7 | active : true 8 | 9 | grancher: 10 | service: grancher 11 | active: true 12 | 13 | gemcutter: 14 | service: GemCutter 15 | active: true 16 | 17 | box: 18 | service: Box 19 | types : [gem] 20 | active : true 21 | 22 | ridoc: 23 | service: RIDoc 24 | include: ~ 25 | exclude: ~ 26 | active : true 27 | 28 | rdoc: 29 | service : RDoc 30 | template: newfish 31 | output : site/documentation/api 32 | include : ~ 33 | exclude : [ Syckfile ] 34 | active : true 35 | 36 | syntax: 37 | service : Syntax 38 | loadpath : ~ 39 | exclude : ~ 40 | active : false 41 | 42 | testrb: 43 | service : testrb 44 | tests : ~ 45 | exclude : ~ 46 | loadpath : ~ 47 | requires : ~ 48 | live : false 49 | active : false 50 | 51 | dnote: 52 | service : DNote 53 | loadpath : ~ 54 | labels : ~ 55 | exclude : [work] 56 | output : ~ 57 | format : ~ 58 | active : true 59 | 60 | stats: 61 | service : Stats 62 | title : ~ 63 | loadpath : ~ 64 | exclude : ~ 65 | output : ~ 66 | active : true 67 | 68 | vclog: 69 | service : VClog 70 | formats : [json] 71 | #layout : rel # gnu 72 | typed : false 73 | output : ~ 74 | active : false 75 | 76 | 77 | #sow: 78 | # service: SowGen 79 | 80 | #test: 81 | # service: TestUnit 82 | 83 | #rdoc: 84 | # service : RDoc 85 | # template: ./.config/rdoc-template 86 | # inline : true 87 | 88 | #rubygem: 89 | # service: Gem 90 | # exclude: [gen, doc/rdoc, doc/ri, log, web, work] 91 | 92 | #rubyforge: 93 | # service: Rubyforge 94 | # groupid: 6276 95 | 96 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/log.rb: -------------------------------------------------------------------------------- 1 | require 'ratch/plugin' 2 | 3 | module Ratch 4 | 5 | # Logging utils. 6 | module Logging 7 | 8 | # Access a log by name. 9 | def log(path) 10 | @logfile ||= {} 11 | @logfile[path.to_s] ||= ( 12 | Log.new(project.log + name.to_s, :noop=>noop?, :verbose=>verbose?) 13 | ) 14 | end 15 | 16 | # The Log class provides a common and easy to use means for 17 | # different services to log there activity. 18 | # 19 | class Log 20 | 21 | attr :pathname 22 | 23 | # 24 | def initialize(pathname, options={}) 25 | @pathname = Pathname.new(pathname) 26 | @noop = options[:noop] 27 | @verbose = options[:verbose] 28 | end 29 | 30 | def noop? ; @noop ; end 31 | 32 | def verbose? ; @verbose ; end 33 | 34 | # 35 | def method_missing(s, *a, &b) 36 | @pathname.send(s, *a, &b) 37 | end 38 | 39 | # Get the path name as string. 40 | def file 41 | @pathname.to_s 42 | end 43 | 44 | # Write to log file. 45 | def write(str) 46 | return if noop? 47 | FileUtils.mkdir_p(File.dirname(file)) #unless File.file?(file) 48 | File.open(file, 'w'){ |f| f << str } 49 | end 50 | alias_method :<<, :write 51 | 52 | # 53 | def append(str) 54 | return if noop? 55 | FileUtils.mkdir_p(File.dirname(file)) #unless File.file?(file) 56 | File.open(file, 'a'){ |f| f << str } 57 | end 58 | 59 | # 60 | def clear 61 | return if noop? 62 | File.open(file, 'w'){ |f| f << '' } if File.file?(file) 63 | end 64 | 65 | end 66 | 67 | end 68 | 69 | end 70 | -------------------------------------------------------------------------------- /work/deprecated/runmode.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | module Ratch 3 | 4 | # = Runmode 5 | # 6 | # The Runmode class encapsulates common options for command line scripts. 7 | # The built-in modes are: 8 | # 9 | # force 10 | # trace 11 | # debug 12 | # quiet 13 | # verbose 14 | # pretend -or- dryrun 15 | # 16 | class Runmode 17 | 18 | def self.load_argv! 19 | options = { 20 | :force => %w{--force}.any?{ |x| ARGV.delete(x) }, 21 | :trace => %w{--trace}.any?{ |x| ARGV.delete(x) }, 22 | :debug => %w{--debug}.any?{ |x| ARGV.delete(x) }, 23 | :quiet => %w{--quiet --silent}.any?{ |x| ARGV.delete(x) }, 24 | :pretend => %w{--pretend --dryrun --dry-run}.any?{ |x| ARGV.delete(x) }, 25 | :verbose => %w{--verbose}.any?{ |x| ARGV.delete(x) } 26 | } 27 | new(options) 28 | end 29 | 30 | def initialize(options={}) 31 | options.rekey(&:to_sym) 32 | 33 | @force = options[:force] 34 | @trace = options[:trace] 35 | @debug = options[:debug] 36 | @quiet = options[:quiet] || options[:silent] 37 | @pretend = options[:pretend] || options[:dryrun] 38 | @verbose = options[:verbose] 39 | end 40 | 41 | attr_accessor :force 42 | 43 | attr_accessor :trace 44 | 45 | attr_accessor :verbose 46 | 47 | attr_accessor :quiet 48 | 49 | attr_accessor :debug 50 | 51 | attr_accessor :pretend 52 | 53 | def force? ; @force ; end 54 | def trace? ; @trace ; end 55 | def debug? ; @debug ; end 56 | def quiet? ; @quiet ; end 57 | def verbose? ; @verbose ; end 58 | def pretend? ; @pretend ; end 59 | 60 | def noharm? ; @pretend ; end 61 | def dryrun? ; @pretend ; end 62 | end 63 | 64 | end 65 | =end 66 | 67 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/xdg.rb: -------------------------------------------------------------------------------- 1 | module Ratch 2 | 3 | # XDG module provides some conenience methods for working 4 | # with the XDG dirtectory standard. 5 | # 6 | # FIXME: This module need serious work. The method names are too general 7 | # and the it probably is easy enough to do without the xdg gem dependency. 8 | module XDG 9 | 10 | def self.included(base) 11 | begin 12 | require 'xdg' 13 | rescue LoadError 14 | raise "The Ratch::XDG module requires the `xdg` gem." 15 | end 16 | end 17 | 18 | # Look up a config file. 19 | def config(path) 20 | file(XDG.xdg_config_file(path)) 21 | end 22 | 23 | # Look up a data file. 24 | def data(path) 25 | file(XDG.xdg_data_file(path)) 26 | end 27 | 28 | # Look up a cache file. 29 | def cache(path) 30 | file(XDG.xdg_cache_file(path)) 31 | end 32 | 33 | # Return a enumertor of system config directories. 34 | def root_config() #_directories 35 | XDG.xdg_config_dirs.to_enum(:each){ |f| dir(f) } 36 | end 37 | 38 | # Return a enumertor of system data directories. 39 | def root_data() #_directories 40 | XDG.xdg_data_dirs.to_enum(:each){ |f| dir(f) } 41 | end 42 | 43 | # Return the home config directory. 44 | def home_config 45 | dir(XDG.xdg_config_home) 46 | end 47 | 48 | # Return the home data directory. 49 | def home_data 50 | dir(XDG.xdg_data_home) 51 | end 52 | 53 | # Return the home cache directory. 54 | def home_cache 55 | dir(XDG.xdg_cache_home) 56 | end 57 | 58 | # Return the work config directory. 59 | def work_config 60 | dir(XDG.xdg_config_work) 61 | end 62 | 63 | # Return the work cache directory. 64 | def work_cache 65 | dir(XDG.xdg_cache_work) 66 | end 67 | 68 | end 69 | 70 | end 71 | -------------------------------------------------------------------------------- /work/consider/lib/ratch/utils/rdoc.rb: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Generate RDoc documentation. 4 | # 5 | def rdoc(*files) 6 | require 'rdoc/rdoc' 7 | 8 | opts = {} 9 | opts.update(files.pop) while Hash===files.last 10 | 11 | opts[:output] ||= 'doc/rdoc' 12 | opts[:main] ||= Dir.glob('README*').first 13 | 14 | output = opts[:output] 15 | 16 | # TODO: I think there is a File method that check this better, ie. File.safe? or something like that. 17 | raise "Output is not a relative path -- #{output}" if output =~ /^\// 18 | 19 | if uptodate?(output, *files) && !force? 20 | puts "#{output} is up-to-date." 21 | return 22 | end 23 | 24 | if File.exist?(output) 25 | #p Dir.pwd, opts[:output] 26 | rm_r output 27 | end 28 | 29 | args = opts.to_argv + files 30 | 31 | r = RDoc::RDoc.new 32 | r.document args 33 | 34 | #c = [] 35 | #c << "rdoc" 36 | #c << "-m #{opts[:main]}" if opts[:main] 37 | #c << "-o #{opts[:output]}" if opts[:output] 38 | #c.concat(files) 39 | #sh cmd 40 | end 41 | 42 | # 43 | # Generate RI documentation. 44 | # 45 | def ridoc(*files) 46 | require 'rdoc/rdoc' 47 | 48 | opts = {} 49 | opts.update(files.pop) while Hash===files.last 50 | 51 | opts[:output] ||= 'doc/ri' 52 | 53 | output = opts[:output] 54 | 55 | # TODO: I think there is a File method that check this better, ie. File.safe? or something like that. 56 | raise "Output is not a relative path -- #{output}" if output =~ /^\// 57 | 58 | if uptodate?(output, *files) && !force? 59 | puts "#{output} is up-to-date." 60 | return 61 | end 62 | 63 | if File.exist?(output) 64 | #p Dir.pwd, opts[:output] 65 | rm_r output 66 | end 67 | 68 | args = ["--ri"] + opts.to_argv + files 69 | 70 | r = RDoc::RDoc.new 71 | r.document args 72 | 73 | #c << "-m #{opts[:main]}" if opts[:main] 74 | #c << "-m #{opts[:output]}" if opts[:output] 75 | #sh cmd 76 | end 77 | -------------------------------------------------------------------------------- /spec/03_batch.rdoc: -------------------------------------------------------------------------------- 1 | = Ratch::Batch 2 | 3 | The Batch class makes makes it possible to work with multiple files 4 | at once as easily as one would work with a single file. 5 | 6 | require 'ratch/batch' 7 | 8 | The demonstration sets up a sample directory consisting of the following 9 | entires in the temporary working directory: 10 | 11 | foo.txt 12 | bar.txt 13 | zoo/ 14 | zoo/one.txt 15 | zoo/two.txt 16 | 17 | To create a new Batch instance, pass the the base directory and any 18 | inclusion patterns to the initializer. 19 | 20 | batch = Ratch::Batch.new('.', '*.txt') 21 | 22 | In this example we will get every `.txt` file at the toplevel of the base 23 | directory. 24 | 25 | batch.to_a.assert = ['foo.txt', 'bar.txt'].to_pathnames 26 | 27 | To get a list of files relative to the base directory, use #entries. 28 | 29 | batch.entries.assert = ['foo.txt', 'bar.txt'].to_pathnames 30 | 31 | Internally a Batch instance tracks the files selected via a Ratch::FileList 32 | object. This can be directly accessed via the #list method. 33 | 34 | batch.file_list.assert.is_a?(Ratch::FileList) 35 | 36 | batch.file_list.to_a.assert = ['foo.txt', 'bar.txt'] 37 | 38 | As with the delegated FileTest methods of the Shell class, Batch can test 39 | the set of files in agregate. For example, to ensure all the entries 40 | are files we can use the #file? method. 41 | 42 | batch.assert.file? 43 | 44 | Likewise to enusre none the entires are directories we can use the #directory? 45 | method. 46 | 47 | batch.refute.directory? 48 | 49 | The Batch list can be reduced to just files or just directories via the #file! 50 | and #directory! methods. 51 | 52 | batch = Ratch::Batch.new('.', '*') 53 | batch.file! 54 | batch.list.assert = ['foo.txt', 'bar.txt'] 55 | 56 | batch = Ratch::Batch.new('.', '*') 57 | batch.directory! 58 | batch.list.assert = ['zoo'] 59 | 60 | The Batch class is enumerable, both #each and #size are defined. 61 | 62 | batch = Ratch::Batch.new('.', '*.txt') 63 | 64 | batch.each do |pathname| 65 | pathname.assert.is_a?(Pathname) 66 | end 67 | 68 | batch.size.assert = 2 69 | 70 | Any enumerable method is likewise applicable. 71 | 72 | -------------------------------------------------------------------------------- /work/reference/layout.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Ratch 11 | 12 | 13 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 |