Class: Hercules::Config
- Inherits:
-
Object
- Object
- Hercules::Config
- Defined in:
- lib/config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
- #branches ⇒ Object
- #each ⇒ Object
- #host ⇒ Object
- #include?(k) ⇒ Boolean
-
#initialize(path) ⇒ Config
constructor
A new instance of Config.
- #port ⇒ Object
- #projects ⇒ Object
- #reload ⇒ Object
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_attributes ⇒ Object
56 57 58 |
# File 'lib/config.rb', line 56 def self.branch_attributes ['checkout_on_startup', 'checkouts_to_keep'] end |
.global_attributes ⇒ Object
48 49 50 |
# File 'lib/config.rb', line 48 def self.global_attributes ['host', 'port'] end |
.project_attributes ⇒ Object
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 |
#branches ⇒ Object
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 |
#each ⇒ Object
22 23 24 25 26 |
# File 'lib/config.rb', line 22 def each @config.each do |k,v| yield(k,v) end end |
#host ⇒ Object
32 33 34 |
# File 'lib/config.rb', line 32 def host @config['host'] || "0.0.0.0" end |
#include?(k) ⇒ Boolean
28 29 30 |
# File 'lib/config.rb', line 28 def include?(k) @config.include?(k) end |
#port ⇒ Object
36 37 38 |
# File 'lib/config.rb', line 36 def port @config['port'] || 49456 end |
#projects ⇒ Object
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 |
#reload ⇒ Object
14 15 16 |
# File 'lib/config.rb', line 14 def reload @config = YAML.load_file(@path) end |