Class: Flor::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/flor/core/node.rb

Direct Known Subclasses

Procedure

Defined Under Namespace

Classes: Payload, PseudoVarContainer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executor, node, message) ⇒ Node

Returns a new instance of Node.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/flor/core/node.rb', line 59

def initialize(executor, node, message)

  @executor, @execution =
    case executor
    when nil then [ nil, nil ] # for some tests
    when Hash then [ nil, executor ] # from some other tests
    else [ executor, executor.execution ] # vanilla case
    end

  @node =
    if node
      node
    elsif message
      @execution['nodes'][message['nid']]
    else
      nil
    end

  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



57
58
59
# File 'lib/flor/core/node.rb', line 57

def message
  @message
end

Instance Method Details

#child_idObject



86
# File 'lib/flor/core/node.rb', line 86

def child_id; Flor.child_id(@node['nid']); end

#cnodesObject



93
# File 'lib/flor/core/node.rb', line 93

def cnodes; @node['cnodes']; end

#cnodes_any?Boolean

Returns:

  • (Boolean)


94
# File 'lib/flor/core/node.rb', line 94

def cnodes_any?; cnodes && cnodes.any?; end

#cnodes_empty?Boolean

Returns:

  • (Boolean)


95
# File 'lib/flor/core/node.rb', line 95

def cnodes_empty?; cnodes.nil? || cnodes.empty?; end

#deref(s) ⇒ Object

Returns the referenced tree. Returns nil if not found.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/flor/core/node.rb', line 202

def deref(s)

  v = lookup_value(s)

  if Flor.is_tree?(v)

    ref =
      case v[0]
      when '_func' then true
      when '_proc' then v[1]['proc'] != s
      when '_tasker' then v[1]['tasker'] != s
      else false
      end

    v[1]['oref'] ||= v[1]['ref'] if ref && v[1]['ref']
    v[1]['ref'] = s if ref

    v

  else

    [ '_val', v, tree[2] ]
  end

rescue KeyError => ke

  nil
end

#descendant_of?(nid, on_self = true) ⇒ Boolean

Returns:

  • (Boolean)


258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/flor/core/node.rb', line 258

def descendant_of?(nid, on_self=true)

  return on_self if self.nid == nid && on_self != nil

  i = self.nid

  loop do
    node = @executor.node(i)
    break unless node
    i = node['parent']
    return true if i == nid
  end

  false
end

#domainObject



88
# File 'lib/flor/core/node.rb', line 88

def domain; Flor.domain(@execution['exid']); end

#exidObject



82
# File 'lib/flor/core/node.rb', line 82

def exid; @execution['exid']; end

#feiObject



248
249
250
251
# File 'lib/flor/core/node.rb', line 248

def fei

  "#{exid}-#{nid}"
end

#fromObject



91
# File 'lib/flor/core/node.rb', line 91

def from; @from || @message['from']; end

#hObject



80
# File 'lib/flor/core/node.rb', line 80

def h; @node; end

#lookup_tree(nid) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/flor/core/node.rb', line 132

def lookup_tree(nid)

  return nil unless nid

  node = @execution['nodes'][nid]

  tree = node && node['tree']
  return tree if tree

  par = node && node['parent']
  cid = Flor.child_id(nid)

  tree = par && lookup_tree(par)
  return subtree(tree, par, nid) if tree

  return nil if node

  tree = lookup_tree(Flor.parent_nid(nid))
  return tree[1][cid] if tree

  #tree = lookup_tree(Flor.parent_nid(nid, remove_subnid=true))
  #return tree[1][cid] if tree
    #
    # might become necessary at some point

  nil
end

#lookup_value(path) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/flor/core/node.rb', line 160

def lookup_value(path)

  original_path = path

  path =
    case path
    when '*' then [ path ]
    when String then Dense::Path.make(path).to_a
    else path
    end

  path.unshift('v') \
    if path.length < 2

  case path.first
  when /\Af(?:ld|ield)?\z/
    lookup_field(nil, path[1..-1]) # mod -> nil...
  when /\At(?:ag)?\z/
    lookup_tag(nil, path[1])
  when /\A([lgd]?)v(?:ar|ariable)?\z/
    return @message['__head'][1] if path[1] == '__head'
    lookup_var(@node, $1, path[1], path[2..-1])
  when 'node'
    lookup_in_node(path[1..-1])
  when 'exe', 'execution'
    lookup_in_execution(path[1..-1])
  else
    lookup_var(@node, '', path[0], path[1..-1])
  end

rescue KeyError => ke

  class << ke; attr_accessor :original_path, :work_path; end
  ke.original_path = original_path
  ke.work_path = path

  raise
end

#message_or_node_payloadObject



128
129
130
# File 'lib/flor/core/node.rb', line 128

def message_or_node_payload
  payload.current ? payload : node_payload
end

#nidObject



83
# File 'lib/flor/core/node.rb', line 83

def nid; @node['nid']; end

#node_closed?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/flor/core/node.rb', line 107

def node_closed?
  node_status['status'] == 'closed'
end

#node_ended?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/flor/core/node.rb', line 110

def node_ended?
  node_status['status'] == 'ended'
end

#node_open?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/flor/core/node.rb', line 113

def node_open?
  node_status['status'] == nil
end

#node_payloadObject



117
118
119
# File 'lib/flor/core/node.rb', line 117

def node_payload
  @node_payload ||= Payload.new(self)
end

#node_payload_retObject



120
121
122
# File 'lib/flor/core/node.rb', line 120

def node_payload_ret
  Flor.dup(node_payload['ret'])
end

#node_statusObject



101
102
103
# File 'lib/flor/core/node.rb', line 101

def node_status
  @node['status'].last
end

#node_status_flavourObject



104
105
106
# File 'lib/flor/core/node.rb', line 104

def node_status_flavour
  node_status['flavour']
end

#on_error_parent(skip = false) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/flor/core/node.rb', line 274

def on_error_parent(skip=false)

  if @node['in_on_error'] # prevent loop when error in on_error:
    skip = true
  end

  if (@node['on_error'] || []).find { |criteria, _| match_on?(criteria) }
    return self unless skip
    skip = false
  end

  if pn = parent_node
    return Flor::Node.new(@executor, pn, @message).on_error_parent(skip)
  end

  nil
end

#parentObject



84
# File 'lib/flor/core/node.rb', line 84

def parent; @node['parent']; end

#payloadObject



97
98
99
# File 'lib/flor/core/node.rb', line 97

def payload
  @message_payload ||= Payload.new(self, :message)
end

#payload_retObject



124
125
126
# File 'lib/flor/core/node.rb', line 124

def payload_ret
  message['payload']['ret']
end

#pointObject



90
# File 'lib/flor/core/node.rb', line 90

def point; @message['point']; end

#reheap(tree, heat) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/flor/core/node.rb', line 231

def reheap(tree, heat)

  case
  when ! heat.is_a?(Array) then '_val'
  when tree && tree[1] == [] then '_val'
  when heat[0] == '_proc' then heat[1]['proc']
  when heat[0] == '_func' then 'apply'
  when heat[0] == '_tasker' then 'task'
  else '_val'
  end
end

#to_procedure_nodeObject



253
254
255
256
# File 'lib/flor/core/node.rb', line 253

def to_procedure_node

  Flor::Procedure.new(@executor, @node, @message)
end

#treeObject



243
244
245
246
# File 'lib/flor/core/node.rb', line 243

def tree

  lookup_tree(nid)
end