Class: SearchCop::SearchScope

Inherits:
Object
  • Object
show all
Defined in:
lib/search_cop/search_scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, model) ⇒ SearchScope

Returns a new instance of SearchScope.



25
26
27
28
# File 'lib/search_cop/search_scope.rb', line 25

def initialize(name, model)
  self.model = model
  self.reflection = Reflection.new
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



23
24
25
# File 'lib/search_cop/search_scope.rb', line 23

def model
  @model
end

#nameObject

Returns the value of attribute name.



23
24
25
# File 'lib/search_cop/search_scope.rb', line 23

def name
  @name
end

#reflectionObject

Returns the value of attribute reflection.



23
24
25
# File 'lib/search_cop/search_scope.rb', line 23

def reflection
  @reflection
end

Instance Method Details

#aliases(hash) ⇒ Object



40
41
42
43
44
# File 'lib/search_cop/search_scope.rb', line 40

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) ⇒ Object



30
31
32
33
34
# File 'lib/search_cop/search_scope.rb', line 30

def attributes(*args)
  args.each do |arg|
    attributes_hash arg.is_a?(Hash) ? arg : { arg => arg }
  end
end

#generator(name, &block) ⇒ Object



50
51
52
# File 'lib/search_cop/search_scope.rb', line 50

def generator(name, &block)
  reflection.generators[name] = block
end

#options(key, options = {}) ⇒ Object



36
37
38
# File 'lib/search_cop/search_scope.rb', line 36

def options(key, options = {})
  reflection.options[key.to_s] = (reflection.options[key.to_s] || {}).merge(options)
end

#scope(&block) ⇒ Object



46
47
48
# File 'lib/search_cop/search_scope.rb', line 46

def scope(&block)
  reflection.scope = block
end