Class: ConfigX::Builder
- Inherits:
-
Object
- Object
- ConfigX::Builder
- Defined in:
- lib/config_x/builder.rb
Instance Attribute Summary collapse
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Class Method Summary collapse
-
.load ⇒ UntypedConfig
Loads the configuration.
-
.source(source, **args) ⇒ Source
Creates a source object based on the type of the input.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#add_source(source, **args) ⇒ Builder
Adds a source to the builder.
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #load(config_class:) ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
34 35 36 |
# File 'lib/config_x/builder.rb', line 34 def initialize @sources = [] end |
Instance Attribute Details
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
38 39 40 |
# File 'lib/config_x/builder.rb', line 38 def sources @sources end |
Class Method Details
.load ⇒ UntypedConfig
Loads the configuration.
27 |
# File 'lib/config_x/builder.rb', line 27 def load(...) = new.load(...) |
.source(source, **args) ⇒ Source
Creates a source object based on the type of the input.
13 14 15 16 17 18 19 20 21 |
# File 'lib/config_x/builder.rb', line 13 def source(source, **args) case source in Source then source in Hash then HashSource.new(source) in String then FileSource.new(source) in Pathname then FileSource.new(source) in ENV then EnvSource.new(ENV, **args) end end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/config_x/builder.rb', line 54 def ==(other) other.is_a?(self.class) && other.sources == sources end |
#add_source(source, **args) ⇒ Builder
Adds a source to the builder.
45 46 47 48 |
# File 'lib/config_x/builder.rb', line 45 def add_source(source, **args) sources << self.class.source(source, **args) self end |
#load(config_class:) ⇒ Object
50 51 52 |
# File 'lib/config_x/builder.rb', line 50 def load(config_class:) config_class.new(read_from_sources) end |