Class: Urbit::Fact::GraphUpdateFact

Inherits:
BaseFact
  • Object
show all
Defined in:
lib/urbit/fact/graph_fact.rb

Direct Known Subclasses

AddGraphFact, AddNodesFact, RemoveGraphFact

Instance Attribute Summary

Attributes inherited from BaseFact

#ack, #channel, #data, #type

Instance Method Summary collapse

Methods inherited from BaseFact

#add_ack, #contents, #create_parser, #for_this_ship?, #is_acknowledged?, #raw_json, #ship, #to_s

Constructor Details

#initialize(channel:, event:) ⇒ GraphUpdateFact

Returns a new instance of GraphUpdateFact.



6
7
8
# File 'lib/urbit/fact/graph_fact.rb', line 6

def initialize(channel:, event:)
  super channel: channel, event: event
end

Instance Method Details

#attach_parserObject

Attach this new fact as a node to its Graph.



13
14
15
16
17
# File 'lib/urbit/fact/graph_fact.rb', line 13

def attach_parser
  if self.incoming_graph
    self.create_parser
  end
end

#graph_update?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/urbit/fact/graph_fact.rb', line 19

def graph_update?
  true
end

#incoming_graphObject



23
24
25
# File 'lib/urbit/fact/graph_fact.rb', line 23

def incoming_graph
  self.ship.graph(resource: self.resource)
end

#resourceObject



27
28
29
# File 'lib/urbit/fact/graph_fact.rb', line 27

def resource
  return "~#{self.resource_h["ship"]}/#{self.resource_h["name"]}" unless self.resource_h.nil?
end

#resource_hObject



31
32
33
# File 'lib/urbit/fact/graph_fact.rb', line 31

def resource_h
  self.raw_json["resource"]
end

#root_hObject



35
36
37
# File 'lib/urbit/fact/graph_fact.rb', line 35

def root_h
  self.contents["json"]["graph-update"]
end

#to_hObject



39
40
41
# File 'lib/urbit/fact/graph_fact.rb', line 39

def to_h
  super.merge!(resource: self.resource)
end