Class: Kangaru::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/kangaru/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



7
8
9
# File 'lib/kangaru/config.rb', line 7

def initialize
  @configurators = set_configurators!
end

Instance Attribute Details

#configuratorsObject (readonly)

Returns the value of attribute configurators.



5
6
7
# File 'lib/kangaru/config.rb', line 5

def configurators
  @configurators
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/kangaru/config.rb', line 21

def [](key)
  configurators[key.to_sym]
end

#errorsObject



34
35
36
# File 'lib/kangaru/config.rb', line 34

def errors
  configurators.values.flat_map(&:errors)
end

#import!(path) ⇒ Object



11
12
13
14
15
# File 'lib/kangaru/config.rb', line 11

def import!(path)
  read_external_config(path).each do |key, config|
    configurators[key]&.merge!(**config)
  end
end

#serialiseObject



17
18
19
# File 'lib/kangaru/config.rb', line 17

def serialise
  configurators.transform_values(&:serialise)
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/kangaru/config.rb', line 25

def valid?
  validate
  errors.empty?
end

#validateObject



30
31
32
# File 'lib/kangaru/config.rb', line 30

def validate
  configurators.each_value(&:validate)
end