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 vault constancy )
- VALID_CONSUL_CONFIG_KEYS =
%w( url datacenter token_source )
- VALID_VAULT_CONFIG_KEYS =
%w( url consul_token_path consul_token_field )
- VALID_CONSTANCY_CONFIG_KEYS =
%w( verbose chomp delete color )
- DEFAULT_CONSUL_URL =
"http://localhost:8500"- DEFAULT_CONSUL_TOKEN_SOURCE =
"none"- DEFAULT_VAULT_CONSUL_TOKEN_FIELD =
"token"
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#call_external_apis ⇒ Object
Returns the value of attribute call_external_apis.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#consul ⇒ Object
Returns the value of attribute consul.
-
#consul_token_source ⇒ Object
Returns the value of attribute consul_token_source.
-
#sync_targets ⇒ Object
Returns the value of attribute sync_targets.
-
#target_whitelist ⇒ Object
Returns the value of attribute target_whitelist.
-
#vault_config ⇒ Object
Returns the value of attribute vault_config.
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, call_external_apis: true) ⇒ Config
constructor
A new instance of Config.
- #verbose? ⇒ Boolean
Constructor Details
#initialize(path: nil, targets: nil, call_external_apis: true) ⇒ Config
Returns a new instance of Config.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/constancy/config.rb', line 39 def initialize(path: nil, targets: nil, call_external_apis: true) 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 self.call_external_apis = call_external_apis parse! end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def base_dir @base_dir end |
#call_external_apis ⇒ Object
Returns the value of attribute call_external_apis.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def call_external_apis @call_external_apis end |
#config_file ⇒ Object
Returns the value of attribute config_file.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def config_file @config_file end |
#consul ⇒ Object
Returns the value of attribute consul.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def consul @consul end |
#consul_token_source ⇒ Object
Returns the value of attribute consul_token_source.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def consul_token_source @consul_token_source end |
#sync_targets ⇒ Object
Returns the value of attribute sync_targets.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def sync_targets @sync_targets end |
#target_whitelist ⇒ Object
Returns the value of attribute target_whitelist.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def target_whitelist @target_whitelist end |
#vault_config ⇒ Object
Returns the value of attribute vault_config.
21 22 23 |
# File 'lib/constancy/config.rb', line 21 def vault_config @vault_config end |
Class Method Details
.discover(dir: nil) ⇒ Object
discover the nearest config file
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/constancy/config.rb', line 25 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
63 64 65 |
# File 'lib/constancy/config.rb', line 63 def chomp? @do_chomp end |
#color? ⇒ Boolean
71 72 73 |
# File 'lib/constancy/config.rb', line 71 def color? @use_color end |
#delete? ⇒ Boolean
67 68 69 |
# File 'lib/constancy/config.rb', line 67 def delete? @do_delete end |
#verbose? ⇒ Boolean
59 60 61 |
# File 'lib/constancy/config.rb', line 59 def verbose? @is_verbose end |