aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type
Commit message (Collapse)AuthorAgeFilesLines
* edit pass over all warningsXavier Noria2014-10-281-3/+7
| | | | | | | | | | | | | | | This patch uniformizes warning messages. I used the most common style already present in the code base: * Capitalize the first word. * End the message with a full stop. * "Rails 5" instead of "Rails 5.0". * Backticks for method names and inline code. Also, converted a few long strings into the new heredoc convention.
* Fix typo in error message when non-boolean value is assigned to boolean columnPrathamesh Sonpatki2014-10-261-1/+1
|
* Add a deprecation warning for abiguous boolean valuesSean Griffin2014-10-161-1/+8
| | | | | | | | | | | In Rails 5.0, we'd like to change the behavior of boolean columns in Rails to be closer to Ruby's semantics. Currently we have a small set of values which are "truthy", and all others are "falsy". In Rails 5.0, we will reverse this to have a small number of values which are "falsy", and all others will become "truthy". In the interim, all values which are ambiguous must emit a deprecation warning.
* Allow YAML serialization when using TZ aware attributesSean Griffin2014-09-172-3/+17
|
* Correctly detect mutation on serialized columns mapping to binarySean Griffin2014-08-272-0/+15
| | | | Fixes #16701
* 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
|
* Merge pull request #16333 from ↵Yves Senn2014-08-041-4/+17
|\ | | | | | | | | | | | | | | | | joker1007/fix_decimal_cast_from_float_with_large_precision Fix type casting to Decimal from Float with large precision Conflicts: activerecord/CHANGELOG.md
| * Fix type casting to Decimal from Float with ...joker10072014-08-011-4/+17
| | | | | | | | | | When I defines large precision column at RDBMS, I assigns float value, raise ArgumentError (precision too large).
* | Rename method for clarityCarlos Antonio da Silva2014-07-311-3/+3
|/ | | | Ruby generally does not use the is_* prefix on predicate methods.
* Prefer if/else for this caseRafael Mendonça França2014-07-171-3/+2
| | | | | One of the branches is using a proc to check if the value respond_to a method so it is better to not do case comparations
* Fix decimal_test module and add new test for object responding to to_dMariano Valles2014-07-161-1/+0
|
* Fix case statement to use ::Numeric and ::StringMariano Valles2014-07-161-1/+1
|
* Change class evaluation for Rationals in cast_valueMariano Valles2014-07-161-4/+6
|
* Fix rational to decimal on type_cast_from_userMariano Valles2014-07-161-1/+3
|
* Remove the `text?` predicate from the type objectsSean Griffin2014-07-062-8/+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.
* active_record: Type cast booleans and durations for string columns.Dylan Thacker-Smith2014-07-062-2/+4
|
* Remove unneccessary special case for money in quotingSean Griffin2014-07-031-4/+4
|
* 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`