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.



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

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

Instance Attribute Details

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#reflectionObject

Returns the value of attribute reflection.



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

def reflection
  @reflection
end

Instance Method Details

#aliases(hash) ⇒ Object



39
40
41
42
43
# 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) ⇒ Object



29
30
31
32
33
# 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) ⇒ Object



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

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

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



35
36
37
# 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) ⇒ Object



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

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