Class: Ruote::Dollar::RubyContext

Inherits:
BlankSlate show all
Defined in:
lib/ruote/svc/dollar_sub.rb

Overview

Dict uses this RubyContext class to evaluate ruby code. The method of this instance are directly visible to “$r:ruby_code” ruby code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dict) ⇒ RubyContext


229
230
231
232
233
# File 'lib/ruote/svc/dollar_sub.rb', line 229

def initialize(dict)

  @dict = dict
  @workitem = Ruote::Workitem.new(@dict.workitem)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object

Given a workitem with the field “newspaper” set to “NYT”, “$r:newspaper” will eval to “NYT”.

If the field “cars” hold the value [ “bmw”, “volkswagen” ], “$0” will eval to “bmw”.

Else the regular NoMethodError will be raised.


286
287
288
289
290
291
292
293
# File 'lib/ruote/svc/dollar_sub.rb', line 286

def method_missing(m, *args)

  if args.length < 1 && v = @workitem.fields[m.to_s]
    return v
  end

  super
end

Instance Attribute Details

#workitemObject (readonly) Also known as: wi

Returns the value of attribute workitem


227
228
229
# File 'lib/ruote/svc/dollar_sub.rb', line 227

def workitem
  @workitem
end

Instance Method Details

#d(s) ⇒ Object

This 'd' function can be called from inside $r:… notations.

pdef = Ruote.process_definition do
  sequence do
    set 'f:toto' => 'person'
    echo "${r:d('f:toto')}"
  end
end

will yield “person”.


273
274
275
276
# File 'lib/ruote/svc/dollar_sub.rb', line 273

def d(s)

  Rufus.dsub("${#{s}}", @dict)
end

#engine_idObject

The engine_id, if any.


257
258
259
260
# File 'lib/ruote/svc/dollar_sub.rb', line 257

def engine_id

  @dict.fexp.context.engine_id
end

#feiObject

The FlowExpressionId of the expression for which the rendering/substitution is occurring.


248
249
250
251
# File 'lib/ruote/svc/dollar_sub.rb', line 248

def fei

  @dict.fexp.fei
end

#flow_expressionObject Also known as: fe, fexp

The FlowExpression for which the rendering/substitution is occurring.


237
238
239
240
# File 'lib/ruote/svc/dollar_sub.rb', line 237

def flow_expression

  @dict.fexp
end