Module: TenantCheck::ActiveRecord::ActiveRecordExtension

Defined in:
lib/tenant_check/active_record/extensions.rb

Instance Method Summary collapse

Instance Method Details

#dump_arel(arel, depth = 0) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/tenant_check/active_record/extensions.rb', line 125

def dump_arel(arel, depth = 0)
  case arel
  when Array
    arel.each do |node|
      dump_arel(node, depth + 1)
    end
  when ::Arel::SelectManager
    indent_puts(depth, '[SelectManager]')
    dump_arel(arel.ast, depth + 1)
    pp arel
  when ::Arel::Nodes::SelectStatement
    indent_puts(depth, '[SelectStatement]')
    dump_arel(arel.cores, depth + 1)
  when ::Arel::Nodes::SelectCore
    indent_puts(depth, '[SelectCore]')
    indent_puts(depth + 1, 'projections=')
    dump_arel(arel.projections, depth + 1)
    indent_puts(depth + 1, 'join_source=')
    dump_arel(arel.source, depth + 2)
    indent_puts(depth + 1, 'wheres=')
    dump_arel(arel.wheres, depth + 1)
  when ::Arel::Nodes::Node
    indent_puts(depth, "[#{arel.class}]")
  when ::Arel::Attributes::Attribute
    indent_puts(depth, "[#{arel.class}]")
  end
end

#find_by_sql(sql, binds = [], preparable: nil, &block) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/tenant_check/active_record/extensions.rb', line 111

def find_by_sql(sql, binds = [], preparable: nil, &block)
  puts '************************* find_by_sql'
  puts caller
  puts '************************* sql'
  pp sql
  puts '************************* binds'
  pp binds
  puts '************************* to_sql'
  puts connection.to_sql(sql, binds)
  puts '************************* dump_arel'
  dump_arel(sql)
  super
end

#indent_puts(depth, str) ⇒ Object



153
154
155
# File 'lib/tenant_check/active_record/extensions.rb', line 153

def indent_puts(depth, str)
  puts '  ' * depth + str
end