]> git.openstreetmap.org Git - rails.git/commitdiff
Replace alias_method_chain with Module#prepend
authorTom Hughes <tom@compton.nu>
Thu, 1 Jun 2017 21:41:03 +0000 (22:41 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 1 Jun 2017 21:45:28 +0000 (22:45 +0100)
config/initializers/abstract_adapter.rb
config/initializers/i18n.rb
config/initializers/router.rb
lib/migrate.rb

index 6bb5d10c01bcafcecf142d36fc1c8ce27543d5bd..290e2493d943c26470eb54d6e2a2b49f28041b5d 100644 (file)
@@ -1,21 +1,17 @@
 if defined?(ActiveRecord::ConnectionAdaptors::AbstractAdapter)
-  module ActiveRecord
-    module ConnectionAdapters
-      class AbstractAdapter
-        protected
-
-        alias old_log log
-
-        def translate_exception_class_with_timeout(e, sql)
+  module OSM
+    module AbstractAdapter
+      module PropagateTimeouts
+        def translate_exception_class(e, sql)
           if e.is_a?(Timeout::Error) || e.is_a?(OSM::APITimeoutError)
             e
           else
-            translate_exception_class_without_timeout(e, sql)
+            super(e, sql)
           end
         end
-
-        alias_method_chain :translate_exception_class, :timeout
       end
     end
   end
+
+  ActiveRecord::ConnectionAdaptors::AbstractAdapter.prepend(OSM::AbstractAdapter::PropagateTimeouts)
 end
index a94618c7e3f374f580edd1cf6eca371bb723f452..fff69378baf7246fda9e65fda0737fdebcb9479b 100644 (file)
@@ -8,31 +8,32 @@ module I18n
         ex.entry[:other]
       end
     end
+  end
+end
 
-    class Simple
-      def store_translations_with_normalisation(locale, data, options = {})
-        locale = I18n::Locale::Tag::Rfc4646.tag(locale).to_s
+module OSM
+  module I18n
+    module NormaliseLocales
+      def store_translations(locale, data, options = {})
+        locale = ::I18n::Locale::Tag::Rfc4646.tag(locale).to_s
 
-        store_translations_without_normalisation(locale, data, options)
+        super(locale, data, options)
       end
-
-      alias_method_chain :store_translations, :normalisation
     end
-  end
 
-  module JS
-    class FallbackLocales
-      def default_fallbacks_with_validation
-        default_fallbacks_without_validation.select do |locale|
+    module ValidateLocales
+      def default_fallbacks
+        super.select do |locale|
           ::I18n.available_locales.include?(locale)
         end
       end
-
-      alias_method_chain :default_fallbacks, :validation
     end
   end
 end
 
+I18n::Backend::Simple.prepend(OSM::I18n::NormaliseLocales)
+I18n::JS::FallbackLocales.prepend(OSM::I18n::ValidateLocales)
+
 I18n::Backend::Simple.include(I18n::Backend::PluralizationFallback)
 I18n::Backend::Simple.include(I18n::Backend::Fallbacks)
 
index 2987e424af8a5f282df92cb6312207e39dd11049..0987fa0183fb5fd399237857e5e03a05ef54a3b4 100644 (file)
@@ -1,18 +1,14 @@
 # Some versions of ruby seem to accidentally force the encoding
 # as part of normalize_path and some don't
 
-module ActionDispatch
-  module Journey
-    class Router
-      class Utils
-        def self.normalize_path_with_encoding(path)
-          normalize_path_without_encoding(path).force_encoding("UTF-8")
-        end
-
-        class << self
-          alias_method_chain :normalize_path, :encoding
-        end
+module OSM
+  module Router
+    module ForceEncoding
+      def normalize_path(path)
+        super(path).force_encoding("UTF-8")
       end
     end
   end
 end
+
+ActionDispatch::Journey::Router::Utils.singleton_class.prepend(OSM::Router::ForceEncoding)
index 21c1b2cf2ab7e8c03f8d2585af3f4ce1432f19e7..b9917df6d7a98e636c7dcd857614e96196c258f4 100644 (file)
@@ -1,50 +1,48 @@
-module ActiveRecord
-  module ConnectionAdapters
-    module SchemaStatements
-      def add_index_options_with_columns(table_name, column_name, options = {})
-        columns = options.delete(:columns)
-        index_name, index_type, index_columns, index_options, algorithm, using = add_index_options_without_columns(table_name, column_name, options)
-        [index_name, index_type, columns || index_columns, index_options, algorithm, using]
-      end
-
-      alias_method_chain :add_index_options, :columns
+module OSM
+  module SchemaStatements
+    def add_index_options(table_name, column_name, options = {})
+      columns = options.delete(:columns)
+      index_name, index_type, index_columns, index_options, algorithm, using = super(table_name, column_name, options)
+      [index_name, index_type, columns || index_columns, index_options, algorithm, using]
     end
+  end
 
-    module PostgreSQL
-      module Quoting
-        def quote_column_name_with_arrays(name)
-          Array(name).map { |n| quote_column_name_without_arrays(n) }.join(", ")
-        end
-
-        alias_method_chain :quote_column_name, :arrays
+  module PostgreSQL
+    module Quoting
+      def quote_column_name(name)
+        Array(name).map { |n| super(n) }.join(", ")
       end
+    end
 
-      module SchemaStatements
-        def add_primary_key(table_name, column_name, _options = {})
-          execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
-        end
+    module SchemaStatements
+      def add_primary_key(table_name, column_name, _options = {})
+        execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
+      end
 
-        def remove_primary_key(table_name)
-          execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
-        end
+      def remove_primary_key(table_name)
+        execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
+      end
 
-        def alter_primary_key(table_name, new_columns)
-          execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}"
-          execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
-        end
+      def alter_primary_key(table_name, new_columns)
+        execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}"
+        execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
+      end
 
-        def create_enumeration(enumeration_name, values)
-          execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
-        end
+      def create_enumeration(enumeration_name, values)
+        execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
+      end
 
-        def drop_enumeration(enumeration_name)
-          execute "DROP TYPE #{enumeration_name}"
-        end
+      def drop_enumeration(enumeration_name)
+        execute "DROP TYPE #{enumeration_name}"
+      end
 
-        def rename_enumeration(old_name, new_name)
-          execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
-        end
+      def rename_enumeration(old_name, new_name)
+        execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
       end
     end
   end
 end
+
+ActiveRecord::ConnectionAdapters::SchemaStatements.extend(OSM::SchemaStatements)
+ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting.extend(OSM::PostgreSQL::Quoting)
+ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements.extend(OSM::PostgreSQL::SchemaStatements)