class Maid::App
Public Class Methods
sample_rules_path()
click to toggle source
# File lib/maid/app.rb, line 25 def self.sample_rules_path File.join(File.dirname(Maid::Maid::DEFAULTS[:rules_path]), 'rules.sample.rb') end
Public Instance Methods
clean()
click to toggle source
# File lib/maid/app.rb, line 34 def clean maid = Maid::Maid.new(maid_options(options)) unless options.noop? || options.force? warn 'Running "maid clean" without a flag is deprecated. Please use "maid clean --noop" or "maid clean --force".' end if Maid::TrashMigration.needed? migrate_trash return end unless options.silent? || options.noop? say "Logging actions to #{ maid.log_device.inspect }" end maid.load_rules maid.clean end
daemon()
click to toggle source
# File lib/maid/app.rb, line 80 def daemon maid = Maid::Maid.new(maid_options(options)) if Maid::TrashMigration.needed? migrate_trash return end unless options.silent? say "Logging actions to #{ maid.log_device.inspect }" end maid.load_rules maid.daemonize end
introduction()
click to toggle source
# File lib/maid/app.rb, line 10 def introduction say <<EOF #{Maid::UserAgent.short} #{'=' * Maid::UserAgent.short.length} #{Maid::SUMMARY} * Tutorial: https://github.com/benjaminoakes/maid#tutorial * Community & examples: https://github.com/benjaminoakes/maid/wiki * Documentation: http://www.rubydoc.info/gems/maid/#{Maid::VERSION}/Maid/Tools For more information, run "maid help". EOF end
maid_options(options)
click to toggle source
# File lib/maid/app.rb, line 97 def maid_options(options) h = {} if options['noop'] # You're testing, so a simple log goes to STDOUT and no actions are taken h[:file_options] = { :noop => true } unless options['silent'] h[:logger] = false h[:log_device] = STDOUT h[:log_formatter] = lambda { |_, _, _, msg| "#{ msg }\n" } end end if options['rules'] h[:rules_path] = options['rules'] end h end
sample()
click to toggle source
# File lib/maid/app.rb, line 68 def sample path = self.class.sample_rules_path FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w').puts(File.read(File.join(File.dirname(__FILE__), 'rules.sample.rb'))) say "Sample rules created at #{ path.inspect }", :green end
version()
click to toggle source
# File lib/maid/app.rb, line 56 def version if options.long? say Maid::UserAgent.value else say Maid::VERSION end end
Private Instance Methods
migrate_trash()
click to toggle source
Migrate trash to correct directory on Linux due to a configuration bug in previous releases.
# File lib/maid/app.rb, line 122 def migrate_trash migration = Maid::TrashMigration banner('Trash Migration', :yellow) say <<-EOF You are using Linux and have a "~/.Trash" directory. If you used Maid 0.1.2 or earlier, that directory may exist because Maid incorrectly moved trash files there. But no worries. Maid can migrate those files to the correct place. EOF response = ask("Would you like Maid to move the files in #{ migration.incorrect_trash.inspect } to #{ migration.correct_trash.inspect }?", :limited_to => %w(Y N)) case response when 'Y' say('') say('Migrating trash...') migration.perform say('Migrated. See the Maid log for details.') when 'N' say <<-EOF Running Maid again will continue to give this warning until #{ migration.incorrect_trash.inspect } no longer exists, or the environment variable MAID_NO_MIGRATE_TRASH has a value. Exiting... EOF exit -1 else raise "Reached 'impossible' case (response: #{ response.inspect })" end end