From 691377b5af72ea0f3223223cfb623b991c96cbb8 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Sep 2013 15:39:02 +1000 Subject: [PATCH] remove patches that have been upstreamed clean up rails4 checks so they are consistent --- lib/freedom_patches/active_record_relation.rb | 2 +- lib/freedom_patches/ar_result.rb | 33 ---------------- lib/freedom_patches/join_dependency.rb | 22 ----------- lib/freedom_patches/performance_fixes.rb | 39 ++++++++++--------- lib/freedom_patches/rails_security_fixes.rb | 2 +- .../rails_multisite/connection_management.rb | 2 +- 6 files changed, 23 insertions(+), 77 deletions(-) delete mode 100644 lib/freedom_patches/ar_result.rb delete mode 100644 lib/freedom_patches/join_dependency.rb diff --git a/lib/freedom_patches/active_record_relation.rb b/lib/freedom_patches/active_record_relation.rb index ab5cb77ea..be6ca5a53 100644 --- a/lib/freedom_patches/active_record_relation.rb +++ b/lib/freedom_patches/active_record_relation.rb @@ -1,4 +1,4 @@ -unless Rails.version =~ /^4/ +unless rails4? module ActiveRecord class Relation # Patch Rails 3 ActiveRecord::Relation to noop on Rails 4 references diff --git a/lib/freedom_patches/ar_result.rb b/lib/freedom_patches/ar_result.rb deleted file mode 100644 index 99e38fe8d..000000000 --- a/lib/freedom_patches/ar_result.rb +++ /dev/null @@ -1,33 +0,0 @@ -#see: https://github.com/rails/rails/pull/12065 -if rails4? - module ActiveRecord - class Result - private - def hash_rows - @hash_rows ||= - begin - # We freeze the strings to prevent them getting duped when - # used as keys in ActiveRecord::Base's @attributes hash - columns = @columns.map { |c| c.dup.freeze } - @rows.map { |row| - # In the past we used Hash[columns.zip(row)] - # though elegant, the verbose way is much more efficient - # both time and memory wise cause it avoids a big array allocation - # this method is called a lot and needs to be micro optimised - hash = {} - - index = 0 - length = columns.length - - while index < length - hash[columns[index]] = row[index] - index += 1 - end - - hash - } - end - end - end - end -end diff --git a/lib/freedom_patches/join_dependency.rb b/lib/freedom_patches/join_dependency.rb deleted file mode 100644 index a88d575bb..000000000 --- a/lib/freedom_patches/join_dependency.rb +++ /dev/null @@ -1,22 +0,0 @@ -# see PR: https://github.com/rails/rails/pull/12185 -# -class ActiveRecord::Associations::JoinDependency::JoinPart - - def extract_record(row) - # Used to be: Hash[column_names_with_alias.map{|cn, an| [cn, row[an]]}] - # that is fairly inefficient cause all the values are first copied - # in to an array only to construct the Hash - # This code is performance critical as it is called per row. - hash = {} - - index = 0 - while index < column_names_with_alias.length do - cn,an = column_names_with_alias[index] - hash[cn] = row[an] - index += 1 - end - - hash - end -end - diff --git a/lib/freedom_patches/performance_fixes.rb b/lib/freedom_patches/performance_fixes.rb index 30827702a..ee6b66d08 100644 --- a/lib/freedom_patches/performance_fixes.rb +++ b/lib/freedom_patches/performance_fixes.rb @@ -10,27 +10,28 @@ class ActiveRecord::Base end end -class ActionView::Helpers::AssetTagHelper::AssetIncludeTag -private +unless rails4? + class ActionView::Helpers::AssetTagHelper::AssetIncludeTag + private - # pluralization is fairly expensive, and pluralizing the word javascript 400 times is pointless - # this is fixed in Rails 4 + # pluralization is fairly expensive, and pluralizing the word javascript 400 times is pointless + # this is fixed in Rails 4 + + def path_to_asset(source, options = {}) + asset_paths.compute_public_path(source, pluralize_asset_name(asset_name), options.merge(:ext => extension)) + end + + + def path_to_asset_source(source) + asset_paths.compute_source_path(source, pluralize_asset_name(asset_name), extension) + end + + + def pluralize_asset_name(asset_name) + @@pluralization_cache ||= {} + plural = @@pluralization_cache[asset_name] ||= asset_name.to_s.pluralize + end - def path_to_asset(source, options = {}) - asset_paths.compute_public_path(source, pluralize_asset_name(asset_name), options.merge(:ext => extension)) end - - - def path_to_asset_source(source) - asset_paths.compute_source_path(source, pluralize_asset_name(asset_name), extension) - end - - - def pluralize_asset_name(asset_name) - @@pluralization_cache ||= {} - plural = @@pluralization_cache[asset_name] ||= asset_name.to_s.pluralize - end - - end diff --git a/lib/freedom_patches/rails_security_fixes.rb b/lib/freedom_patches/rails_security_fixes.rb index 2d7451211..7650af2d4 100644 --- a/lib/freedom_patches/rails_security_fixes.rb +++ b/lib/freedom_patches/rails_security_fixes.rb @@ -1,4 +1,4 @@ -unless Rails.version =~ /^4/ +unless rails4? module HTML class WhiteListSanitizer # Sanitizes a block of css code. Used by #sanitize when it comes across a style attribute diff --git a/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb b/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb index 980f543fd..6f872b280 100644 --- a/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb +++ b/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb @@ -97,7 +97,7 @@ module RailsMultisite # see: https://github.com/rails/rails/issues/8344#issuecomment-10800848 # @@default_connection_handler = ActiveRecord::Base.connection_handler - ActiveRecord::Base.send :include, NewConnectionHandler + ActiveRecord::Base.send :include, NewConnectionHandler if ActiveRecord::VERSION::MAJOR == 3 ActiveRecord::Base.connection_handler = @@default_connection_handler @@connection_handlers = {} end