Class: Maid::App

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

Overview

rubocop:disable Metrics/ClassLength

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:



9
10
11
# File 'lib/maid/app.rb', line 9

def self.exit_on_failure?
  true
end

.sample_rules_pathObject



29
30
31
# File 'lib/maid/app.rb', line 29

def self.sample_rules_path
  File.join(File.dirname(Maid::Maid::DEFAULTS[:rules_path]), 'rules.sample.rb')
end

Instance Method Details

#cleanObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/maid/app.rb', line 38

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



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/maid/app.rb', line 82

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/maid/app.rb', line 14

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/maid/app.rb', line 99

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



70
71
72
73
74
75
76
77
# File 'lib/maid/app.rb', line 70

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



58
59
60
61
62
63
64
# File 'lib/maid/app.rb', line 58

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