Module: AdaptiveAlias
- Defined in:
- lib/adaptive_alias.rb,
lib/adaptive_alias/version.rb,
lib/adaptive_alias/patches/base.rb,
lib/adaptive_alias/hooks/relation.rb,
lib/adaptive_alias/hooks/insert_all.rb,
lib/adaptive_alias/hooks/association.rb,
lib/adaptive_alias/hooks/calculations.rb,
lib/adaptive_alias/patches/forward_patch.rb,
lib/adaptive_alias/patches/backward_patch.rb,
lib/adaptive_alias/hooks/active_record_core.rb,
lib/adaptive_alias/active_model_patches/arel_table.rb,
lib/adaptive_alias/hooks/active_record_persistence.rb,
lib/adaptive_alias/active_model_patches/apply_scope.rb,
lib/adaptive_alias/active_model_patches/read_attribute.rb,
lib/adaptive_alias/active_model_patches/write_attribute.rb,
lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb
Defined Under Namespace
Modules: ActiveModelPatches, Hooks, Patches
Constant Summary collapse
- VERSION =
'1.3.0'
Class Attribute Summary collapse
-
.current_patches ⇒ Object
Returns the value of attribute current_patches.
-
.log_interval ⇒ Object
Returns the value of attribute log_interval.
-
.unexpected_old_column_proc ⇒ Object
Returns the value of attribute unexpected_old_column_proc.
Class Method Summary collapse
- .[](old_column, new_column) ⇒ Object
- .get_or_create_model_module(klass) ⇒ Object
- .rescue_statement_invalid(relation: nil, reflection: nil, model_klass: nil, &block) ⇒ Object
Class Attribute Details
.current_patches ⇒ Object
Returns the value of attribute current_patches.
27 28 29 |
# File 'lib/adaptive_alias.rb', line 27 def current_patches @current_patches end |
.log_interval ⇒ Object
Returns the value of attribute log_interval.
26 27 28 |
# File 'lib/adaptive_alias.rb', line 26 def log_interval @log_interval end |
.unexpected_old_column_proc ⇒ Object
Returns the value of attribute unexpected_old_column_proc.
25 26 27 |
# File 'lib/adaptive_alias.rb', line 25 def unexpected_old_column_proc @unexpected_old_column_proc end |
Class Method Details
.[](old_column, new_column) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/adaptive_alias.rb', line 31 def [](old_column, new_column) old_column = old_column.to_sym new_column = new_column.to_sym Module.new do extend ActiveSupport::Concern included do patch = (column_names.include?(new_column.to_s) ? Patches::BackwardPatch : Patches::ForwardPatch).new(self, old_column, new_column) patch.apply! patch.mark_removable end end end |
.get_or_create_model_module(klass) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/adaptive_alias.rb', line 57 def get_or_create_model_module(klass) return @model_modules[klass] if @model_modules[klass] @model_modules[klass] = Module.new klass.prepend(@model_modules[klass]) return @model_modules[klass] end |
.rescue_statement_invalid(relation: nil, reflection: nil, model_klass: nil, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/adaptive_alias.rb', line 46 def rescue_statement_invalid(relation: nil, reflection: nil, model_klass: nil, &block) yield rescue ActiveRecord::StatementInvalid => error _key, patch = AdaptiveAlias.current_patches.find{|_key, patch| patch.check_matched.call(relation, reflection, model_klass, error) } raise error if patch == nil patch.remove_and_fix_association.call(relation, reflection) do return rescue_statement_invalid(relation: relation, reflection: reflection, model_klass: model_klass, &block) end end |