aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/attribute_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
| |
| * add description to ActiveModel::MissingAttributeError [ci skip]Francesco Rodriguez2012-06-211-1/+2
| |
| * add example to ActiveModel::AttributeMethods#undefine_attribute_methods [ci ↵Francesco Rodriguez2012-06-211-0/+26
| | | | | | | | skip]
| * add docs to AM::AttributeMethods#define_attribute_method [ci skip]Francesco Rodriguez2012-06-211-0/+25
| |
| * fix ActiveModel::AttributeMethods#alias_attribute documentation [ci skip]Francesco Rodriguez2012-06-211-7/+20
| |
| * update ActiveModel::AttributeMethods documentation [ci skip]Francesco Rodriguez2012-06-211-27/+20
| |
| * add example to ActiveModel::Validations#validators [ci skip]Francesco Rodriguez2012-06-151-1/+0
| |
* | Merge pull request #6800 from mschneider/dynamic_finders_for_aliased_attributesRafael Mendonça França2012-06-221-1/+3
|\ \ | | | | | | Dynamic finders for aliased attributes
| * | made dynamic finders alias_attribute awareMaximilian Schneider2012-06-221-1/+3
| | | | | | | | | | | | | | | previously dynamic finders only worked in combination with the actual column name and not its alias defined with #alias_attribute
* | | add :nodoc: to AM::AttributeMethods#instance_method_already_implemented? [ci ↵Francesco Rodriguez2012-06-211-1/+1
| | | | | | | | | | | | skip]
* | | add :nodoc: to AM::AttributeMethods::AttributeMethodMatcher [ci skip]Francesco Rodriguez2012-06-211-1/+1
|/ /
* / Simplify AR configuration code.Jon Leighton2012-06-151-2/+1
|/ | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* Merge pull request #4785 from ↵José Valim2012-05-251-4/+4
|\ | | | | | | | | ayamomiji/add-self-to-allow-method-name-using-ruby-keyword add `self.` to allow method name using ruby keyword
| * fix `alias_attribute` will raise a syntax error if make an alias on aayaya2012-05-141-4/+4
| | | | | | | | column that named as a ruby keyword
* | Revert "Merge pull request #5702 from oscardelben/patch-4"Piotr Sarnacki2012-05-201-1/+3
| | | | | | | | | | | | | | This reverts commit cae1ca7d1be9c79c7ef012a1f62aef9d3bb815f8, reversing changes made to da97cf016a8ffd1f54f804cd881f393e5d6efc18. These changes break the build, it needs more investigation.