Class: EMN::Config
- Inherits:
-
Object
- Object
- EMN::Config
- Defined in:
- lib/emn/config.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(config = "~/.emn", seen = "~/.emn_seen") ⇒ Config
constructor
A new instance of Config.
- #load_config ⇒ Object
- #logger ⇒ Object
- #save_seen!(seen) ⇒ Object
- #seen ⇒ Object
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_config ⇒ Object
36 37 38 |
# File 'lib/emn/config.rb', line 36 def load_config @config = YAML.load(File.read(File.(@config_file))) end |
#logger ⇒ Object
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.(@seen_file), "w") do |file| file.puts seen.to_yaml end end |
#seen ⇒ Object
18 19 20 21 22 |
# File 'lib/emn/config.rb', line 18 def seen YAML.load(File.read(File.(@seen_file))) rescue {} end |