Class: EMN::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(config = "~/.emn", seen = "~/.emn_seen") ⇒ Config

Returns a new instance of Config.



3
4
5
6
7
8
# File 'lib/emn/config.rb', line 3

def initialize(config="~/.emn", seen="~/.emn_seen")
  @config_file = config
  @seen_file = seen

  load_config
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
# File 'lib/emn/config.rb', line 32

def [](key)
  @config[key]
end

#load_configObject



36
37
38
# File 'lib/emn/config.rb', line 36

def load_config
  @config = YAML.load(File.read(File.expand_path(@config_file)))
end

#loggerObject



10
11
12
13
14
15
16
# File 'lib/emn/config.rb', line 10

def logger
  if OPTIONS[:debug] || OPTIONS[:verbose]
    return @logger ||= Logger.new(STDOUT)
  else
    return @logger ||= Logger.new(nil)
  end
end

#save_seen!(seen) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/emn/config.rb', line 24

def save_seen!(seen)
  return if OPTIONS[:debug]

  File.open(File.expand_path(@seen_file), "w") do |file|
    file.puts seen.to_yaml
  end
end

#seenObject



18
19
20
21
22
# File 'lib/emn/config.rb', line 18

def seen
  YAML.load(File.read(File.expand_path(@seen_file)))
rescue
  {}
end