Class: ActiveModel::Coercer
- Inherits:
-
Object
- Object
- ActiveModel::Coercer
- Defined in:
- lib/active_model/coercer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cast(value) ⇒ Object
-
#initialize(type) ⇒ Coercer
constructor
A new instance of Coercer.
Constructor Details
#initialize(type) ⇒ Coercer
Returns a new instance of Coercer.
5 6 7 |
# File 'lib/active_model/coercer.rb', line 5 def initialize(type) @coercion_type = self.class.defined_coercions.fetch(type) end |
Class Method Details
.defined_coercions ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_model/coercer.rb', line 14 def defined_coercions { integer: ActiveModel::Coercions::Types::Integer, float: ActiveModel::Coercions::Types::Float, symbol: ActiveModel::Coercions::Types::Symbol, time: ActiveModel::Coercions::Types::Time, date: ActiveModel::Coercions::Types::Date, datetime: ActiveModel::Coercions::Types::DateTime, boolean: ActiveModel::Coercions::Types::Boolean } end |
Instance Method Details
#cast(value) ⇒ Object
9 10 11 |
# File 'lib/active_model/coercer.rb', line 9 def cast(value) @coercion_type.new(value).to_value end |