aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/value.rb
Commit message (Collapse)AuthorAgeFilesLines
* Some documentation edits [ci skip]Robin Dupret2015-03-051-3/+3
| | | | | | * Fix a few typos * Wrap some lines around 80 chars * Rephrase some statements
* Rm `Type#type_cast`Sean Griffin2015-02-171-14/+6
| | | | | | | | | This helper no longer makes sense as a separate method. Instead I'll just have `deserialize` call `cast` by default. This led to a random infinite loop in the `JSON` pg type, when it called `super` from `deserialize`. Not really a great way to fix that other than not calling super, or continuing to have the separate method, which makes the public API differ from what we say it is.
* `type_cast_from_user` -> `cast`Sean Griffin2015-02-171-2/+2
|
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-2/+2
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-4/+4
|
* rm `Type#number?`Sean Griffin2015-02-071-4/+0
| | | | | This predicate is only used in `query_attribute`, and is relatively easy to remove without adding a bunch of is a checks.
* rm `Type#text?`Sean Griffin2015-02-071-4/+0
| | | | | | | | | | | | | | | | This predicate was only to figure out if it's safe to do case insensitive comparison, which is only a problem on PG. Turns out, PG can just tell us whether we are able to do it or not. If the query turns out to be a problem, let's just replace that method with checking the SQL type for `text` or `character`. I'd rather not burden the type objects with adapter specific knowledge. The *real* solution, is to deprecate this behavior entirely. The only reason we need it is because the `:case_sensitive` option for `validates_uniqueness_of` is documented as "this option is ignored for non-strings". It makes no sense for us to do that. If the type can't be compared in a case insensitive way, the user shouldn't tell us to do case insensitive comparison.
* Push multi-parameter assignement into the typesSean Griffin2015-02-071-3/+0
| | | | | | | | | | | | This allows us to remove `Type::Value#klass`, as it was only used for multi-parameter assignment to reach into the types internals. The relevant type objects now accept a hash in addition to their previous accepted arguments to `type_cast_from_user`. This required minor modifications to the tests, since previously they were relying on the fact that mulit-parameter assignement was reaching into the internals of time zone aware attributes. In reaility, changing those properties at runtime wouldn't change the accessor methods for all other forms of assignment.
* Grammar and RDoc formattingSean Griffin2015-02-061-14/+14
|
* Docs pass for the attributes APISean Griffin2015-02-061-23/+42
|
* Remove incorrect comment in ActiveRecord::Type::ValueHenrik Nyh2015-01-151-2/+1
| | | | | | | Says it's only used for the schema, but they are in fact used for other things. Integer verifies against the limit during casting, and Decimal uses precision during casting. It may be true that scale is only used for the schema.
* Correctly ignore `case_sensitive` for UUID uniqueness validationSean Griffin2014-12-261-0/+4
| | | | | | | | I think we should deprecate this behavior and just error if you tell us to do a case insensitive comparison for types which are not case sensitive. Partially reverts 35592307 Fixes #18195
* docs, replace ` with + for proper rdoc output. [ci skip]Yves Senn2014-12-231-2/+2
|
* Implement `==` on `Type::Value` and `Attribute`Sean Griffin2014-08-151-0/+7
| | | | | This was a small self contained piece of the refactoring that I am working on, which required these objects to be comparable.
* [ci skip] fix spelling of overrideAkshay Vishnoi2014-08-131-2/+2
|
* Remove the `text?` predicate from the type objectsSean Griffin2014-07-061-4/+0
| | | | | | | This was only used for uniqueness validations. The first usage was in conjunction with `limit`. Types which cast to string, but are not considered text cannot have a limit. The second case was only with an explicit `:case_sensitive => true` option given by the user.
* Doc pass for `Type::Value` [ci skip]Sean Griffin2014-06-241-22/+42
|
* Small typoAnton Cherepanov2014-06-231-1/+1
|
* Remove `serialized?` from the type interfaceSean Griffin2014-06-131-4/+0
|
* Detect in-place changes on mutable AR attributesSean Griffin2014-06-131-0/+4
| | | | | | 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.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-5/+8
| | | | | | | | 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-091-5/+5
| | | | | | | | | | | | | - 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-071-2/+2
| | | | | | | | | | | | | 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-061-1/+0
| | | | Only `Date` and `Time` are handled.
* Refactor determination of whether the field has changedSean Griffin2014-06-031-0/+9
| | | | | 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-011-1/+0
| | | | | | | | | | | 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-301-0/+4
| | | | | | | 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-291-5/+6
|
* Refactor serialized types to be partially defined as custom propertiesSean Griffin2014-05-291-0/+4
| | | | | | | 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-271-0/+59
`ActiveRecord::ConnectionAdapters::Type::Value` => `ActiveRecord::Type::Value`