Class: Matching::ActiveRelationStore

Inherits:
Object
  • Object
show all
Defined in:
lib/matching/active_relation_store.rb

Overview

Stores and retrieves data from ActiveRelation for Matcher

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/matching/active_relation_store.rb', line 8

def model
  @model
end

#where_clauseObject (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