Module: ArelMysqlIndexHint::ActiveRecordHintMethods

Defined in:
lib/arel-mysql-index-hint/active_record-hint_methods.rb

Instance Method Summary collapse

Instance Method Details

#build_arelObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/arel-mysql-index-hint/active_record-hint_methods.rb', line 17

def build_arel
  arel = super

  if mysql_index_hint_value.present?
    if mysql_index_hint_value.values.any? {|i| i.is_a?(Hash) }
      index_hint_by_table = mysql_index_hint_value
    else
      index_hint_by_table = Hash.new(mysql_index_hint_value)
    end

    arel.ast.select {|i| i.is_a?(Arel::Table) }.each do |node|
      node.index_hint = index_hint_by_table[node.name]
    end
  end

  arel
end

#hint(index_hint_by_table) ⇒ Object



11
12
13
14
15
# File 'lib/arel-mysql-index-hint/active_record-hint_methods.rb', line 11

def hint(index_hint_by_table)
  self.mysql_index_hint_value ||= {}.with_indifferent_access
  mysql_index_hint_value.deep_merge!(index_hint_by_table)
  self
end

#mysql_index_hint_valueObject



7
8
9
# File 'lib/arel-mysql-index-hint/active_record-hint_methods.rb', line 7

def mysql_index_hint_value
  @values[:mysql_index_hint]
end

#mysql_index_hint_value=(value) ⇒ Object



3
4
5
# File 'lib/arel-mysql-index-hint/active_record-hint_methods.rb', line 3

def mysql_index_hint_value=(value)
  @values[:mysql_index_hint] = value
end