Class: SearchCop::SearchScope
- Inherits:
-
Object
- Object
- SearchCop::SearchScope
- Defined in:
- lib/search_cop/search_scope.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reflection ⇒ Object
Returns the value of attribute reflection.
Instance Method Summary collapse
- #aliases(hash) ⇒ Object
- #attributes(*args) ⇒ Object
- #generator(name, &block) ⇒ Object
-
#initialize(name, model) ⇒ SearchScope
constructor
A new instance of SearchScope.
- #options(key, options = {}) ⇒ Object
- #scope(&block) ⇒ Object
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
#model ⇒ Object
Returns the value of attribute model.
23 24 25 |
# File 'lib/search_cop/search_scope.rb', line 23 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/search_cop/search_scope.rb', line 23 def name @name end |
#reflection ⇒ Object
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 (key, = {}) reflection.[key.to_s] = (reflection.[key.to_s] || {}).merge() end |
#scope(&block) ⇒ Object
46 47 48 |
# File 'lib/search_cop/search_scope.rb', line 46 def scope(&block) reflection.scope = block end |