Class: Constancy::Config
- Inherits:
-
Object
- Object
- Constancy::Config
- Defined in:
- lib/constancy/config.rb
Constant Summary collapse
- CONFIG_FILENAMES =
%w( constancy.yml )
- VALID_CONFIG_KEYS =
%w( sync consul constancy )
- VALID_CONSUL_CONFIG_KEYS =
%w( url datacenter )
- VALID_CONSTANCY_CONFIG_KEYS =
%w( verbose chomp delete color )
- DEFAULT_CONSUL_URL =
"http://localhost:8500"
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#consul ⇒ Object
Returns the value of attribute consul.
-
#sync_targets ⇒ Object
Returns the value of attribute sync_targets.
-
#target_whitelist ⇒ Object
Returns the value of attribute target_whitelist.
Class Method Summary collapse
-
.discover(dir: nil) ⇒ Object
discover the nearest config file.
Instance Method Summary collapse
- #chomp? ⇒ Boolean
- #color? ⇒ Boolean
- #delete? ⇒ Boolean
-
#initialize(path: nil, targets: nil) ⇒ Config
constructor
A new instance of Config.
- #verbose? ⇒ Boolean
Constructor Details
#initialize(path: nil, targets: nil) ⇒ Config
Returns a new instance of Config.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/constancy/config.rb', line 32 def initialize(path: nil, targets: nil) if path.nil? or File.directory?(path) self.config_file = Constancy::Config.discover(dir: path) elsif File.exist?(path) self.config_file = path else raise Constancy::ConfigFileNotFound.new end if self.config_file.nil? or not File.exist?(self.config_file) or not File.readable?(self.config_file) raise Constancy::ConfigFileNotFound.new end self.config_file = File.(self.config_file) self.base_dir = File.dirname(self.config_file) self.target_whitelist = targets parse! end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
14 15 16 |
# File 'lib/constancy/config.rb', line 14 def base_dir @base_dir end |
#config_file ⇒ Object
Returns the value of attribute config_file.
14 15 16 |
# File 'lib/constancy/config.rb', line 14 def config_file @config_file end |
#consul ⇒ Object
Returns the value of attribute consul.
14 15 16 |
# File 'lib/constancy/config.rb', line 14 def consul @consul end |
#sync_targets ⇒ Object
Returns the value of attribute sync_targets.
14 15 16 |
# File 'lib/constancy/config.rb', line 14 def sync_targets @sync_targets end |
#target_whitelist ⇒ Object
Returns the value of attribute target_whitelist.
14 15 16 |
# File 'lib/constancy/config.rb', line 14 def target_whitelist @target_whitelist end |
Class Method Details
.discover(dir: nil) ⇒ Object
discover the nearest config file
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/constancy/config.rb', line 18 def discover(dir: nil) dir ||= Dir.pwd CONFIG_FILENAMES.each do |filename| full_path = File.join(dir, filename) if File.exist?(full_path) return full_path end end dir == "/" ? nil : self.discover(dir: File.dirname(dir)) end |
Instance Method Details
#chomp? ⇒ Boolean
55 56 57 |
# File 'lib/constancy/config.rb', line 55 def chomp? @do_chomp end |
#color? ⇒ Boolean
63 64 65 |
# File 'lib/constancy/config.rb', line 63 def color? @use_color end |
#delete? ⇒ Boolean
59 60 61 |
# File 'lib/constancy/config.rb', line 59 def delete? @do_delete end |
#verbose? ⇒ Boolean
51 52 53 |
# File 'lib/constancy/config.rb', line 51 def verbose? @is_verbose end |