Class: Matching::ActiveRelationStore
- Inherits:
-
Object
- Object
- Matching::ActiveRelationStore
- Defined in:
- lib/matching/active_relation_store.rb
Overview
Stores and retrieves data from ActiveRelation for Matcher
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#where_clause ⇒ Object
readonly
Returns the value of attribute where_clause.
Instance Method Summary collapse
-
#each(&blk) ⇒ Object
Iterates over array, also returning id.
-
#find(id) ⇒ Object
Return an object by its AR id.
-
#initialize(model, where_clause = nil) ⇒ ActiveRelationStore
constructor
A new instance of ActiveRelationStore.
Constructor Details
#initialize(model, where_clause = nil) ⇒ ActiveRelationStore
Returns a new instance of ActiveRelationStore.
10 11 12 13 |
# File 'lib/matching/active_relation_store.rb', line 10 def initialize(model, where_clause = nil) @model = model @where_clause = where_clause end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/matching/active_relation_store.rb', line 8 def model @model end |
#where_clause ⇒ Object (readonly)
Returns the value of attribute where_clause.
8 9 10 |
# File 'lib/matching/active_relation_store.rb', line 8 def where_clause @where_clause end |
Instance Method Details
#each(&blk) ⇒ Object
Iterates over array, also returning id
16 17 18 19 20 21 22 |
# File 'lib/matching/active_relation_store.rb', line 16 def each(&blk) @model.where(@where_clause).find_in_batches do |group| group.each do |obj| blk.yield(obj, obj.id) end end end |
#find(id) ⇒ Object
Return an object by its AR id
25 26 27 |
# File 'lib/matching/active_relation_store.rb', line 25 def find(id) @model.find(id) end |