Class: ActiveRecord::Type::Value
- Inherits:
-
Object
- Object
- ActiveRecord::Type::Value
- Defined in:
- lib/active_record/type/value.rb
Overview
:nodoc:
Direct Known Subclasses
AttributeMethods::TimeZoneConversion::TimeZoneConverter, ConnectionAdapters::PostgreSQL::OID::Array, ConnectionAdapters::PostgreSQL::OID::Bit, ConnectionAdapters::PostgreSQL::OID::Cidr, ConnectionAdapters::PostgreSQL::OID::Enum, ConnectionAdapters::PostgreSQL::OID::Hstore, ConnectionAdapters::PostgreSQL::OID::Json, ConnectionAdapters::PostgreSQL::OID::Point, ConnectionAdapters::PostgreSQL::OID::Range, ConnectionAdapters::PostgreSQL::OID::Uuid, ConnectionAdapters::PostgreSQL::OID::Vector, Binary, Boolean, Date, DateTime, Decimal, Float, Integer, Serialized, String, Time
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#binary? ⇒ Boolean
:nodoc:.
-
#changed?(old_value, new_value, _new_value_before_type_cast) ⇒ Boolean
Determines whether a value has changed for dirty checking.
-
#changed_in_place? ⇒ Boolean
Determines whether the mutable value has been modified since it was read.
-
#initialize(options = {}) ⇒ Value
constructor
Valid options are
precision
,scale
, andlimit
. -
#klass ⇒ Object
:nodoc:.
-
#number? ⇒ Boolean
:nodoc:.
-
#text? ⇒ Boolean
These predicates are not documented, as I need to look further into their use, and see if they can be removed entirely.
-
#type ⇒ Object
The simplified type that this object represents.
-
#type_cast_for_database(value) ⇒ Object
Cast a value from the ruby type to a type that the database knows how to understand.
-
#type_cast_for_schema(value) ⇒ Object
Type cast a value for schema dumping.
-
#type_cast_from_database(value) ⇒ Object
Type casts a string from the database into the appropriate ruby type.
-
#type_cast_from_user(value) ⇒ Object
Type casts a value from user input (e.g. from a setter).
Constructor Details
#initialize(options = {}) ⇒ Value
Valid options are precision
, scale
, and limit
. They are only used when dumping schema.
8 9 10 11 12 13 |
# File 'lib/active_record/type/value.rb', line 8 def initialize( = {}) .assert_valid_keys(:precision, :scale, :limit) @precision = [:precision] @scale = [:scale] @limit = [:limit] end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/active_record/type/value.rb', line 4 def limit @limit end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
4 5 6 |
# File 'lib/active_record/type/value.rb', line 4 def precision @precision end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
4 5 6 |
# File 'lib/active_record/type/value.rb', line 4 def scale @scale end |
Instance Method Details
#==(other) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/active_record/type/value.rb', line 83 def ==(other) self.class == other.class && precision == other.precision && scale == other.scale && limit == other.limit end |
#binary? ⇒ Boolean
:nodoc:
61 62 63 |
# File 'lib/active_record/type/value.rb', line 61 def binary? # :nodoc: false end |
#changed?(old_value, new_value, _new_value_before_type_cast) ⇒ Boolean
Determines whether a value has changed for dirty checking. old_value
and new_value
will always be type-cast. Types should not need to override this method.
71 72 73 |
# File 'lib/active_record/type/value.rb', line 71 def changed?(old_value, new_value, _new_value_before_type_cast) old_value != new_value end |
#changed_in_place? ⇒ Boolean
Determines whether the mutable value has been modified since it was read. Returns false
by default. This method should not be overridden directly. Types which return a mutable value should include Type::Mutable
, which will define this method.
79 80 81 |
# File 'lib/active_record/type/value.rb', line 79 def changed_in_place?(*) false end |
#klass ⇒ Object
:nodoc:
65 66 |
# File 'lib/active_record/type/value.rb', line 65 def klass # :nodoc: end |
#number? ⇒ Boolean
:nodoc:
57 58 59 |
# File 'lib/active_record/type/value.rb', line 57 def number? # :nodoc: false end |
#text? ⇒ Boolean
These predicates are not documented, as I need to look further into their use, and see if they can be removed entirely.
53 54 55 |
# File 'lib/active_record/type/value.rb', line 53 def text? # :nodoc: false end |
#type ⇒ Object
The simplified type that this object represents. Returns a symbol such as :string
or :integer
17 |
# File 'lib/active_record/type/value.rb', line 17 def type; end |
#type_cast_for_database(value) ⇒ Object
Cast a value from the ruby type to a type that the database knows how to understand. The returned value from this method should be a String
, Numeric
, Date
, Time
, Symbol
, true
, false
, or nil
41 42 43 |
# File 'lib/active_record/type/value.rb', line 41 def type_cast_for_database(value) value end |
#type_cast_for_schema(value) ⇒ Object
Type cast a value for schema dumping. This method is private, as we are hoping to remove it entirely.
47 48 49 |
# File 'lib/active_record/type/value.rb', line 47 def type_cast_for_schema(value) # :nodoc: value.inspect end |
#type_cast_from_database(value) ⇒ Object
Type casts a string from the database into the appropriate ruby type. Classes which do not need separate type casting behavior for database and user provided values should override cast_value
instead.
22 23 24 |
# File 'lib/active_record/type/value.rb', line 22 def type_cast_from_database(value) type_cast(value) end |
#type_cast_from_user(value) ⇒ Object
Type casts a value from user input (e.g. from a setter). This value may be a string from the form builder, or an already type cast value provided manually to a setter.
Classes which do not need separate type casting behavior for database and user provided values should override type_cast
or cast_value
instead.
33 34 35 |
# File 'lib/active_record/type/value.rb', line 33 def type_cast_from_user(value) type_cast(value) end |