Class: ActiveRecord::DynamicScopeMatch
- Inherits:
-
Object
- Object
- ActiveRecord::DynamicScopeMatch
- Defined in:
- activerecord/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)
-
- (Object) attribute_names
readonly
Returns the value of attribute attribute_names.
-
- (Object) scope
(also: #scope?)
readonly
Returns the value of attribute scope.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (DynamicScopeMatch) initialize(scope, attribute_names)
constructor
A new instance of DynamicScopeMatch.
Constructor Details
- (DynamicScopeMatch) initialize(scope, attribute_names)
A new instance of DynamicScopeMatch
15 16 17 18 |
# File 'activerecord/lib/active_record/dynamic_scope_match.rb', line 15 def initialize(scope, attribute_names) @scope = scope @attribute_names = attribute_names end |
Instance Attribute Details
- (Object) attribute_names (readonly)
Returns the value of attribute attribute_names
20 21 22 |
# File 'activerecord/lib/active_record/dynamic_scope_match.rb', line 20 def attribute_names @attribute_names end |
- (Object) scope (readonly) Also known as: scope?
Returns the value of attribute scope
20 21 22 |
# File 'activerecord/lib/active_record/dynamic_scope_match.rb', line 20 def scope @scope end |
Class Method Details
+ (Object) match(method)
10 11 12 13 |
# File 'activerecord/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 |