Class: SequelMapper::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel_mapper/graph.rb

Instance Method Summary collapse

Constructor Details

#initialize(datastore:, top_level_namespace:, relation_mappings:) ⇒ Graph

Returns a new instance of Graph.



7
8
9
10
11
# File 'lib/sequel_mapper/graph.rb', line 7

def initialize(datastore:, top_level_namespace:, relation_mappings:)
  @top_level_namespace = top_level_namespace
  @datastore = datastore
  @relation_mappings = relation_mappings
end

Instance Method Details

#save(graph_root) ⇒ Object



27
28
29
30
# File 'lib/sequel_mapper/graph.rb', line 27

def save(graph_root)
  @persisted_objects = []
  dump(top_level_namespace, graph_root)
end

#where(criteria) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/sequel_mapper/graph.rb', line 16

def where(criteria)
  datastore[top_level_namespace]
    .where(criteria)
    .map { |row|
      load(
        relation_mappings.fetch(top_level_namespace),
        row,
      )
    }
end