Class: RecordCollection
- Inherits:
-
Object
- Object
- RecordCollection
- Includes:
- Enumerable
- Defined in:
- lib/record_collection.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(base_scope) ⇒ RecordCollection
constructor
A new instance of RecordCollection.
- #is_limited_by?(scope) ⇒ Boolean
- #limit_by(scope) ⇒ Object
Constructor Details
#initialize(base_scope) ⇒ RecordCollection
Returns a new instance of RecordCollection.
5 6 7 8 |
# File 'lib/record_collection.rb', line 5 def initialize(base_scope) self.base_scope = base_scope self.scopes = Set.new end |
Instance Method Details
#each(&block) ⇒ Object
20 21 22 |
# File 'lib/record_collection.rb', line 20 def each(&block) scopes.reduce(base_scope) { |scope, base| base.merge(scope) }.each(&block) end |
#is_limited_by?(scope) ⇒ Boolean
15 16 17 18 |
# File 'lib/record_collection.rb', line 15 def is_limited_by?(scope) # because ActiveRecord::Relations do not implement hashing correctly, we must do case by case equality scopes.any? { |s| s == scope } end |
#limit_by(scope) ⇒ Object
10 11 12 13 |
# File 'lib/record_collection.rb', line 10 def limit_by(scope) scopes.add(scope) self end |