Class: RiceBubble::Attributes::Array

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#membersObject (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

Returns:



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