Module: Mementus::Mutators

Included in:
GraphBuilder, MutableGraph
Defined in:
lib/mementus/mutators.rb

Instance Method Summary collapse

Instance Method Details

#add_edge(id: nil, from: nil, to: nil, label: nil, props: {}) ⇒ Object



18
19
20
21
# File 'lib/mementus/mutators.rb', line 18

def add_edge(id: nil, from: nil, to: nil, label: nil, props: {})
  id = @edge_ids.next_id unless id
  set_edge(Edge.new(id: id, from: from, to: to, label: label, props: props))
end

#add_node(id: nil, label: nil, props: {}) ⇒ Object



13
14
15
16
# File 'lib/mementus/mutators.rb', line 13

def add_node(id: nil, label: nil, props: {})
  id = @node_ids.next_id unless id
  set_node(Node.new(id: id, label: label, props: props))
end

#create_edge {|builder| ... } ⇒ Object

Yields:

  • (builder)


30
31
32
33
34
35
# File 'lib/mementus/mutators.rb', line 30

def create_edge(&block)
  builder = EdgeBuilder.new
  yield builder
  builder.id = @edge_ids.next_id unless builder.id
  set_edge(builder.to_edge)
end

#create_node {|builder| ... } ⇒ Object

Yields:

  • (builder)


23
24
25
26
27
28
# File 'lib/mementus/mutators.rb', line 23

def create_node(&block)
  builder = NodeBuilder.new
  yield builder
  builder.id = @node_ids.next_id unless builder.id
  set_node(builder.to_node)
end

#remove_edge(edge) ⇒ Object



41
42
43
# File 'lib/mementus/mutators.rb', line 41

def remove_edge(edge)
  @structure.remove_edge(edge)
end

#remove_node(node) ⇒ Object



37
38
39
# File 'lib/mementus/mutators.rb', line 37

def remove_node(node)
  @structure.remove_node(node)
end

#set_edge(edge) ⇒ Object



8
9
10
11
# File 'lib/mementus/mutators.rb', line 8

def set_edge(edge)
  @structure.set_edge(edge)
  edge
end

#set_node(node) ⇒ Object



3
4
5
6
# File 'lib/mementus/mutators.rb', line 3

def set_node(node)
  @structure.set_node(node)
  node
end