Class: ActionSet::Instruction::Value

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

Defined Under Namespace

Classes: ActiveModelAdapter, BooleanAdapter, PlainRubyAdapter, TimeWithZoneAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Value

Returns a new instance of Value.



8
9
10
# File 'lib/action_set/instruction/value.rb', line 8

def initialize(value)
  @raw = value
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/action_set/instruction/value.rb', line 6

def raw
  @raw
end

Instance Method Details

#cast(to:) ⇒ Object



12
13
14
15
16
17
# File 'lib/action_set/instruction/value.rb', line 12

def cast(to:)
  adapters.map do |adapter|
    value = adapter.new(@raw, to).process
    return value unless value.nil?
  end.compact.first || @raw
end