Class: Pristine::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pristine/config.rb

Constant Summary collapse

DEFAULT_LOG =
STDOUT
DEFAULT_FLAGS =

Lets watch IN_MODIFY events for now

:modify
DEFAULT_FILES_LIST =
'/var/lib/puppet/state/resources.txt'

Class Method Summary collapse

Class Method Details

.configObject



56
57
58
# File 'lib/pristine/config.rb', line 56

def self.config
  @config
end

.files_listObject

Specific for Puppet's resource.txt file



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pristine/config.rb', line 61

def self.files_list
  list = []
  File.open(@config.files_list, 'r') do |f|
    f.each_line do |line|
      if line.match(/^file/)
        list << line.split('[')[1].split(']').first
      end
    end
  end
  list
end

.load(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pristine/config.rb', line 13

def self.load(args)
  @config = OpenStruct.new

  parser = OptionParser.new do |opts|
    opts.on_head('--config FILE', 'Config file') do |path|
      @config[:config_file] = path
      @config = OpenStruct.new(Hash[YAML::load(open(path)).map { |k, v| [k.to_sym, v] }])
    end

    # TODO
#        opts.on('-F', '--foreground', 'Run on foreground') do |v|
#          @config[:foreground] = v
#        end

    opts.on('-l', '--log FILE', 'Log output') do |v|
      @config[:log] = v
    end

    # TODO
#        opts.on('-f', '--flags x,y,z', Array, 'Systemcalls to watch') do |v|
#          @config[:config_file] = v
#        end

    opts.on('-f', '--files FILE', 'Files list to watch') do |v|
      @config[:files_list] = v
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("--version", "Show version") do
      puts Pristine::VERSION
      exit
    end
  end
  parser.parse(args)
  parser.load(config.config_file) unless config.config_file.nil?

  set_defaults
end

.method_missing(method) ⇒ Object



73
74
75
# File 'lib/pristine/config.rb', line 73

def self.method_missing(method)
  @config.send method
end