aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | Fix uninitialized ivar warning in testsSean Griffin2014-10-281-1/+1
|/
* Changed the DangerousAttributeError exception message to include messaging ↵Jim Jones2014-09-101-1/+1
| | | | that the conflict could be because of a conflicting attribute.
* Allow included modules to override association methods.Yves Senn2014-09-091-0/+2
| | | | | | | | | | Closes #16684. This is achieved by always generating `GeneratedAssociationMethods` when `ActiveRecord::Base` is subclassed. When some of the included modules of `ActiveRecord::Base` were reordered this behavior was broken as `Core#initialize_generated_modules` was no longer called. Meaning that the module was generated on first access.
* Enums shouldn't ruin people's anniversariesGodfrey Chan2014-09-041-1/+1
| | | | | | | | Added a few more methods on Module/Class to the dangerous class methods blacklist. (Technically, allocate and new are already protected currently because we happen to redefine them in the current implantation.) Closes #16792
* Avoid using heredoc for user warningsGodfrey Chan2014-08-281-5/+3
| | | | | | | | | | Using heredoc would enforce line wrapping to whatever column width we decided to use in the code, making it difficult for the users to read on some consoles. This does make the source code read slightly worse and a bit more error-prone, but this seems like a fair price to pay since the primary purpose for these messages are for the users to read and the code will not stick around for too long.
* Merge pull request #16458 from chancancode/ar_fix_reserved_inheritanceGodfrey Chan2014-08-171-5/+8
|\ | | | | | | | | | | | | Fixed issue w/custom accessors + reserved name + inheritance Conflicts: activerecord/CHANGELOG.md
| * Fixed issue w/custom accessors + reserved name + inheritanceGodfrey Chan2014-08-111-5/+8
| | | | | | | | | | | | | | | | | | | | Fixed an issue where custom accessor methods (such as those generated by `enum`) with the same name as a global method are incorrectly overridden when subclassing. This was partially fixed in 4155431 then broken again by e5f15a8. Fixes #16288.
* | Spelling errorsjbsmith862014-08-141-2/+2
|/
* Remove references to SQLite3Column from documentationa3gis2014-07-251-1/+1
|
* Merge pull request #16138 from sgrif/sg-attribute-set-keyYves Senn2014-07-161-2/+2
|\ | | | | AttributeSet#include? -> AttributeSet#key?
| * AttributeSet#include? -> AttributeSet#key?Sean Griffin2014-07-111-2/+2
| | | | | | | | https://github.com/rails/rails/pull/15868/files#r14135210
* | Fixing typo in commentGregory Igelmund2014-07-121-1/+1
|/
* Don't add a second method for attribute existenceSean Griffin2014-06-301-6/+1
| | | | | We already had one in the public API that people can use more easily for the transition
* Don't encourage usage of `columns_hash`Sean Griffin2014-06-291-2/+7
| | | | | | | | | As discussed in https://github.com/plataformatec/simple_form/pull/1094, we should not encourage usage of `columns_hash`, and instead provide an alternate method to determine whether or not an attribute exists. The language `attribute` was chosen over `column` since these are in the `AttributeMethods` module.
* Add a deprecation cycle for `NullColumn` from `column_for_attribute`Sean Griffin2014-06-231-6/+10
| | | | | | This is public API, and `simple_form` depends on the `nil` return value. We need to go through a deprecation cycle to return a null object. If people want hash access, they can access the hash.
* Move `attributes` to the `AttributeSet` object.Sean Griffin2014-06-211-3/+1
|
* Introduce an object to aid in creation and management of `@attributes`Sean Griffin2014-06-191-8/+2
| | | | | Mostly delegation to start, but we can start moving a lot of behavior in bulk to this object.
* Remove unused `method_missing` definitionSean Griffin2014-06-131-34/+1
| | | | We always define attribute methods in the constructor or in `init_with`.
* Introduce an Attribute object to handle the type casting danceSean Griffin2014-06-131-12/+8
| | | | | | | | | | | | | | | There's a lot more that can be moved to these, but this felt like a good place to introduce the object. Plans are: - Remove all knowledge of type casting from the columns, beyond a reference to the cast_type - Move type_cast_for_database to these objects - Potentially make them mutable, introduce a state machine, and have dirty checking handled here as well - Move `attribute`, `decorate_attribute`, and anything else that modifies types to mess with this object, not the columns hash - Introduce a collection object to manage these, reduce allocations, and not require serializing the types
* have an actual `NullColumn` object and update docs accordingly.Yves Senn2014-06-041-4/+5
| | | | | | Follow up to #15438 and #15502. /cc @sgrif
* Use null column for association key typesSean Griffin2014-06-041-19/+21
|
* Return a null column when no column exists for an attributeSean Griffin2014-06-031-7/+9
|
* Remove most code related to serialized propertiesSean Griffin2014-06-011-5/+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
* Don't change values in `@raw_attributes` during serializationSean Griffin2014-06-011-1/+1
| | | | | | During `init_with`, the attributes given to the coder will be placed into `@raw_attributes`. As such, we should read from `@raw_attributes` when encoding, rather than `@attributes`, which has been type cast.
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-5/+5
| | | | | | | | | `@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.
* Merge pull request #15261 from hbin/missing_parametersRafael Mendonça França2014-05-231-1/+5
|\ | | | | Bring the missing parameters back.
| * Bring the missing parameters back.Bin Huang2014-05-231-1/+5
| |
* | Merge pull request #15282 from sgrif/sg-remove-column-primaryRafael Mendonça França2014-05-231-1/+1
|\ \ | | | | | | Remove `Column#primary`
| * | Remove `Column#primary`Sean Griffin2014-05-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | It appears to have been used at some point in the past, but is no longer used in any meaningful way. Whether a column is considered primary is a property of the model, not the schema/column. This also removes the need for yet another layer of caching of the model's schema, and we can leave that to the schema cache.
* | | Avoid slowing down AR object initializationGodfrey Chan2014-05-221-0/+1
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2d73f5a forces AR to enter the `define_attribute_methods` method whenever it instantiate a record from the `init_with` entry point. This is a potential performance hotspot, because `init_with` is called from all `find*` family methods, and `define_attribute_methods` is slow because it tries to acquire a lock on the mutex everytime it is entered. By using [DCL](http://en.wikipedia.org/wiki/Double-checked_locking), we can avoid grabbing the lock most of the time when the attribute methods are already defined (the common case). This is made possible by the fact that reading an instance variable is an atomic operation in Ruby. Credit goes to Aaron Patterson for pointing me to DCL and filling me in on the atomicity guarantees in Ruby. [*Godfrey Chan*, *Aaron Patterson*]
* | fix test from 7537057888d2d63c3b6c2019d5828bc445fbd6c9Aaron Patterson2014-05-221-0/+1
|/
* [ci skip]add updated information, ref[#522c0fd]Kuldeep Aggarwal2014-05-141-0/+2
|
* Update attribute_methods.rbGuillermo Iguaran2014-05-111-1/+1
| | | Improve documentation
* correcting method documentation [ci skip]Chris Beer2014-05-111-7/+7
|
* Block a few default Class methods as scope name.Arthur Neves2014-04-031-1/+3
| | | | | | Add tests to make sure scopes cannot be create with names such as: private, protected, public. Make sure enum values don't collide with those methods too.
* Fixes STI when 2+ levels deep.Arthur Neves2014-03-101-3/+3
| | | | | | PR #14052 Added a regression where it was only looking for methods in one level up, So when the method was defined in a 2+ levels up the inheritance chain, the method was not found as defined.
* Fixed STI classes not defining an attribute method if there is aGodfrey Chan2014-02-231-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | conflicting private method defined on its ancestors. The problem is that `method_defined_within?(name, klass, superklass)` only works correclty when `klass` and `superklass` are both `Class`es. If both `klass` and `superklass` are both `Class`es, they share the same inheritance chain, so if a method is defined on `klass` but not `superklass`, this method must be introduced at some point between `klass` and `superklass`. This does not work when `superklass` is a `Module`. A `Module`'s inheritance chain contains just itself. So if a method is defined on `klass` but not on `superklass`, the method could still be defined somewhere upstream, e.g. in `Object`. This fix works by avoiding calling `method_defined_within?` with a module while still fufilling the requirement (checking that the method is defined withing `superclass` but not is not a generated attribute method). 4d8ee288 is likely an attempted partial fix for this problem. This unrolls that fix and properly check the `superclass` as intended. Fixes #11569.
* Fixing issue with activerecord serialization not being able to dump a record ↵Mauricio Linhares2014-01-291-0/+5
| | | | after loading it from YAML - fixes #13861
* `scope` now raises on "dangerous" name conflictsGodfrey Chan2014-01-291-4/+22
| | | | | | | | | | Similar to dangerous attribute methods, a scope name conflict is dangerous if it conflicts with an existing class method defined within `ActiveRecord::Base` but not its ancestors. See also #13389. *Godfrey Chan*, *Philippe Creux*
* fix typos and grammar mistake [ci skip]nishant-cyro2013-12-191-1/+1
|
* Merge pull request #12403 from thedarkone/attr-method-missing-fixRafael Mendonça França2013-12-041-1/+18
|\ | | | | | | | | | | | | Fix AR#method_missing re-dispatching into overwritten attribute methods Conflicts: activerecord/lib/active_record/attribute_methods.rb
| * Fix AR#method_missing re-dispatching into overwritten attribute methods.thedarkone2013-09-291-1/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This was happening when a `super` call in an overwritten attribute method was triggering a method_missing fallback, because attribute methods haven't been generated yet. class Topic < ActiveRecord::Base def title # `super` would re-invoke this method if define_attribute_methods # hasn't been called yet resulting in double '!' appending super + '!' end end
* | short arrays in inspectJan Bernacki2013-10-301-3/+10
| |
* | always check to see if methods exist after calling define_attribute_methodsMatt Jones2013-10-241-6/+3
|/
* Use TS::Cache instead of Mutex + Hash.thedarkone2013-09-281-12/+8
| | | | TS::Cache#compute_if_absent guarantees that only a single thread will get to execute the provided block for a given key.
* Remove deprecation warning from attribute_missing Arun Agrawal2013-07-151-14/+0
| | | for attributes that are columns.
* Avoid creating an extra Range instanceAkira Matsuda2013-07-101-1/+1
|
* Fix: attribute_for_inspect truncate upto (51 => 50) characters.namusyaka2013-07-091-2/+2
|
* refactor the method cache objects to have a superclassAaron Patterson2013-07-031-0/+25
|
* move the reader method cache in to the read moduleAaron Patterson2013-07-031-48/+0
|