Class: Strict::Attributes::Coercer

Inherits:
Object
  • Object
show all
Defined in:
lib/strict/attributes/coercer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes_class) ⇒ Coercer

Returns a new instance of Coercer.



8
9
10
# File 'lib/strict/attributes/coercer.rb', line 8

def initialize(attributes_class)
  @attributes_class = attributes_class
end

Instance Attribute Details

#attributes_classObject (readonly)

Returns the value of attribute attributes_class.



6
7
8
# File 'lib/strict/attributes/coercer.rb', line 6

def attributes_class
  @attributes_class
end

Instance Method Details

#call(value) ⇒ Object



12
13
14
15
16
# File 'lib/strict/attributes/coercer.rb', line 12

def call(value)
  return value if value.nil? || !value.respond_to?(:to_h)

  coerce(value.to_h)
end