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
readonly
Returns the value of attribute scope.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (DynamicScopeMatch) initialize(method)
constructor
A new instance of DynamicScopeMatch.
- - (Boolean) scope?
Constructor Details
- (DynamicScopeMatch) initialize(method)
A new instance of DynamicScopeMatch
15 16 17 18 19 20 21 22 23 24 |
# File 'activerecord/lib/active_record/dynamic_scope_match.rb', line 15 def initialize(method) @scope = true case method.to_s when /^scoped_by_([_a-zA-Z]\w*)$/ names = $1 else @scope = nil end @attribute_names = names && names.split('_and_') end |
Instance Attribute Details
- (Object) attribute_names (readonly)
Returns the value of attribute attribute_names
26 27 28 |
# File 'activerecord/lib/active_record/dynamic_scope_match.rb', line 26 def attribute_names @attribute_names end |
- (Object) scope (readonly)
Returns the value of attribute scope
26 27 28 |
# File 'activerecord/lib/active_record/dynamic_scope_match.rb', line 26 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) ds_match = self.new(method) ds_match.scope ? ds_match : nil end |
Instance Method Details
- (Boolean) scope?
28 29 30 |
# File 'activerecord/lib/active_record/dynamic_scope_match.rb', line 28 def scope? !@scope.nil? end |