aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
Commit message (Collapse)AuthorAgeFilesLines
* Add days_in_year methodJon Pascoe2015-11-101-0/+6
|
* Merge pull request #21897 from swaathi/masterKasper Timm Hansen2015-11-071-2/+20
|\ | | | | Parameterize with options to preserve the case of string
| * Parameterize with options to preserve case of stringSwaathi K2015-11-071-2/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added test cases Using kwargs instead of three seperate functions Updated parameterize in transliterate.rb Updated parameterize in transliterate.rb Added deprecation warnings and updating RDoc+Guide Misspelled separtor. Fixed. Deprecated test cases and added support to parameterize with keyword parameters Squashing commits. Fixed test cases and added deprecated test cases Small changes to Gemfile.lock and CHANGELOG Update Gemfile.lock
* | Merge pull request #21806 from kachick/fix-transformer-sizeEileen M. Uchitelle2015-11-072-4/+4
|\ \ | |/ |/| Return a sized Enumerator from Hash#transform_values{!}
| * Return a sized Enumerator from Hash#{transform_values{!}|transform_keys{!}}Kenichi Kamiya2015-09-292-4/+4
| |
* | Merge pull request #16357 from gchan/hwia-respects-to-hash-defaultSean Griffin2015-10-291-1/+1
|\ \ | | | | | | | | | | | | `HashWithIndifferentAccess.new` respects the default value or proc on objects that respond to `#to_hash`
| * | `HashWithIndifferentAccess.new` respects the default value or proc on ↵Gordon Chan2014-07-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | objects that respond to `#to_hash`. Builds on the work of #12550 where `.new` will convert the object (that respond to `#to_hash`) to a hash and add that hash's keys and values to itself. This change will also make `.new` respect the default value or proc of objects that respond to `#to_hash`. In other words, this `.new` behaves exactly like `.new_from_hash_copying_default`. `.new_from_hash_copying_default` now simply invokes `.new` and any references to `.new_from_hash_copying_default` are replaced with `.new`. Added tests confirm behavior.
* | | Make `Module#redefine_method` to keep method visibilityyui-knk2015-10-261-0/+13
| | | | | | | | | | | | | | | | | | | | | Before this commit `Module#redefine_method` always changes visibility of redefined method to `public`. This commit changes behavior of Module#redefine_method` to keep method visibility.
* | | [ci skip] Add more code examples for `Module#anonymous?` docsyui-knk2015-10-231-2/+4
| | | | | | | | | | | | | | | In later code examples, it is better to write how `Module#anonymous?` works.
* | | Change Integer#year to return a Fixnum instead of a Float to improve consistencyKonstantinos Rousis2015-10-221-1/+1
| | |
* | | Add Module#remove_possible_singleton_methodAndrew White2015-10-212-1/+17
| | | | | | | | | | | | | | | This is primarily to fix method redefinition warnings in class_attribute but may be of use in other places where we define singleton methods.
* | | Merge pull request #19992 from greysteil/handle-invalid-utf8-in-html-escapeSean Griffin2015-10-201-2/+2
|\ \ \ | | | | | | | | | | | | Handle invalid UTF-8 strings when HTML escaping
| * | | Handle invalid UTF-8 strings when HTML escapingGrey Baker2015-06-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Use `ActiveSupport::Multibyte::Unicode.tidy_bytes` to handle invalid UTF-8 strings in `ERB::Util.unwrapped_html_escape` and `ERB::Util.html_escape_once`. Prevents user-entered input passed from a querystring into a form field from causing invalid byte sequence errors.
* | | | Merge pull request #20038 from imanel/numeric_prependSean Griffin2015-10-202-33/+19
|\ \ \ \ | | | | | | | | | | Use Module.prepend instead of alias_method and unify behavior of all Numeric extensions
| * | | | Unify behavior of all Numeric extensions and use Module.prepend instead of ↵Bernard Potocki2015-05-282-33/+19
| | | | | | | | | | | | | | | | | | | | alias_method
* | | | | Merge pull request #21302 from theunraveler/delegate_reserved_argument_namesSean Griffin2015-10-201-5/+6
|\ \ \ \ \ | | | | | | | | | | | | ActiveSupport: Fixing issue when delegating to methods named "block", "args", or "arg"
| * | | | | Fixing issue when delegating to methods named "block", "args", or "arg"Jake Bell2015-08-191-5/+6
| | | | | |
* | | | | | fixes #21815Maarten Jacobs2015-10-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default timestamp used for AR is `updated_at` in nanoseconds! (:nsec) This causes issues on any machine that runs an OS that supports nanoseconds timestamps, i.e. not-OS X, where the cache_key of the record persisted in the database (milliseconds precision) is out-of-sync with the cache_key in the ruby VM. This commit adds: A test that shows the issue, it can be found in the separate file `cache_key_test.rb`, because - model couldn't be defined inline - transactional testing needed to be turned off to get it to pass the MySQL tests This seemed cleaner than putting it in an existing testcase file. It adds :usec as a dateformat that calculates datetime in microseconds It sets precision of cache_key to :usec instead of :nsec, as no db supports nsec precision on timestamps
* | | | | | drop array allocations when iterating over the hashAaron Patterson2015-10-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `each_with_object` allocates an array for each kv pair. Switching to the slightly more verbose but less allocatey `each_pair` eliminates array allocations. Eliminating this allocation returns AR objects to have constant array allocations regardless of the number of columns the object has. Here is test code: ```ruby require 'active_record' class Topic < ActiveRecord::Base end 20.times do |i| Process.waitpid fork { ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' ActiveRecord::Base.connection.instance_eval do create_table(:topics) do |t| t.string :title, limit: 250 t.string :author_name t.string :author_email_address t.string :parent_title t.string :type t.string :group i.times do |j| t.string :"aaa#{j}" end t.timestamps null: true end end ObjectSpace::AllocationTracer.setup(%i{type}) Topic.create title: "aaron" # heat cache result = ObjectSpace::AllocationTracer.trace do 10.times do |i| Topic.create title: "aaron #{i}" end end puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_ARRAY }.last.first / 10)}" } end ``` Before this commit: ``` 9,166 10,167 11,168 12,169 13,170 14,171 15,172 16,173 17,174 18,175 19,176 20,177 21,178 22,179 23,180 24,181 25,182 26,183 27,184 28,185 ``` After: ``` 9,157 10,157 11,157 12,157 13,157 14,157 15,157 16,157 17,157 18,157 19,157 20,157 21,157 22,157 23,157 24,157 25,157 26,157 27,157 28,157 ``` Left side is the number of columns, right is the number of allocations
* | | | | | make string allocation constant regardless of column countAaron Patterson2015-10-151-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | deep_dup'ing a hash will dup the keys as well as the values. Since string keys from the source hash will be frozen, and the dup'd objects are immediately dup'd and frozen on insert in to the hash, the end user will only ever see two frozen strings. Since the strings are immutable, this commit just cheats a little and reuses the immutable strings. Just to reiterate, before this commit, deep duping a hash that looks like this: `{ "foo" => "bar" }` will generate two new instances of "foo". One is created when `deep_dup` is called on "foo", and the other is created when the newly allocated "foo" string is inserted in to the hash. The user never sees the intermediate "foo", and both copies of "foo" that the user *can* access will be frozen, so in this case we just reuse the existing frozen key. The upshot is that after this change, string allocations on AR allocations become constant regardless of the number of columns the model has. ```ruby require 'active_record' class Topic < ActiveRecord::Base end 20.times do |i| Process.waitpid fork { ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' ActiveRecord::Base.connection.instance_eval do create_table(:topics) do |t| t.string :title, limit: 250 t.string :author_name t.string :author_email_address t.string :parent_title t.string :type t.string :group i.times do |j| t.integer :"aaa#{j}" end t.timestamps null: true end end ObjectSpace::AllocationTracer.setup(%i{type}) Topic.create title: "aaron" # heat cache result = ObjectSpace::AllocationTracer.trace do 10.times do |i| Topic.create title: "aaron #{i}" end end puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_STRING }.last.first / 10)}" } end ``` If you run the above script before this commit, the output looks like this: ``` [aaron@TC rails (master)]$ be ruby -rallocation_tracer test.rb 9,105 10,107 11,109 12,111 13,113 14,115 15,117 16,119 17,121 18,123 19,125 20,127 21,129 22,131 23,133 24,135 25,137 26,139 27,141 28,143 ``` The left column is the number of methods, the right column is the number of string allocations. Running against this commit, the output is: ``` [aaron@TC rails (master)]$ be ruby -rallocation_tracer test.rb 9,87 10,87 11,87 12,87 13,87 14,87 15,87 16,87 17,87 18,87 19,87 20,87 21,87 22,87 23,87 24,87 25,87 26,87 27,87 28,87 ``` As you can see, there is now only a constant number of strings allocated, regardless of the number of columns the model has.
* | | | | | Merge pull request #21868 from tanmay3011/fix_time_class_documentationVijay Dev2015-10-051-3/+3
|\ \ \ \ \ \ | | | | | | | | | | | | | | [ci skip] Fix #seconds_since_midnight documentation output it will al…
| * | | | | | [ci skip] Fix #seconds_since_midnight documentation output it will always ↵Tanmay Sinha2015-10-051-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | return floating pointnumber
* | | | | | | Merge pull request #21866 from tanmay3011/fix_documentationSean Griffin2015-10-041-1/+1
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Fix Time.now format in documentation [ci skip]
| * | | | | | | Fix Time.now format in documentationTanmay Sinha2015-10-041-1/+1
| |/ / / / / /
* | | | | | | Merge pull request #21863 from tanmay3011/use_applications_yearSean Griffin2015-10-041-1/+1
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Use #current instead of #now to prevent zone issues and use new ruby …
| * | | | | | | Use Time#current instead of Time#now to prevent zone issue inorder to use ↵Tanmay Sinha2015-10-041-1/+1
| |/ / / / / / | | | | | | | | | | | | | | | | | | | | | application's time zone
* | | | | | | Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-10-042-2/+2
|\ \ \ \ \ \ \ | |/ / / / / / |/| | | | | |
| * | | | | | Renamed ‘Return’ to ‘Returns’ [ci skip]Ronak Jangir2015-09-282-2/+2
| | | | | | |
* | | | | | | Wrong usage of 'a' in docs fixed [ci skip]Mehmet Emin İNAÇ2015-10-031-1/+1
| | | | | | |
* | | | | | | Regex fix for mattr_accessor validationAliaksandr Buhayeu2015-10-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change ^ and $ operators to \A and \z to prevent code injection after the line breaks
* | | | | | | Improve readability of docs by using code tag [ci skip]Prakash Laxkar2015-09-293-3/+3
| | | | | | |
* | | | | | | Merge pull request #21807 from ronakjangir47/fix_formatted_offset_docsRafael Mendonça França2015-09-292-1/+4
|\ \ \ \ \ \ \ | |_|_|_|_|_|/ |/| | | | | | Update docs for `formatted_offset`
| * | | | | | Update docs for `formatted_offset` Ronak Jangir2015-09-292-1/+4
| | | | | | | | | | | | | | | | | | | | | Output of `formatted_offset` is depends on input so it’s not always in +HH:MM format. Possible outputs are “+5:30”, “+530” or provided alternate UTC string [ci skip]
* | | | | | | Merge pull request #21782 from ronakjangir47/transform_values_docsRafael Mendonça França2015-09-282-8/+17
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Updated docs for transform_keys & transform_values
| * | | | | | | Updated docs for transform_values [ci skip]Ronak Jangir2015-09-281-3/+8
| | | | | | | |
| * | | | | | | Updated docs for transform_keys [ci skip]Ronak Jangir2015-09-281-5/+9
| |/ / / / / /
* / / / / / / Speed up `Hash#transform_values` when emptySean Griffin2015-09-281-0/+1
|/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We're calling this function on an empty hash as part of copying the attribute set during dirty checking initialization. The new structure caused a performance regression on loading records from the database. This causes `User.all.to_a` to perform about 10% faster w/ 10k records. Calculating ------------------------------------- User.all - master 9.000 i/100ms User.all - sg-fix-ar-regression 8.000 i/100ms ------------------------------------------------- User.all - master 81.236 (± 7.4%) i/s - 405.000 User.all - sg-fix-ar-regression 89.716 (± 7.8%) i/s - 448.000
* | | | | | Improve readability of docs by using code tag [ci skip]amitkumarsuroliya2015-09-242-3/+3
| | | | | |
* | | | | | Merge pull request #21678 from ronakjangir47/array_to_formatted_s_docsYves Senn2015-09-221-1/+3
|\ \ \ \ \ \ | | | | | | | | | | | | | | Added Examples in docs for internal behavior of Array#to_formatted_s [ci skip]
| * | | | | | Added Examples in docs for internal behavior of Array#to_formatted_s [ci skip]Ronak Jangir2015-09-191-1/+3
| | | | | | |
* | | | | | | Short-circuit `blank?` on date and time valuesAndrew White2015-09-215-1/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The concept of a blank date or time doesn't make sense so we can short circuit the calls for `blank?` on these classes to gain small speed boost. Fixes #21657
* | | | | | | Applying right result of examples in ActiveSupport Multibyte [ci skip]amitkumarsuroliya2015-09-211-6/+4
| | | | | | |
* | | | | | | String#strip_heredocs doesn't need Object#tryVlado Cingel2015-09-191-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Call to Object#try was removed with this pull request https://github.com/rails/rails/pull/21596
* | | | | | | Merge pull request #21669 from amitsuroliya/improve_docsYves Senn2015-09-191-2/+2
|\ \ \ \ \ \ \ | | | | | | | | | | | | | | | | Correcting `NameError` error message in `mattr_reader` method. [ci skip]
| * | | | | | | Correcting `NameError` error message in `mattr_reader` method. Since this ↵amitkumarsuroliya2015-09-191-2/+2
| |/ / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commit https://github.com/rails/rails/commit/7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d, `NameError` includes attribute_name also in error message [ci skip]
* | | | | | | Corrected numeric conversions output [ci skip]amitkumarsuroliya2015-09-191-2/+2
| | | | | | |
* | | | | | | Replace `#=>` with `# =>` [ci skip]amitkumarsuroliya2015-09-191-2/+2
|/ / / / / / | | | | | | | | | | | | | | | | | | @rafaelfranca suggested in https://github.com/rails/rails/commit/f7c7bcd9c2a8b0e8c2840295d001d2d4dfd4cfae that code examples should display the result after `# =>` and not after `#=>`.
* | | | | | Merge pull request #21662 from amitsuroliya/improve_docsKasper Timm Hansen2015-09-181-3/+3
|\ \ \ \ \ \ | |/ / / / / |/| | | | | Corrected `to_time` output in ActiveSupport Date Conversion docs [ci …
| * | | | | Corrected `to_time` output in ActiveSupport Date Conversion docs.Since ↵amitkumarsuroliya2015-09-181-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://github.com/rails/rails/commit/48583f8bf74d1cefefea3cd6591bd546a9eaff6c, to_time returns times formatted as YYYY-MM-DD HH:MM:SS UTC [ci skip] `to_time` method now returns in `YYYY-MM-DD HH:MM:SS UTC` format.
* | | | | | Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-09-181-1/+1
|\ \ \ \ \ \