module Utusemi::Core::ActiveRecord::QueryMethods

Public Instance Methods

build_where(opts = :chain, *rest) click to toggle source
Calls superclass method
# File lib/utusemi/core.rb, line 178
def build_where(opts = :chain, *rest)
  return super unless utusemi_values[:flag]
  if utusemi_values[:options][:times]
    opts_with_times(opts, utusemi_values[:options][:times]) { |opts_with_mapped| super(opts_with_mapped, *rest) }
  else
    super(opts_with_mapped_column_name(opts), *rest)
  end
end
order(opts = nil, *rest) click to toggle source
Calls superclass method
# File lib/utusemi/core.rb, line 187
def order(opts = nil, *rest)
  opts = opts_with_mapped_column_name(opts) if utusemi_values[:flag]
  super
end

Private Instance Methods

mapped_column_names_for_string(string, index = nil) click to toggle source
# File lib/utusemi/core.rb, line 212
def mapped_column_names_for_string(string, index = nil)
  utusemi_column_names(index).each do |old_column_name, new_column_name|
    string.gsub!(/\b#{old_column_name}\b/, new_column_name.to_s)
  end
  string
end
opts_with_mapped_column_name(opts, index = nil) click to toggle source
# File lib/utusemi/core.rb, line 200
def opts_with_mapped_column_name(opts, index = nil)
  case opts
  when Hash
    key_values = opts.map { |key, value| [mapped_utusemi_column_name(key.to_s, index), value] }.flatten(1)
    Hash[*key_values]
  when String, Symbol
    mapped_column_names_for_string(opts.to_s, index)
  else
    opts
  end
end
opts_with_times(opts, times) { |opts_with_mapped_column_name(opts, index)| ... } click to toggle source
# File lib/utusemi/core.rb, line 194
def opts_with_times(opts, times)
  1.upto(times).map do |index|
    yield opts_with_mapped_column_name(opts, index)
  end
end