This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'benchmark' | |
| ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/ | |
| FAST_ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d+))?\z/ | |
| COUNT = 1000000 | |
| SRAND = 1455677931 | |
| DATETIME_STRING = "2010-01-12 12:34:56.%6.6i" | |
| Benchmark.bm do |bench| | |
| f = bench.report("Fast") do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Recursively coerce empty string values in hash -particularly | |
| # useful for HTTP POSTed forms. | |
| # Values are coerced based on the rules mapping of params_hash keys to coerced values. | |
| # See http://dev.rubyonrails.org/ticket/5694 for background | |
| def self.coerce_empty_strings(params_hash, rules = {}) | |
| return unless params_hash | |
| params_hash.each_pair do |k,v| | |
| # AR::Base.extract_callstack_for_multiparameter_attributes can't handle nil values | |
| unless k.include?('(') | |
| params_hash[k] = rules[k.to_sym] if v.kind_of?(String) && v.empty? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ActiveRecord | |
| class Reflection::AssociationReflection | |
| # Return a named scope instead of the bare ActiveRecord::Base subclass. | |
| def klass_with_scope | |
| k = klass_without_scope | |
| options[:scope].nil? ? k : k.send(options[:scope]) | |
| end | |
| alias_method_chain :klass, :scope | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb | |
| index 7f78191..e55b639 100755 | |
| --- a/activerecord/lib/active_record/associations.rb | |
| +++ b/activerecord/lib/active_record/associations.rb | |
| @@ -1557,7 +1557,8 @@ module ActiveRecord | |
| :finder_sql, :counter_sql, | |
| :before_add, :after_add, :before_remove, :after_remove, | |
| :extend, :readonly, | |
| - :validate | |
| + :validate, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Tag | |
| has_many :taggings | |
| end | |
| class Tagging | |
| belongs_to :tag | |
| belongs_to :posts | |
| # uses a string 'flag' column but could be changed to a boolean important | |
| # column later, hence the need to encapsulate! |
NewerOlder