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


28
29
30
# File 'lib/config_x/builder.rb', line 28

def initialize
  @sources = []
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



32
33
34
# File 'lib/config_x/builder.rb', line 32

def sources
  @sources
end

Class Method Details

.loadObject

See Also:



19
20
21
# File 'lib/config_x/builder.rb', line 19

def load(...)
  new(...).load
end

.source(source, **args) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/config_x/builder.rb', line 8

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



47
48
49
# File 'lib/config_x/builder.rb', line 47

def ==(other)
  other.is_a?(self.class) && other.sources == sources
end

#add_source(source, **args) ⇒ Object



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

def add_source(source, **args)
  sources << self.class.source(source, **args)
  self
end

#loadObject

Loads config in the following order:

1. Reads default config
2. Reads all the config files provided in the order
3. Reads environment variables


43
44
45
# File 'lib/config_x/builder.rb', line 43

def load
  Config.new(read_from_sources)
end