Class: OpenWFE::ProcessDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/openwfe/expressions/rprocdef.rb

Overview

Extend this class to create a programmatic process definition.

A short example :

class MyProcessDefinition < OpenWFE::ProcessDefinition
    def make
        process_definition :name => "test1", :revision => "0" do
            sequence do
                set :variable => "toto", :value => "nada"
                print "toto:${toto}"
            end
        end
    end
end

li = OpenWFE::LaunchItem.new(MyProcessDefinition)
engine.launch(li)

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProcessDefinition

Returns a new instance of ProcessDefinition.



74
75
76
77
78
# File 'lib/openwfe/expressions/rprocdef.rb', line 74

def initialize

    super()
    @context = Context.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/openwfe/expressions/rprocdef.rb', line 80

def method_missing (m, *args, &block)

    #puts "__i_method_missing >>>#{m}<<<<"

    ProcessDefinition.make_expression(
        @context, 
        OpenWFE::to_expression_name(m),
        ProcessDefinition.pack_args(args), 
        &block)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



72
73
74
# File 'lib/openwfe/expressions/rprocdef.rb', line 72

def context
  @context
end

Class Method Details

.do_make(instance = nil) ⇒ Object

A class method for actually “making” the process segment raw representation



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
198
199
200
201
202
203
# File 'lib/openwfe/expressions/rprocdef.rb', line 172

def self.do_make (instance=nil)

    context = if @ccontext

        @ccontext.discard
            # preventing further additions in case of reevaluation
        @ccontext

    elsif instance

        instance.make
        instance.context
    else    

        pdef = self.new
        pdef.make
        pdef.context
    end

    return context.top_expression if context.top_expression

    name, revision = 
        extract_name_and_revision(self.metaclass.to_s[8..-2])

    top_expression = [ 
        "process-definition", 
        { "name" => name, "revision" => revision }, 
        context.top_expressions 
    ]

    top_expression
end

.eval_ruby_process_definition(code, safety_level = 2) ⇒ Object

Turns a String containing a ProcessDefinition …



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/openwfe/expressions/rprocdef.rb', line 224

def self.eval_ruby_process_definition (code, safety_level=2)

    #puts "\nin:\n#{code}\n"

    code, is_wrapped = wrap_code code

    o = Rufus::eval_safely code, safety_level, binding()

    o = extract_class(code) \
        if (o == nil) or o.is_a?(Array)
        #if (o == nil) or o.is_a?(SimpleExpRepresentation)
            #
            # grab the first process definition class found
            # in the given code

    #return o.do_make \
    #    if o.is_a?(ProcessDefinition) or o.is_a?(Class)
    #o

    result = o.do_make

    #return result.first_child if is_wrapped
    return result.last.first if is_wrapped

    result
end

.extract_class(ruby_proc_def_string) ⇒ Object

Parses the string to find the class name of the process definition and returns that class (instance).



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/openwfe/expressions/rprocdef.rb', line 209

def self.extract_class (ruby_proc_def_string)

    ruby_proc_def_string.each_line do |l|

        m = ClassNameRex.match l

        return eval(m[1]) if m
    end

    nil
end

.make_expression(context, exp_name, params, &block) ⇒ Object

builds an actual expression representation (a node in the process definition tree).



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
159
160
161
# File 'lib/openwfe/expressions/rprocdef.rb', line 107

def self.make_expression (context, exp_name, params, &block)

    string_child = nil
    #attributes = OpenWFE::SymbolHash.new
    attributes = Hash.new

    #puts " ... params.class is #{params.class}"

    if params.kind_of?(Hash)

        params.each do |k, v|

            if k == '0'
                string_child = v.to_s
            else
                #attributes[OpenWFE::symbol_to_name(k.to_s)] = v.to_s
                attributes[OpenWFE::symbol_to_name(k.to_s)] = v
            end
        end

    elsif params

        string_child = params.to_s
    end

    exp = [ exp_name, attributes, [] ]

    exp.last << string_child \
        if string_child

    if context.parent_expression
        #
        # adding this new expression to its parent
        #
        context.parent_expression.last << exp
    else
        #
        # an orphan, a top expression
        #
        context.top_expressions << exp
    end

    return exp unless block

    context.push_parent_expression exp

    result = block.call

    exp.last << result \
        if result and result.kind_of?(String)

    context.pop_parent_expression

    exp
end

.metaclassObject



70
# File 'lib/openwfe/expressions/rprocdef.rb', line 70

def self.metaclass; class << self; self; end; end

.method_missing(m, *args, &block) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/openwfe/expressions/rprocdef.rb', line 91

def self.method_missing (m, *args, &block)

    @ccontext = Context.new \
        if (not @ccontext) or @ccontext.discarded?

    ProcessDefinition.make_expression(
        @ccontext, 
        OpenWFE::to_expression_name(m),
        ProcessDefinition.pack_args(args), 
        &block)
end

Instance Method Details

#do_makeObject



163
164
165
166
# File 'lib/openwfe/expressions/rprocdef.rb', line 163

def do_make

    ProcessDefinition.do_make self
end