aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/enum.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add a warning for enum elements with 'not_' prefix.Edu Depetris2019-06-301-0/+9
| | | | | | | | | | When a enum element contains the prefix 'not_'. I warns to users to be aware of this new feature. Example code: class Foo < ActiveRecord::Base enum status: [:sent, :not_sent] end
* Add negative scopes for all enum values (#35381)David Heinemeier Hansson2019-02-261-0/+6
| | | Add negative scopes for all enum values
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-211-1/+1
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* option to disable scopes that `ActiveRecord.enum` generates by defaultAlfred Dominic2018-12-041-2/+5
|
* Raises error when attempting to modify enum valuesebyrds2018-11-231-0/+1
|
* Guard Enums against definitions with blank label namesChristophe Maximin2018-11-071-0/+4
|
* Privatize ENUM_CONFLICT_MESSAGE constantAlberto Almagro2018-10-101-0/+1
|
* Raise on invalid definition valuesAlberto Almagro2018-10-101-0/+10
| | | | | | | | | When defining a Hash enum it can be easy to use [] instead of {}. This commit checks that only valid definition values are provided, those can be a Hash, an array of Symbols or an array of Strings. Otherwise it raises an ArgumentError. Fixes #33961
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-171-4/+1
|
* Prevent scope named same as a ActiveRecord::Relation instance method.Chen Kinnrot2017-11-281-0/+2
| | | | | | | | | Due to inconsistent behavior when chaining scopes and one scope named after a Relation method Validation code added in 2 places: - scope, to prevent problematic scope names. - enum, cause it tries to auto define scope.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-2/+1
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Refactor enum to use `value` instead of `label` in the scopeRyuta Kamizono2017-05-071-11/+12
|
* Describe what we are protectingAkira Matsuda2016-12-231-0/+2
|
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-1/+1
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-4/+4
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix `enum` with `alias_attribute`Ryuta Kamizono2016-07-311-5/+6
| | | | Fixes #25892.
* return correct type from `EnumType`yuuji.yaginuma2016-06-241-0/+2
|
* This code won't workAkira Matsuda2016-03-061-1/+1
| | | | [ci skip]
* Merge branch '5-0-beta-sec'Aaron Patterson2016-01-251-1/+1
|\ | | | | | | | | | | | | | | | | | | | | * 5-0-beta-sec: bumping version fix version update task to deal with .beta1.1 Eliminate instance level writers for class accessors allow :file to be outside rails root, but anything else must be inside the rails view directory Don't short-circuit reject_if proc stop caching mime types globally use secure string comparisons for basic auth username / password
| * Eliminate instance level writers for class accessorsAaron Patterson2016-01-221-1/+1
| | | | | | | | | | | | | | | | | | Instance level writers can have an impact on how the Active Model / Record objects are saved. Specifically, they can be used to bypass validations. This is a problem if mass assignment protection is disabled and specific attributes are passed to the constructor. CVE-2016-0753
* | Use the database type to deserialize enumSean Griffin2016-01-231-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | This fixes incorrect assumptions made by e991c7b that we can assume the DB is already casting the value for us. The enum type needs additional information to perform casting, and needs a subtype. I've opted not to call `super` in `cast`, as we have a known set of types which we accept there, and the subtype likely doesn't accept them (symbol -> integer doesn't make sense) Close #23190
* | Ensure enum scopes work properly with STI and inheritanceSean Griffin2016-01-141-1/+1
| | | | | | | | | | | | | | | | | | The code was changed to call `where` on a specific class in 813c8c07, but no reasoning was given and I can't see any good reason why we would need to do that. This will ensure that the method is called on whatever class the scope is called on. Fixes #23013
* | value has the right type hereSantiago Pastorino2015-12-311-1/+1
|/ | | | | | | | | | using `enum kind: [ :any, :income, :expense ]` syntax, value is already an integer and using `enum kind: { any: 'any', income: 'income', expense: 'expense' }` syntax value is a string. This allows us to define the mapping in the enum definition. This reverts commit 933decceaf6092020ba7ba768b51b2db9d5b882f.
* docs, nodoc `EnumType`. [ci skip]Yves Senn2015-11-071-1/+1
| | | | | This type is backed by a class macro. Documentation related to the type casting behavior should be added in the macro description.
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-3/+3
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Clean up the implementation of AR::DirtySean Griffin2015-09-241-1/+7
| | | | | | | | | | | | | This moves a bit more of the logic required for dirty checking into the attribute objects. I had hoped to remove the `with_value_from_database` stuff, but unfortunately just calling `dup` on the attribute objects isn't enough, since the values might contain deeply nested data structures. I think this can be cleaned up further. This makes most dirty checking become lazy, and reduces the number of object allocations and amount of CPU time when assigning a value. This opens the door (but doesn't quite finish) to improving the performance of writes to a place comparable to 4.1
* DRY enum conflict detectionRonak Jangir2015-09-181-21/+13
|
* [ci skip] Fix #21364 error in documentation about ActiveRecord::EnumAndrew Grimm2015-08-251-2/+1
|
* Improvements on the enum documentation [ci skip]Robin Dupret2015-07-231-9/+11
| | | | | | | | | | | | | The note regarding the `_prefix` and `_suffix` options is no longer useful since they were renamed specifically for this purpose. Also the given example doesn't show what these options enable and in which case they are really useful (when there are conflicting values for instance). Refs #20999. [Godfrey Chan & Robin Dupret]
* Rename the enum_{prefix,suffix} options to _{prefix,suffix}Robin Dupret2015-07-231-10/+10
| | | | | | This makes it more clear that they are reserved keywords and also it seems less redundant as the line already starts with the call to the `enum` method.
* A few documentation edits [ci skip]Robin Dupret2015-06-151-2/+2
|
* [ci skip] fix typo mistakeKuldeep Aggarwal2015-06-141-1/+1
|
* Add enum prefix/suffix option to enum definitionIgor Kapkov2015-06-121-6/+36
| | | | Fixes #17511 and #17415
* Fix a minor grammatical issue in the docRomain Goyet2015-04-231-1/+1
|
* `type_cast_from_user` -> `cast`Sean Griffin2015-02-171-1/+1
|
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-1/+1
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-1/+1
|
* Mention `where.not` in the exampleGodfrey Chan2015-02-141-3/+3
| | | | | | | ...so it doesn't look like you *have* to use SQL strings for that case (not anymore!). Would like to replace the SQL string example with something that you cannot do with the "normal" query API, but I could not come up with a short, realistic example. Suggestions welcome!
* Fixed a bug where NULLs are casted into the first enum valueGodfrey Chan2015-02-131-0/+1
|
* Partially revert ae33aeaGodfrey Chan2015-02-131-1/+7
| | | | | Using enum names in SQL strings doesn't actually work, the test was wrong (fixed in 3dfd1ba).
* Enums mapping is a HWIA [ci skip]Godfrey Chan2015-02-131-2/+3
| | | | | The previous edit kind of de-emphasized that, so changing it to be more explict. (It also avoids showing it as if it's a string-keyed hash.)
* Enums should be referred to by symbolsGodfrey Chan2015-02-131-5/+6
| | | | | Also updated the documentation about the new ability to query them normally, and added test to make sure they work!
* Don't break enum on PGSean Griffin2015-02-111-1/+1
|
* Refactor enum to be defined in terms of the attributes APISean Griffin2015-02-111-43/+38
| | | | | | | | | | | In addition to cleaning up the implementation, this allows type casting behavior to be applied consistently everywhere. (#where for example). A good example of this was the previous need for handling value to key conversion in the setter, because the number had to be passed to `where` directly. This is no longer required, since we can just pass the string along to where. (It's left around for backwards compat) Fixes #18387
* Improve the performance of reading attributesSean Griffin2014-11-181-1/+1
| | | | | | | We added a comparison to "id", and call to `self.class.primary_key` a *lot*. We also have performance hits from `&block` all over the place. We skip the check in a new method, in order to avoid breaking the behavior of `read_attribute`
* Implement `_was` and `changes` for in-place mutations of AR attributesSean Griffin2014-08-161-2/+2
|