aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
Commit message (Collapse)AuthorAgeFilesLines
* Don't raise on out-of-range datetimes passed by a userGrey Baker2014-12-231-1/+5
|
* Allow custom handling of non-standard types in `time_zone_conversion`Sean Griffin2014-12-081-1/+1
| | | | | | | | | | | | PostgreSQL for example, allows infinity as a valid value for date time columns. The PG type has explicit handling for that case. However, time zone conversion will end up trampling that handling. Unfortunately, we can't call super and then convert time zones. However, if we get back nil from `.in_time_zone`, it's something we didn't expect so we can let the superclass handle it. Fixes #17971
* Use `DelegateClass` instead of `SimpleDelegator` for type decoratorsSean Griffin2014-11-141-1/+1
| | | | There is a significant performance difference between the two. Closes
* Allow YAML serialization when using TZ aware attributesSean Griffin2014-09-171-0/+2
|
* Stop using instance exec for type decoratorsSean Griffin & Sean Doyle2014-06-271-5/+15
| | | | | | | | We are moving this behavior out to an object that we would like to keep separated from `ActiveRecord::Base`, which means not passing the class object to it. As such, we need to stop using `instance_exec`, and instead close over the subclass on global type decorators that are applied in `Base`.
* Silence warning in testSean Griffin2014-06-241-2/+2
| | | | | We still had one file using `column_for_attribute` when it could return nil, causing deprecation warnings in the tests.
* Promote time zone aware attributes to a first class type decoratorSean Griffin2014-06-161-1/+6
| | | | | | | | | | | | | This refactoring revealed the need for another form of decoration, which takes a proc to select which it applies to (There's a *lot* of cases where this form can be used). To avoid duplication, we can re-implement the old decoration in terms of the proc-based decoration. The reason we're `instance_exec`ing the matcher is for cases such as time zone aware attributes, where a decorator is defined in a parent class, and a method called in the matcher is overridden by a child class. The matcher will close over the parent, and evaluate in its context, which is not the behavior we want.
* Rename `type_cast` to `type_cast_from_database`Sean Griffin2014-06-091-1/+1
| | | | | | | | 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-40/+11
| | | | | | | | | | | | | - 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
* Ensure time zones don't change after round trip with array columnsSean Griffin2014-06-071-1/+11
| | | | | The times would be equivalent, even if they were in different time zones. E.g. 12:00 UTC == 5:00 PDT
* changelog for #15556 and credit @kuldeepaggarwal [Kuldeep Aggarwal]Yves Senn2014-06-071-2/+0
| | | | | | This is a follow up to #15556 @kuldeepaggarwal did submit this patch way back (#13624).
* Add array support when time zone aware attributes are enabledSean Griffin2014-06-071-1/+13
|
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-1/+1
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* Add an interface for type objects to control Ruby => SQLSean Griffin2014-05-261-4/+2
| | | | | Adds the ability to save custom types, which type cast to non-primitive ruby objects.
* Remove :timestamp column typeSean Griffin2014-05-191-2/+2
| | | | | | | | | | | | The `:timestamp` type for columns is unused. All database adapters treat them as the same database type. All code in `ActiveRecord` which changes its behavior based on the column's type acts the same in both cases. However, when the type is passed to code that checks for the `:datetime` type, but not `:timestamp` (such as XML serialization), the result is unexpected behavior. Existing schema definitions will continue to work, and the `timestamp` type is transparently aliased to `datetime`.
* Perf: avoid array allocation where not neededSam2013-08-271-1/+1
|
* Simplify type casting code for timezone aware attributesAndrew White2013-01-261-10/+5
| | | | | | With the addition of String#in_time_zone and Date#in_time_zone we can simplify the type casting code by checking if the value has an `in_time_zone` method.
* Fix handling of dirty time zone aware attributesLilibeth De La Cruz2013-01-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously, when `time_zone_aware_attributes` were enabled, after changing a datetime or timestamp attribute and then changing it back to the original value, `changed_attributes` still tracked the attribute as changed. This caused `[attribute]_changed?` and `changed?` methods to return true incorrectly. Example: in_time_zone 'Paris' do order = Order.new original_time = Time.local(2012, 10, 10) order.shipped_at = original_time order.save order.changed? # => false # changing value order.shipped_at = Time.local(2013, 1, 1) order.changed? # => true # reverting to original value order.shipped_at = original_time order.changed? # => false, used to return true end
* Revert "Round usec when writing timestamp attribute."Andrew White2013-01-221-13/+5
| | | | | | | | | | This reverts commit e9d2ad395ec2ef929d74752f3d71c80674044fbe. Closes #8460 Conflicts: activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb activerecord/test/cases/dirty_test.rb
* Don't call will_change! for datetime nil->"".Alisdair McDiarmid2012-11-251-0/+1
| | | | | | | Setting a nil datetime attribute to a blank string should not cause the attribute to be dirty. Fix #8310
* Remove return guardCarlos Antonio da Silva2012-11-171-2/+1
|
* Remove ActiveRecord::ModelJon Leighton2012-10-261-11/+5
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."Jeremy Kemper2012-10-201-1/+1
| | | | This reverts commit 83846838252397b3781eed165ca301e05db39293.
* Get rid of the ActiveRecord::Model::DeprecationProxy thing.Jon Leighton2012-10-191-1/+1
| | | | | | | | | | | | | | | | | I think it's going to be too much pain to try to transition the :active_record load hook from executing against Base to executing against Model. For example, after Model is included in Base, and modules included in Model will no longer get added to the ancestors of Base. So plugins which wish to be compatible with both Model and Base should use the :active_record_model load hook which executes *before* Base gets loaded. In general, ActiveRecord::Model is an advanced feature at the moment and probably most people will continue to inherit from ActiveRecord::Base for the time being.
* Revert "Key the attributes hash with symbols"Jon Leighton2012-10-121-1/+1
| | | | | | | | | | | | This reverts commit 86c3dfbd47cb96af02daaa655963292b1a1b110e. Conflicts: activerecord/lib/active_record/attribute_methods/read.rb Reason: whilst this increased performance, it also presents a DoS risk via memory exhaustion if users were allowing user input to dictate the arguments of read/write_attribute. I will investigate alternative ways to cut down on string allocations here.
* Removing dead code. attribute_cast_code is not called.kennyj2012-09-281-15/+0
|
* Key the attributes hash with symbolsJon Leighton2012-08-311-1/+1
| | | | | | | | This is a performance/GC optimisation. In theory, this could be optimised by the implementation (last time I checked, this would have no effect on JRuby). But in practise, this make attribute access faster.
* Round usec when writing timestamp attribute.kennyj2012-08-211-5/+14
|
* load active_support/core_ext/class/attribute in active_support/railsXavier Noria2012-08-021-1/+0
|
* load active_support/core_ext/object/inclusion in active_support/railsXavier Noria2012-08-021-1/+0
|
* Simplify AR configuration code.Jon Leighton2012-06-151-4/+9
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* Fix #6591. If a field with timezone isn't changed, we don't call will_change!.kennyj2012-06-041-1/+2
|
* force datetime attributes to be changed, fix GH #3965Sergey Nartimov2012-02-281-0/+1
|
* removing dead codeAaron Patterson2012-02-091-10/+0
|
* give each PG type a `type` method and decortate tz attributesAaron Patterson2012-02-071-1/+18
|
* moved most of the evald code in to regular ruby codeAaron Patterson2012-02-071-5/+2
|
* copy the columns hash to the active record instances, typecast using columns ↵Aaron Patterson2012-02-071-33/+46
| | | | looked up on the instance
* Support configuration on ActiveRecord::Model.Jon Leighton2011-12-281-3/+4
| | | | | | | | | | | | | | | The problem: We need to be able to specify configuration in a way that can be inherited to models that include ActiveRecord::Model. So it is no longer sufficient to put 'top level' config on ActiveRecord::Base, but we do want configuration specified on ActiveRecord::Base and descendants to continue to work. So we need something like class_attribute that can be defined on a module but that is inherited when ActiveRecord::Model is included. The solution: added ActiveModel::Configuration module which provides a config_attribute macro. It's a bit specific hence I am not putting this in Active Support or making it a 'public API' at present.
* Deal with global config better between AR::Base and AR::ModelJon Leighton2011-12-241-3/+2
|
* Fix #3837.Jon Leighton2011-12-031-11/+5
| | | | | We also need to time zone convert time zone aware attributes when accessed via read_attribute, not only when via direct access.
* Remove some unnecessary code etcJon Leighton2011-12-011-19/+3
|
* Remove the need for type_cast_attribute.Jon Leighton2011-12-011-3/+16
| | | | This is good because it reduces duplication.
* Don't rely on underscore-prefixed attribute methods.Jon Leighton2011-12-011-11/+15
| | | | | | Define singleton methods on the attributes module instead. This reduces method pollution on the actual model classes. It also seems to make something faster, I am unsure why! O_o
* Remove `#among?` from Active SupportPrem Sichanugrist2011-04-131-1/+1
| | | | | | After a long list of discussion about the performance problem from using varargs and the reason that we can't find a great pair for it, it would be best to remove support for it for now. It will come back if we can find a good pair for it. For now, Bon Voyage, `#among?`.
* Change Object#either? to Object#among? -- thanks to @jamesarosen for the ↵David Heinemeier Hansson2011-04-121-1/+1
| | | | suggestion!
* Using Object#in? and Object#either? in various placesPrem Sichanugrist2011-04-111-1/+2
| | | | There're a lot of places in Rails source code which make a lot of sense to switching to Object#in? or Object#either? instead of using [].include?.
* Fix before_type_cast for timezone aware attributes by caching converted ↵Adam Meehan2011-03-231-4/+5
| | | | value on write. Also remove read method reload arg on timezone attributes.
* avoid nil.dupAkira Matsuda2011-02-071-1/+1
| | | | Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Make before_type_cast available for datetime fieldsAkira Matsuda2011-02-011-2/+3
| | | | | | [#3973 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* class inheritable attributes is used no more! all internal use of class ↵Josh Kalderimis2010-11-201-2/+4
| | | | | | inheritable has been changed to class_attribute. class inheritable attributes has been deprecated. Signed-off-by: José Valim <jose.valim@gmail.com>