aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/attribute_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #29788 from kamipo/remove_unused_mutex_mRafael França2017-07-171-7/+4
|\ | | | | Remove unused `Mutex_m` in Active Model
| * Make `generated_attribute_methods` to privateRyuta Kamizono2017-07-141-4/+4
| | | | | | | | Because `generated_attribute_methods` is an internal API.
| * Remove unused `Mutex_m` in Active ModelRyuta Kamizono2017-07-141-4/+1
| |
* | Use frozen string literal in activemodel/Kir Shatrov2017-07-161-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-3/+2
| | | | | | | | | | | | * 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
* Move around AR::Dirty and fix _attribute methodAaron Patterson2017-04-141-0/+4
| | | | | | We already have a _read_attribute method that can get the value we need from the model. Lets define that method in AM::Dirty and use the existing one from AR::Dirty rather than introducing a new method.
* Fix `define_attribute_method` with Symbol in ARPrem Sichanugrist2017-02-211-1/+1
| | | | | | | | | | | | | | | | | | | This issue is only appear when you try to call `define_attribute_method` and passing a symbol in Active Record. It does not appear in isolation in Active Model itself. Before this patch, when you run `User.define_attribute_method :foo`, you will get: NoMethodError: undefined method `unpack' for :foo:Symbol from activerecord/lib/active_record/attribute_methods/read.rb:28:in `define_method_attribute' from activerecord/lib/active_record/attribute_methods/primary_key.rb:61:in `define_method_attribute' from activemodel/lib/active_model/attribute_methods.rb:292:in `block in define_attribute_method' from activemodel/lib/active_model/attribute_methods.rb:285:in `each' from activemodel/lib/active_model/attribute_methods.rb:285:in `define_attribute_method' This patch contains both a fix in Active Model and a test in Active Record for this error.
* Privatize unneededly protected methods in Active ModelAkira Matsuda2016-12-241-6/+4
|
* No need to :nodoc: private methodsAkira Matsuda2016-12-241-3/+3
|
* let Regexp#match? be globally availableXavier Noria2016-10-271-1/+0
| | | | | | Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation.
* applies new string literal convention in activemodel/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.
* systematic revision of =~ usage in AMoXavier Noria2016-07-241-2/+3
|
* Require only necessary concurrent-ruby classes.Jerry D'Antonio2015-11-041-1/+1
|
* Replaced `ThreadSafe::Map` with successor `Concurrent::Map`.Jerry D'Antonio2015-09-191-2/+2
| | | | | | | The thread_safe gem is being deprecated and all its code has been merged into the concurrent-ruby gem. The new class, Concurrent::Map, is exactly the same as its predecessor except for fixes to two bugs discovered during the merge.
* Rename match_attribute_method? to matched_attribute_methodMarcin Olichwirowicz2015-08-121-4/+4
| | | | | `match_attribute_method?` is a bit confusing because it suggest that a return value is a boolean which is not true.
* Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* formatting changesunknown2015-05-291-2/+2
|
* Fix grammar/style: assigns/declares -> assignments/declarations.Tim Wade2015-04-241-3/+3
| | | | [ci skip]
* Fix grammar/style: use (v) fall back (on).Tim Wade2015-04-241-1/+1
| | | | [ci skip]
* Fix grammar/style: break up long sentence.Tim Wade2015-04-241-2/+2
| | | | | | | A conjunction was needed to make these sentences correct. Breaking them up seemed like a better option. [ci skip]
* Fix grammar/style: pluralize 'each of its method'Tim Wade2015-04-241-1/+1
| | | | [ci skip]
* Correctly handle multiple attribute method prefix/suffixes which matchSean Griffin2014-12-041-6/+4
| | | | | | | | | Active Record defines `attribute_method_suffix :?`. That suffix will match any predicate method when the lookup occurs in Active Model. This will make it incorrectly decide that `id_changed?` should not exist, because it attempts to determine if the attribute `id_changed` is present, rather than `id` with the `_changed?` suffix. Instead, we will look for any correct match.
* Fix typo in AMo docs [ci skip]Carlos Antonio da Silva2014-01-061-1/+1
|
* Added Backslashes to ActiveModel::AttributeMethods to prevent unwanted links ↵aditya-kapoor2013-12-251-16/+11
| | | | in the rdoc + some other doc fixes.[ci skip]
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-12-201-1/+1
|\
| * fixed a typoaditya-kapoor2013-08-201-1/+1
| |
* | Typo and grammatical fixes [ci skip]Akshay Vishnoi2013-12-021-1/+1
|/
* eagerly initialize the attributes module to avoid check-then-set race conditionsAaron Patterson2013-07-021-1/+4
|
* remove wrong documentation from a :nodoc:'d methodAaron Patterson2013-07-021-1/+0
|
* the data structure used to store attribute aliases should not be exposedAaron Patterson2013-07-011-0/+10
|
* Remove deprecation warning from AttributeMethodsMatcherPaul Nikitochkin2013-06-281-8/+0
|
* Convert ActiveModel to 1.9 hash syntax.Patrick Robertson2013-05-011-1/+1
| | | | | I also attempted to fix other styleguide violations such as { a: :b } over {a: :b} and foo(b: 'bar') over foo( b: 'bar' ).
* pass over the code commentsXavier Noria2013-04-281-28/+32
| | | | | | * Highlights the requirement of an attributes method. * Removes some details that depend on the implementation of the class including the module. * Applies guidelines here and there.
* prefer american spelling of 'behavior'Gosha Arinich2013-01-071-1/+1
|
* Replace some global Hash usages with the new thread safe cache.thedarkone2012-12-141-4/+5
| | | | | | | | | | | | | | | | Summary of the changes: * Add thread_safe gem. * Use thread safe cache for digestor caching. * Replace manual synchronization with ThreadSafe::Cache in Relation::Delegation. * Replace @attribute_method_matchers_cache Hash with ThreadSafe::Cache. * Use TS::Cache to avoid the synchronisation overhead on listener retrieval. * Replace synchronisation with TS::Cache usage. * Use a preallocated array for performance/memory reasons. * Update the controllers cache to the new AS::Dependencies::ClassCache API. The original @controllers cache no longer makes much sense after @tenderlove's changes in 7b6bfe84f3 and f345e2380c. * Use TS::Cache in the connection pool to avoid locking overhead. * Use TS::Cache in ConnectionHandler.
* cleanup, remove broken whitespaceYves Senn2012-11-251-2/+2
|
* Make caller attribute in deprecation methods optionalAlexey Gaziev2012-10-301-1/+1
|
* Provide a call stack for deprecation warnings where needed.Nikita Afanasenko2012-10-291-6/+5
| | | | It's sometimes hard to quickly find where deprecated call was performed, especially in case of migrating between Rails versions. So this is an attempt to improve the call stack part of the warning message by providing caller explicitly.
* minor edits in AM documentation [ci skip]Francesco Rodriguez2012-10-211-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-08-041-0/+8
|\ | | | | | | | | | | Conflicts: activemodel/lib/active_model/secure_password.rb activerecord/lib/active_record/associations/collection_proxy.rb
| * add example to ActiveModel::MissingAttributeError [ci skip]Francesco Rodriguez2012-07-281-0/+8
| |
* | load active_support/deprecation in active_support/railsXavier Noria2012-08-021-1/+0
| |
* | load active_support/core_ext/class/attribute in active_support/railsXavier Noria2012-08-021-1/+0
|/
* Refactor attribute method matcher to use Hash#fetchCarlos Antonio da Silva2012-06-261-5/+3
|
* Cleanup attribute methods a bit, use map! when accepting *argsCarlos Antonio da Silva2012-06-261-17/+12
| | | | | | | | | Since we're dealing with a new array instance, it's safe to use map! and we avoid an extra array object. Also remove the symbolize_keys! from AttributeMethodMatcher, since it's an internal class that always receives symbol keys from the prefix/suffix methods implementations.
* add :nodoc: to internal implementations [ci skip]Francesco Rodriguez2012-06-221-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-06-221-35/+92
|\
| * fixes a few mistakes in api docs [ci skip]Vijay Dev2012-06-221-1/+1
| |