Class: ConfigX::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/config_x/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.

Examples:

ConfigX.new("production").load
ConfigX.new.load


34
35
36
# File 'lib/config_x/builder.rb', line 34

def initialize
  @sources = []
end

Instance Attribute Details

#sourcesObject (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

.loadUntypedConfig

Loads the configuration.

Returns:

See Also:



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.

Parameters:

  • source (Source, Hash, String, Pathname, ENV)

    the source input

  • args (Hash)

    additional arguments for the source

Returns:



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.

Parameters:

  • source (Source, Hash, String, Pathname, ENV)

    the source input

  • args (Hash)

    additional arguments for the source

Returns:



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