Class: RiceBubble::Attributes::Array
- Defined in:
- lib/rice_bubble/attributes/array.rb
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
Instance Method Summary collapse
- #call(value, path: '') ⇒ Object
-
#initialize(members) ⇒ Array
constructor
A new instance of Array.
- #valid?(value) ⇒ Boolean
Methods inherited from Base
#description, #fetch, #optional, #valid_types
Constructor Details
#initialize(members) ⇒ Array
Returns a new instance of Array.
6 7 8 9 |
# File 'lib/rice_bubble/attributes/array.rb', line 6 def initialize(members, &) super(&) @members = instantiate(members) end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
4 5 6 |
# File 'lib/rice_bubble/attributes/array.rb', line 4 def members @members end |
Instance Method Details
#call(value, path: '') ⇒ Object
19 20 21 22 23 |
# File 'lib/rice_bubble/attributes/array.rb', line 19 def call(value, path: '') (value || []).map.with_index do |child, index| members.call(child, path: "#{path}[#{index}]") end end |
#valid?(value) ⇒ Boolean
11 12 13 14 15 16 17 |
# File 'lib/rice_bubble/attributes/array.rb', line 11 def valid?(value) return false unless value.respond_to?(:all?) value.all? do |child| members.valid?(child) end end |