Module: SimpleNestedSetPatchArel2

Defined in:
lib/simple_nested_set/patches/arel_table_initialization.rb

Overview

patch for Arel 2.0.x

we need to save the provided options in order to pass them to the new Arel-Table. This way, we should be able to maintain the interface and just add the “as”-funtionality

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/simple_nested_set/patches/arel_table_initialization.rb', line 75

def self.included(base)
  base.class_eval do
    attr_reader :provided_options
    alias_method :initialize_without_saving_options, :initialize
    alias_method :initialize, :initialize_with_saving_options
  end
end

Instance Method Details

#as(table_alias) ⇒ Object



90
91
92
# File 'lib/simple_nested_set/patches/arel_table_initialization.rb', line 90

def as(table_alias)
  Arel::Table.new(name, provided_options.merge(:as => table_alias))
end

#initialize_with_saving_options(*args) ⇒ Object

name, engine = Arel::Table.engine



83
84
85
86
87
88
# File 'lib/simple_nested_set/patches/arel_table_initialization.rb', line 83

def initialize_with_saving_options(*args) # name, engine = Arel::Table.engine
  engine = args[1]
  @provided_options = (engine.is_a?(Hash)) ? engine : {}

  initialize_without_saving_options *args
end