class CleanFiles::Runner
Attributes
options[R]
Public Class Methods
new(arguments)
click to toggle source
# File lib/clean_files/runner.rb, line 11 def initialize(arguments) @arguments = arguments # Set defaults @options = Hash.new @options[:threshold] = 1.month.ago end
Public Instance Methods
run()
click to toggle source
Parse options, check arguments, then process the command
# File lib/clean_files/runner.rb, line 20 def run if parsed_options? && arguments_valid? Cleaner.new(@options.delete(:paths), @options).start else output_usage end end
Protected Instance Methods
arguments_valid?()
click to toggle source
# File lib/clean_files/runner.rb, line 57 def arguments_valid? @options[:paths].present? end
output_help()
click to toggle source
# File lib/clean_files/runner.rb, line 61 def output_help rdoc exit -1 end
output_usage()
click to toggle source
# File lib/clean_files/runner.rb, line 66 def output_usage rdoc('Usage', 'Options') exit -1 end
parsed_options?()
click to toggle source
# File lib/clean_files/runner.rb, line 32 def parsed_options? # Specify options opts = OptionParser.new opts.on('-h', '--help') { output_help } opts.on('-v', '--verbose') { @options[:verbose] = true } opts.on('-d', '--pretend') { @options[:pretend] = true @options[:verbose] = true } opts.on('-r', '--recursive') {@options[:recursive] = true } opts.on('-t', '--treshold [DAYS]') do |days| raise OptionParser::InvalidOption unless days.to_i > 0 || days == "0" @options[:threshold] = days.to_i.send(:days).ago end Cleaner::VALID_INTERVALS.each do |interval| opts.on("-#{interval.to_s.first.upcase}", "--#{interval}") {@options[interval] = true} end return false unless opts.parse!(@arguments) @options[:paths] = @arguments.dup true end
rdoc(*sections)
click to toggle source
# File lib/clean_files/runner.rb, line 71 def rdoc(*sections) readme_path = File.join(File.dirname(__FILE__), '/../../README.rdoc') comment = File.read(readme_path) puts comment.gsub(/.*Usage/m, '') end