Class: RiceBubble::Attributes::Object

Inherits:
Base
  • Object
show all
Defined in:
lib/rice_bubble/attributes/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#description, #fetch, #optional, #valid_types

Constructor Details

#initialize(children = {}) ⇒ Object

Returns a new instance of Object.



6
7
8
9
10
11
# File 'lib/rice_bubble/attributes/object.rb', line 6

def initialize(children = {}, &)
  super(&)
  @children = Attributes.new(
    children.transform_values(&method(:instantiate))
  )
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



4
5
6
# File 'lib/rice_bubble/attributes/object.rb', line 4

def children
  @children
end

Instance Method Details

#call(value, path: '') ⇒ Object



19
20
21
22
23
24
# File 'lib/rice_bubble/attributes/object.rb', line 19

def call(value, path: '')
  children.to_h do |name, attr|
    [name,
     attr.call(value[name] || value[name.to_s], path: "#{path}.#{name}")]
  end
end

#valid?(value) ⇒ Boolean

Returns:



13
14
15
16
17
# File 'lib/rice_bubble/attributes/object.rb', line 13

def valid?(value)
  children.all? do |name, attr|
    attr.valid?(value[name])
  end
end