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.
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
#model ⇒ Object
Returns the value of attribute model.
22 23 24 |
# File 'lib/search_cop/search_scope.rb', line 22 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/search_cop/search_scope.rb', line 22 def name @name end |
#reflection ⇒ Object
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 (key, = {}) reflection.[key.to_s] = (reflection.[key.to_s] || {}).merge() end |
#scope(&block) ⇒ Object
45 46 47 |
# File 'lib/search_cop/search_scope.rb', line 45 def scope(&block) reflection.scope = block end |