Class: Maid::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/maid/app.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sample_rules_pathObject



25
26
27
# 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

Instance Method Details

#cleanObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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

  say "Logging actions to #{maid.log_device.inspect}" unless options.silent? || options.noop?

  maid.load_rules
  maid.clean
end

#daemonObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/maid/app.rb', line 78

def daemon
  maid = Maid::Maid.new(maid_options(options))

  if Maid::TrashMigration.needed?
    migrate_trash
    return
  end

  say "Logging actions to #{maid.log_device.inspect}" unless options.silent?

  maid.load_rules
  maid.daemonize
end

#introductionObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

#logsObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/maid/app.rb', line 95

def logs
  maid = Maid::Maid.new(maid_options(options))

  if options.path?
    say maid.log_device
  elsif File.readable?(maid.log_device)
    if options.tail?
      system("tail -f #{maid.log_device}")
    else
      say `tail #{maid.log_device}`
    end
  else
    error "Log file #{maid.log_device} does not exist."
  end
end

#sampleObject



66
67
68
69
70
71
72
73
# File 'lib/maid/app.rb', line 66

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

#versionObject



54
55
56
57
58
59
60
# File 'lib/maid/app.rb', line 54

def version
  if options.long?
    say Maid::UserAgent.value
  else
    say Maid::VERSION
  end
end