Class: Yarrow::Schema::Types::List

Inherits:
TypeClass
  • Object
show all
Defined in:
lib/yarrow/schema/types.rb

Instance Attribute Summary collapse

Attributes inherited from TypeClass

#accepts, #unit

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TypeClass

#accept, #cast, #check_instance_of!, #check_kind_of!, #check_respond_to_all!, #check_respond_to_any!, #coerce, #should_coerce?, #|

Constructor Details

#initialize(unit_type, element_type) ⇒ List

Returns a new instance of List.



180
181
182
183
# File 'lib/yarrow/schema/types.rb', line 180

def initialize(unit_type, element_type)
  @element_type = element_type
  super(unit_type)
end

Instance Attribute Details

#element_typeObject (readonly)

Returns the value of attribute element_type.



177
178
179
# File 'lib/yarrow/schema/types.rb', line 177

def element_type
  @element_type
end

Class Method Details

.anyObject



168
169
170
171
# File 'lib/yarrow/schema/types.rb', line 168

def self.any
  # Constraint: must be array instance
  new(Instance.of(Array), Any.new)
end

.of(wrapped_type) ⇒ Object



173
174
175
# File 'lib/yarrow/schema/types.rb', line 173

def self.of(wrapped_type)
  new(Instance.of(Array), Instance.of(wrapped_type))
end

Instance Method Details

#accept_elements(accept_type) ⇒ Object



185
186
187
188
# File 'lib/yarrow/schema/types.rb', line 185

def accept_elements(accept_type)
  element_type.accept(accept_type)
  self
end

#check(input) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/yarrow/schema/types.rb', line 190

def check(input)
  converted = container_type.cast(input)

  converted.map do |item|
    element_type.cast(item)
  end
end