Class: ActiveModel::Type::Binary
- Defined in:
- activemodel/lib/active_model/type/binary.rb
Overview
Attribute type for representation of binary data. This type is registered under the :binary
key.
Non-string values are coerced to strings using their to_s
method.
Defined Under Namespace
Classes: Data
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
- #binary? ⇒ Boolean
- #cast(value) ⇒ Object
- #changed_in_place?(raw_old_value, value) ⇒ Boolean
- #serialize(value) ⇒ Object
- #type ⇒ Object
Methods inherited from Value
#==, #as_json, #assert_valid_value, #changed?, #deserialize, #force_equality?, #hash, #immutable_value, #initialize, #map, #serializable?, #type_cast_for_schema, #value_constructed_by_mass_assignment?
Constructor Details
This class inherits a constructor from ActiveModel::Type::Value
Instance Method Details
#binary? ⇒ Boolean
14 15 16 |
# File 'activemodel/lib/active_model/type/binary.rb', line 14 def binary? true end |
#cast(value) ⇒ Object
18 19 20 21 22 23 24 |
# File 'activemodel/lib/active_model/type/binary.rb', line 18 def cast(value) if value.is_a?(Data) value.to_s else super end end |
#changed_in_place?(raw_old_value, value) ⇒ Boolean
31 32 33 34 |
# File 'activemodel/lib/active_model/type/binary.rb', line 31 def changed_in_place?(raw_old_value, value) old_value = deserialize(raw_old_value) old_value != value end |
#serialize(value) ⇒ Object
26 27 28 29 |
# File 'activemodel/lib/active_model/type/binary.rb', line 26 def serialize(value) return if value.nil? Data.new(super) end |
#type ⇒ Object
10 11 12 |
# File 'activemodel/lib/active_model/type/binary.rb', line 10 def type :binary end |