Class: ActiveRecord::DynamicScopeMatch
- Inherits:
-
Object
- Object
- ActiveRecord::DynamicScopeMatch
- Defined in:
- lib/active_record/dynamic_scope_match.rb
Overview
Active Record Dynamic Scope Match
Provides dynamic attribute-based scopes such as scoped_by_price(4.99)
if, for example, the Product
has an attribute with that name. You can chain more scoped_by_*
methods after the other. It acts like a named scope except that it’s dynamic.
Instance Attribute Summary collapse
-
#attribute_names ⇒ Object
readonly
Returns the value of attribute attribute_names.
-
#scope ⇒ Object
(also: #scope?)
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scope, attribute_names) ⇒ DynamicScopeMatch
constructor
A new instance of DynamicScopeMatch.
Constructor Details
#initialize(scope, attribute_names) ⇒ DynamicScopeMatch
Returns a new instance of DynamicScopeMatch.
15 16 17 18 |
# File 'lib/active_record/dynamic_scope_match.rb', line 15 def initialize(scope, attribute_names) @scope = scope @attribute_names = attribute_names end |
Instance Attribute Details
#attribute_names ⇒ Object (readonly)
Returns the value of attribute attribute_names.
20 21 22 |
# File 'lib/active_record/dynamic_scope_match.rb', line 20 def attribute_names @attribute_names end |
#scope ⇒ Object (readonly) Also known as: scope?
Returns the value of attribute scope.
20 21 22 |
# File 'lib/active_record/dynamic_scope_match.rb', line 20 def scope @scope end |
Class Method Details
.match(method) ⇒ Object
10 11 12 13 |
# File 'lib/active_record/dynamic_scope_match.rb', line 10 def self.match(method) return unless method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/ new(true, $1 && $1.split('_and_')) end |