Class: HashCast::Casters::ArrayCaster

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_cast/casters/array_caster.rb

Class Method Summary collapse

Class Method Details

.cast(value, attr_name, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hash_cast/casters/array_caster.rb', line 3

def self.cast(value, attr_name, options = {})
  unless value.is_a?(Array)
    raise HashCast::Errors::CastingError, "should be an array"
  end

  if HashCast.config.array_size_validator_enabled
    if value.size > HashCast.config.array_size_validator_limit
      HashCast.config.array_size_validator_callback.call(value, attr_name, options)
    end
  end

  if options[:each]
    cast_array_items(value, attr_name, options)
  else
    value
  end
end