Class: Environmentor::ConfigManager

Inherits:
Object
  • Object
show all
Defined in:
lib/environmentor/config_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ ConfigManager

Returns a new instance of ConfigManager.



9
10
11
12
# File 'lib/environmentor/config_manager.rb', line 9

def initialize(mod)
  @mod = mod
  @schemas = []
end

Instance Attribute Details

#schemasObject (readonly)

Returns the value of attribute schemas.



7
8
9
# File 'lib/environmentor/config_manager.rb', line 7

def schemas
  @schemas
end

Instance Method Details

#delegate_from(mod) ⇒ Object



37
38
39
40
41
# File 'lib/environmentor/config_manager.rb', line 37

def delegate_from(mod)
  schemas.each do |s|
    s.map_to mod
  end
end

#delegate_to(mod) ⇒ Object



31
32
33
34
35
# File 'lib/environmentor/config_manager.rb', line 31

def delegate_to(mod)
  mod.environmentor.schemas.each do |s|
    s.map_to @mod
  end
end

#with_mapper(mappers, **opts, &block) ⇒ Object Also known as: with_mappers



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/environmentor/config_manager.rb', line 14

def with_mapper(mappers, **opts, &block)
  defined_at = caller.first
  mappers = Array(mappers)

  if mappers.size > 1 && opts.size > 0
    raise ArgumentError, "Cannot accept options when passing multiple mappers: they would be applied to all mappers. Create instances of mappers, pass options to those, and give me those instances."
  end

  mappers = mappers.map { |m| Environmentor::Mappers.deduce(m, **opts) }.
    compact

  Schema.new(mappers, defined_at: defined_at, **opts, &block).tap do |s|
    s.map_to @mod
    @schemas << s
  end
end