aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #15788 from sgrif/sg-mutable-stringsRafael Mendonça França2014-06-271-1/+16
|\ | | | | | | Detect in-place modifications on Strings
| * Detect in-place modifications on StringsSean Griffin2014-06-171-1/+16
| |
* | Doc pass for `Type::Value` [ci skip]Sean Griffin2014-06-242-23/+43
| |
* | Always assume strings with non-numeric characters change numeric typesSean Griffin2014-06-241-3/+3
| | | | | | | | | | | | | | | | We previously only did this if the old value was zero, to make sure numericality validations run and failed if the user gave 'wibble' as the value, which would be type cast to 0. However, numericality validations will fail if there are any non-numeric characters in the string, so 5 -> '5wibble' should also be marked as changed.
* | add missing `:nodoc:` for recent refactorings. [ci skip]Yves Senn2014-06-242-2/+2
| | | | | | | | | | | | | | | | | | | | Adding `# :nodoc:` to the parent `class` / `module` is not going to ignore nested classes or modules. There is a modifier `# :nodoc: all` but sadly the containing class or module will continue to be in the docs. /cc @sgrif
* | Small typoAnton Cherepanov2014-06-231-1/+1
| |
* | Further simplify `changed?` conditional for numeric typesSean Griffin2014-06-191-12/+6
|/ | | | | | | `Type::Integer.new.type_cast('') # => nil`, we do not need a special case to handle this, `nil => ''` already returns false. The only case we need to handle is `0 => 'wibble'` should be changed, while `0 => '0'` should not.
* Move array database type casting to the Array typeSean Griffin2014-06-171-0/+10
| | | | | | | | | The case where we have a column object, but don't have a type cast method involves type casting the default value when changing the schema. We get one of the column definition structs instead. That is a case that I'm trying to remove overall, but in the short term, we can achieve the same behavior without needing to pass the adapter to the array type by creating a fake type that proxies to the adapter.
* Remove `serialized?` from the type interfaceSean Griffin2014-06-132-8/+0
|
* Detect in-place changes on mutable AR attributesSean Griffin2014-06-133-4/+22
| | | | | | We have several mutable types on Active Record now. (Serialized, JSON, HStore). We need to be able to detect if these have been modified in place.
* Keep the types of virtual columns after yaml serializationSean Griffin2014-06-101-0/+11
| | | | | On MySQL and PostgreSQL, the adapter does not type cast virtual columns for us.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-092-7/+10
| | | | | | | | In some cases there is a difference between the two, we should always be doing one or the other. For convenience, `type_cast` is still a private method on type, so new types that do not need different behavior don't need to implement two methods, but it has been moved to private so it cannot be used accidentally.
* Make `_before_type_cast` actually be before type castSean Griffin2014-06-093-8/+19
| | | | | | | | | | | | | - The following is now true for all types, all the time - `model.attribute_before_type_cast == given_value` - `model.attribute == model.save_and_reload.attribute` - `model.attribute == model.dup.attribute` - `model.attribute == YAML.load(YAML.dump(model)).attribute` - Removes the remaining types implementing `type_cast_for_write` - Simplifies the implementation of time zone aware attributes - Brings tz aware attributes closer to being implemented as an attribute decorator - Adds additional point of control for custom types
* Do not type cast twice on attribute assignmentSean Griffin2014-06-073-9/+5
| | | | | | | | | | | | | The definition of `write_attribute` in dirty checking ultimately leads to the columns calling `type_cast` on the value to perform the comparison. However, this is a potentially expensive computation that we cache when it occurs in `read_attribute`. The only case that we need the non-type-cast form is for numeric, so we pass that through as well (something I'm looking to remove in the future). This also reduces the number of places that manually access various stages in an attribute's type casting lifecycle, which will aid in one of the larger refactorings that I'm working on.
* Removed unused `klass` definitions from typesSean Griffin2014-06-066-21/+0
| | | | Only `Date` and `Time` are handled.
* Don't mess with `_before_type_cast` for numeric typesSean Griffin2014-06-061-7/+8
|
* serialized Type should delegate `type_cast_for_write` to underlying TypeYves Senn2014-06-061-1/+1
| | | | | | | This adds a regression test for #14411, which was fixed by #15503. Closes #14411 Closes #14595
* Merge pull request #15486 from sgrif/sg-binary-quotingMatthew Draper2014-06-041-0/+18
|\ | | | | Refactor quoting of binary data to not be based on the column type
| * Refactor quoting of binary data to not be based on the column typeSean Griffin2014-06-031-0/+18
| |
* | Refactor determination of whether the field has changedSean Griffin2014-06-033-0/+36
|/ | | | | The types know more about what is going on than the dirty module. Let's ask them!
* docs, fix typo [ci skip]Yves Senn2014-06-021-2/+2
|
* Remove most code related to serialized propertiesSean Griffin2014-06-012-25/+11
| | | | | | | | | | | Nearly completely implemented in terms of custom properties. `_before_type_cast` now stores the raw serialized string consistently, which removes the need to keep track of "state". The following is now consistently true: - `model.serialized == model.reload.serialized` - A model can be dumped and loaded infinitely without changing - A model can be saved and reloaded infinitely without changing
* refactor, introduce `Type#type_cast_for_schema` to cast for schema.rbYves Senn2014-05-304-0/+16
| | | | | | | This removes the case statement in `SchemaDumper` and gives every `Type` the possibility to control the SchemaDumper default value output. /cc @sgrif
* Move `type_cast_for_write` behavior over to the serialized type objectSean Griffin2014-05-292-8/+38
|
* Refactor serialized types to be partially defined as custom propertiesSean Griffin2014-05-292-0/+32
| | | | | | | Many of the methods defined in `AttributeMethods::Serialization` can be refactored onto this type as well, but this is a reasonable small step. Removes the `Type` class, and the need for `decorate_columns` to handle serialized types.
* Move types to the top level `ActiveRecord` namespaceSean Griffin2014-05-2716-0/+439
`ActiveRecord::ConnectionAdapters::Type::Value` => `ActiveRecord::Type::Value`