Class: ENVied::Configuration
- Inherits:
-
Object
- Object
- ENVied::Configuration
- Defined in:
- lib/envied/configuration.rb
Instance Attribute Summary collapse
-
#coercer ⇒ Object
readonly
Returns the value of attribute coercer.
-
#current_group ⇒ Object
readonly
Returns the value of attribute current_group.
-
#defaults_enabled ⇒ Object
readonly
Returns the value of attribute defaults_enabled.
Class Method Summary collapse
Instance Method Summary collapse
- #defaults_enabled? ⇒ Boolean
- #enable_defaults!(value = nil, &block) ⇒ Object
- #group(name, &block) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Configuration
constructor
A new instance of Configuration.
- #variable(name, type = :String, options = {}) ⇒ Object
- #variables ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Configuration
5 6 7 8 9 |
# File 'lib/envied/configuration.rb', line 5 def initialize( = {}, &block) @defaults_enabled = .fetch(:enable_defaults, false) @coercer = .fetch(:coercer, Coercer.new) instance_eval(&block) if block_given? end |
Instance Attribute Details
#coercer ⇒ Object (readonly)
Returns the value of attribute coercer.
3 4 5 |
# File 'lib/envied/configuration.rb', line 3 def coercer @coercer end |
#current_group ⇒ Object (readonly)
Returns the value of attribute current_group.
3 4 5 |
# File 'lib/envied/configuration.rb', line 3 def current_group @current_group end |
#defaults_enabled ⇒ Object (readonly)
Returns the value of attribute defaults_enabled.
3 4 5 |
# File 'lib/envied/configuration.rb', line 3 def defaults_enabled @defaults_enabled end |
Class Method Details
.load(options = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/envied/configuration.rb', line 11 def self.load( = {}) envfile = File.('Envfile') new().tap do |v| v.instance_eval(File.read(envfile), envfile) end end |
Instance Method Details
#defaults_enabled? ⇒ Boolean
22 23 24 25 26 |
# File 'lib/envied/configuration.rb', line 22 def defaults_enabled? @defaults_enabled.respond_to?(:call) ? @defaults_enabled.call : @defaults_enabled end |
#enable_defaults!(value = nil, &block) ⇒ Object
18 19 20 |
# File 'lib/envied/configuration.rb', line 18 def enable_defaults!(value = nil, &block) @defaults_enabled = (value.nil? ? block : value) end |
#group(name, &block) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/envied/configuration.rb', line 37 def group(name, &block) @current_group = name.to_sym yield ensure @current_group = nil end |
#variable(name, type = :String, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/envied/configuration.rb', line 28 def variable(name, type = :String, = {}) unless coercer.supported_type?(type) raise ArgumentError, "Variable type (of #{name}) should be one of #{coercer.supported_types}" end [:group] = current_group if current_group variables << ENVied::Variable.new(name, type, ) end |
#variables ⇒ Object
44 45 46 |
# File 'lib/envied/configuration.rb', line 44 def variables @variables ||= [] end |