Replace alias_method_chain with Module#prepend
This commit is contained in:
parent
f412c80d3f
commit
f940a154f3
4 changed files with 66 additions and 75 deletions
|
@ -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
|
||||
|
|
|
@ -8,31 +8,32 @@ module I18n
|
|||
ex.entry[:other]
|
||||
end
|
||||
end
|
||||
|
||||
class Simple
|
||||
def store_translations_with_normalisation(locale, data, options = {})
|
||||
locale = I18n::Locale::Tag::Rfc4646.tag(locale).to_s
|
||||
|
||||
store_translations_without_normalisation(locale, data, options)
|
||||
end
|
||||
|
||||
alias_method_chain :store_translations, :normalisation
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module JS
|
||||
class FallbackLocales
|
||||
def default_fallbacks_with_validation
|
||||
default_fallbacks_without_validation.select do |locale|
|
||||
module OSM
|
||||
module I18n
|
||||
module NormaliseLocales
|
||||
def store_translations(locale, data, options = {})
|
||||
locale = ::I18n::Locale::Tag::Rfc4646.tag(locale).to_s
|
||||
|
||||
super(locale, data, options)
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
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
|
||||
|
||||
alias_method_chain :add_index_options, :columns
|
||||
module PostgreSQL
|
||||
module Quoting
|
||||
def quote_column_name(name)
|
||||
Array(name).map { |n| super(n) }.join(", ")
|
||||
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 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue