Class: Hercules::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
# File 'lib/config.rb', line 7

def initialize(path)
  @config = nil
  @path = path
  reload
  validate
end

Class Method Details

.branch_attributesObject



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

def self.branch_attributes
  ['checkout_on_startup', 'checkouts_to_keep']
end

.global_attributesObject



48
49
50
# File 'lib/config.rb', line 48

def self.global_attributes
  ['host', 'port']
end

.project_attributesObject



52
53
54
# File 'lib/config.rb', line 52

def self.project_attributes
  ['target_directory', 'repository', 'token']
end

Instance Method Details

#[](k) ⇒ Object



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

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

#branchesObject



60
61
62
63
64
65
66
# File 'lib/config.rb', line 60

def branches
  r = {}
  projects.each do |k,v|
    r[k] = v.keys.find_all{|e| e unless self.class.project_attributes.include?(e)}
  end
  r
end

#eachObject



22
23
24
25
26
# File 'lib/config.rb', line 22

def each
  @config.each do |k,v|
    yield(k,v)
  end
end

#hostObject



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

def host
  @config['host'] || "0.0.0.0"
end

#include?(k) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/config.rb', line 28

def include?(k)
  @config.include?(k)
end

#portObject



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

def port
  @config['port'] || 49456
end

#projectsObject



40
41
42
43
44
45
46
# File 'lib/config.rb', line 40

def projects
  p = {}
  @config.each do |k,v| 
    p[k] = v unless self.class.global_attributes.include?(k)
  end
  p
end

#reloadObject



14
15
16
# File 'lib/config.rb', line 14

def reload
  @config = YAML.load_file(@path)
end