Class: Configurable::ConfigTypes::NestType

Inherits:
ObjectType
  • Object
show all
Defined in:
lib/configurable/config_types/nest_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ObjectType

cast, errors, inherited, matches, matches?, subclass, uncast

Constructor Details

#initialize(attrs = {}) ⇒ NestType

Returns a new instance of NestType.



14
15
16
17
18
19
20
21
22
# File 'lib/configurable/config_types/nest_type.rb', line 14

def initialize(attrs={})
  @configurable = attrs[:configurable]
  
  unless configurable.respond_to?(:config) && configurable.class.respond_to?(:configs)
    raise ArgumentError, "invalid configurable: #{configurable.inspect}"
  end
  
  super
end

Instance Attribute Details

#configurableObject (readonly)

Returns the value of attribute configurable.



12
13
14
# File 'lib/configurable/config_types/nest_type.rb', line 12

def configurable
  @configurable
end

Class Method Details

.init(&block) ⇒ Object



5
6
7
8
# File 'lib/configurable/config_types/nest_type.rb', line 5

def init(&block)
  define_method(:init, &block) if block
  self
end

Instance Method Details

#cast(input) ⇒ Object



30
31
32
# File 'lib/configurable/config_types/nest_type.rb', line 30

def cast(input)
  configurable.class.configs.import(input)
end

#init(input) ⇒ Object



24
25
26
27
28
# File 'lib/configurable/config_types/nest_type.rb', line 24

def init(input)
  obj = configurable.dup
  obj.config.merge!(input)
  obj
end

#uncast(value) ⇒ Object



34
35
36
# File 'lib/configurable/config_types/nest_type.rb', line 34

def uncast(value)
  configurable.class.configs.export(value)
end