Class: ActionSet::AttributeValue

Inherits:
Object
  • Object
show all
Defined in:
lib/action_set/attribute_value.rb

Defined Under Namespace

Classes: ActiveModelAdapter, BooleanAdapter, PlainRubyAdapter, TimeWithZoneAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ AttributeValue

Returns a new instance of AttributeValue.



7
8
9
# File 'lib/action_set/attribute_value.rb', line 7

def initialize(value)
  @raw = value
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



5
6
7
# File 'lib/action_set/attribute_value.rb', line 5

def raw
  @raw
end

Instance Method Details

#cast(to:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/action_set/attribute_value.rb', line 11

def cast(to:)
  adapters.reduce(nil) do |_, adapter|
    mayble_value_or_nil = adapter.new(@raw, to).process
    next nil if mayble_value_or_nil.nil?

    return mayble_value_or_nil
  end

  @raw
end