Class: RiceBubble::Attributes::Object
- Defined in:
- lib/rice_bubble/attributes/object.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #call(value, path: '') ⇒ Object
-
#initialize(children = {}) ⇒ Object
constructor
A new instance of Object.
- #valid?(value) ⇒ Boolean
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
#children ⇒ Object (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
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 |