Class: Strict::Attributes::Coercer

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

Constant Summary collapse

NOT_PROVIDED =
::Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes_class) ⇒ Coercer

Returns a new instance of Coercer.



10
11
12
# File 'lib/strict/attributes/coercer.rb', line 10

def initialize(attributes_class)
  @attributes_class = attributes_class
end

Instance Attribute Details

#attributes_classObject (readonly)

Returns the value of attribute attributes_class.



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

def attributes_class
  @attributes_class
end

Instance Method Details

#call(value) ⇒ Object



14
15
16
17
18
19
# File 'lib/strict/attributes/coercer.rb', line 14

def call(value)
  return value if value.nil? || value.instance_of?(attributes_class)
  return value unless value.respond_to?(:to_h)

  coerce(value.to_h)
end