Class: Flor::Procedure

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

Constant Summary collapse

RVARS =

“Returning vars” variables to pass back to pass upon reply. In the ‘receive’ messages, it’s a hash under the key ‘rvars’.

%w[ idx ].freeze
TRUE_ATTS =

Attributes that when given alone are turned to “true” attributes.

For example ‘sequence flank` gets turned to `sequence flank: true`

The transformation occurs in Flor::Pro::Att (“_att”).

%w[ flank off disabled ].freeze

Instance Attribute Summary

Attributes inherited from Node

#message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#child_id, #cnodes, #cnodes_any?, #cnodes_empty?, #deref, #descendant_of?, #domain, #exid, #fei, #from, #h, #initialize, #lookup_tree, #lookup_value, #message_or_node_payload, #nid, #node_closed?, #node_ended?, #node_open?, #node_payload, #node_payload_ret, #node_status, #node_status_flavour, #on_error_parent, #parent, #payload, #payload_ret, #point, #reheap, #to_procedure_node, #tree

Constructor Details

This class inherits a constructor from Flor::Node

Class Method Details

.[](name) ⇒ Object



25
26
27
28
# File 'lib/flor/core/procedure.rb', line 25

def [](name)

  @@inherited.find { |k| k.names && k.names.include?(name) }
end

.core?Boolean

Returns:

  • (Boolean)


44
# File 'lib/flor/core/procedure.rb', line 44

def core?; @core; end

.inherited(subclass) ⇒ Object



20
21
22
23
# File 'lib/flor/core/procedure.rb', line 20

def inherited(subclass)

  (@@inherited ||= []) << subclass
end

.make(executor, node, message) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/flor/core/procedure.rb', line 46

def make(executor, node, message)

  heap = node['heap']
  heac = self[heap]

  fail NameError.new("unknown procedure #{heap.inspect}") \
    unless heac

  heac.new(executor, node, message)
end

.names(*names) ⇒ Object Also known as: name



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/flor/core/procedure.rb', line 30

def names(*names)

  @names = [] unless defined?(@names)

  if (names = names.flatten).any?
    @names = names
    @core = !! caller.find { |l| l.match(/flor\/pcore/) }
  end

  @names
end

Instance Method Details

#debug_msg(msg = message) ⇒ Object



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

def debug_msg(msg=message)

  puts Flor.detail_msg(@executor, msg)
end

#debug_tree(nid = nil) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/flor/core/procedure.rb', line 95

def debug_tree(nid=nil)

  nid ||= self.nid
  tree = lookup_tree(nid)

  puts Flor.tree_to_s(tree, nid)
end

#endObject



108
109
110
111
# File 'lib/flor/core/procedure.rb', line 108

def end

  end_node
end

#flankObject



113
114
115
116
117
118
119
# File 'lib/flor/core/procedure.rb', line 113

def flank

  @node['tree'] = Flor.dup(tree)
  @node['replyto'] = nil

  wrap('nid' => parent, 'flavour' => 'flank')
end

#heapObject



121
# File 'lib/flor/core/procedure.rb', line 121

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

#pre_executeObject



58
59
60
61
# File 'lib/flor/core/procedure.rb', line 58

def pre_execute

  # empty default implementation
end

#prepare_on_receive_last(on_x, max = -1)) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/flor/core/procedure.rb', line 63

def prepare_on_receive_last(on_x, max=-1)

  on_x
    .inject([]) { |a, (criteria, mop)|

      next a if max > 0 && a.size >= max
      next a unless match_on?(criteria)

      msg = Flor.dup(@message)

      a.concat(
        if Flor.is_message?(mop)
          [ Flor.dup(mop).merge!('msg' => msg) ]
        else # procedure
          args = [ [ 'msg', msg ], [ 'err', msg['error'] ] ]
          apply(mop, args, mop[2])
        end) }
end

#trigger_on_errorObject



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/flor/core/procedure.rb', line 82

def trigger_on_error

  @message['on_error'] = true

  close_node('on-error')

  @node['on_receive_last'] =
    prepare_on_receive_last(@node['on_error'], 1)

  do_wrap_cancel_children ||
  do_receive # which should trigger 'on_receive_last'
end