Class: AgentClient::Segment

Inherits:
Object
  • Object
show all
Includes:
Helper, Request
Defined in:
lib/agent_client/segment.rb

Overview

Represents a link in a Stratumn application

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#underscore

Methods included from Request

#get, #post

Constructor Details

#initialize(process, obj) ⇒ Segment

Returns a new instance of Segment.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/agent_client/segment.rb', line 24

def initialize(process, obj)
  self.process = process

  self.link = obj['link']
  self.meta = link['meta']
  self.state = link['state']
  self.link_hash = obj['meta']['linkHash']
  self.references = meta['refs']

  process.info['actions'].each do |(method, _)|
    add_transition_method(method)
  end
end

Instance Attribute Details

Returns the value of attribute link.



22
23
24
# File 'lib/agent_client/segment.rb', line 22

def link
  @link
end

Returns the value of attribute link_hash.



22
23
24
# File 'lib/agent_client/segment.rb', line 22

def link_hash
  @link_hash
end

#metaObject

Returns the value of attribute meta.



22
23
24
# File 'lib/agent_client/segment.rb', line 22

def meta
  @meta
end

#processObject

Returns the value of attribute process.



22
23
24
# File 'lib/agent_client/segment.rb', line 22

def process
  @process
end

#referencesObject

Returns the value of attribute references.



22
23
24
# File 'lib/agent_client/segment.rb', line 22

def references
  @references
end

#stateObject

Returns the value of attribute state.



22
23
24
# File 'lib/agent_client/segment.rb', line 22

def state
  @state
end

Class Method Details

.from(segment) ⇒ Object



50
51
52
53
54
55
# File 'lib/agent_client/segment.rb', line 50

def self.from(segment)
  agent = Agent.load(segment['meta']['agentUrl'])
  process = agent.get segment['link']['meta']['process']

  new(process, segment)
end

Instance Method Details

#find_segments(options = {}) ⇒ Object



42
43
44
# File 'lib/agent_client/segment.rb', line 42

def find_segments(options = {})
  process.find_segments(options)
end

#loadObject



46
47
48
# File 'lib/agent_client/segment.rb', line 46

def load
  process.get_segment(link_hash)
end

#previousObject



38
39
40
# File 'lib/agent_client/segment.rb', line 38

def previous
  process.get_segment(meta['prevLinkHash']) if meta['prevLinkHash']
end