Class: Kanmon::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Config

Returns a new instance of Config.



17
18
19
# File 'lib/kanmon/config.rb', line 17

def initialize(data)
  @data = data
end

Class Method Details

.load_file(filepath) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/kanmon/config.rb', line 5

def self.load_file(filepath)
  data = if filepath
           YAML.load_file(filepath)
         else
           default_files = [File.expand_path("~/.kanmon.yml"), "./kanmon.yml"]
           config_file = default_files.find {|path| File.exists?(path)}
           YAML.load_file(config_file)
         end

  new(data)
end

Instance Method Details

#set(target) ⇒ Object



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

def set(target)
  unless @data.keys.include?(target)
    raise TargetNotFoundError.new("#{target} is not found.")
  end
  @target = target
end

#targetsObject



21
22
23
# File 'lib/kanmon/config.rb', line 21

def targets
  @data.keys
end