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(agent, obj) ⇒ Segment

Returns a new instance of Segment.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/agent_client/segment.rb', line 16

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

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

  agent.agent_info['actions'].each do |(method, _)|
    add_transition_method(method)
  end
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



14
15
16
# File 'lib/agent_client/segment.rb', line 14

def agent
  @agent
end

Returns the value of attribute link.



14
15
16
# File 'lib/agent_client/segment.rb', line 14

def link
  @link
end

Returns the value of attribute link_hash.



14
15
16
# File 'lib/agent_client/segment.rb', line 14

def link_hash
  @link_hash
end

#metaObject

Returns the value of attribute meta.



14
15
16
# File 'lib/agent_client/segment.rb', line 14

def meta
  @meta
end

#stateObject

Returns the value of attribute state.



14
15
16
# File 'lib/agent_client/segment.rb', line 14

def state
  @state
end

Class Method Details

.from(segment) ⇒ Object



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

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

  new(agent, segment)
end

Instance Method Details

#find_segments(options = {}) ⇒ Object



33
34
35
# File 'lib/agent_client/segment.rb', line 33

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

#loadObject



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

def load
  agent.get_segment(link_hash)
end

#previousObject



29
30
31
# File 'lib/agent_client/segment.rb', line 29

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