class SearchCop::SearchScope

Attributes

model[RW]
name[RW]
reflection[RW]

Public Class Methods

new(name, model) click to toggle source
# File lib/search_cop/search_scope.rb, line 24
def initialize(name, model)
  self.model = model
  self.reflection = Reflection.new
end

Public Instance Methods

aliases(hash) click to toggle source
# File lib/search_cop/search_scope.rb, line 39
def aliases(hash)
  hash.each do |key, value|
    reflection.aliases[key.to_s] = value.is_a?(Class) ? value : value.to_s
  end
end
attributes(*args) click to toggle source
# File lib/search_cop/search_scope.rb, line 29
def attributes(*args)
  args.each do |arg|
    attributes_hash arg.is_a?(Hash) ? arg : { arg => arg }
  end
end
generator(name, &block) click to toggle source
# File lib/search_cop/search_scope.rb, line 49
def generator(name, &block)
  reflection.generators[name] = block
end
options(key, options = {}) click to toggle source
# File lib/search_cop/search_scope.rb, line 35
def options(key, options = {})
  reflection.options[key.to_s] = (reflection.options[key.to_s] || {}).merge(options)
end
scope(&block) click to toggle source
# File lib/search_cop/search_scope.rb, line 45
def scope(&block)
  reflection.scope = block
end

Private Instance Methods

attributes_hash(hash) click to toggle source
# File lib/search_cop/search_scope.rb, line 55
def attributes_hash(hash)
  hash.each do |key, value|
    reflection.attributes[key.to_s] = Array(value).collect do |column|
      table, attribute = column.to_s =~ /\./ ? column.to_s.split(".") : [model.name.tableize, column]

      "#{table}.#{attribute}"
    end
  end
end