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

Returns a new instance of RubyContext.



232
233
234
235
236
# File 'lib/ruote/svc/dollar_sub.rb', line 232

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.



289
290
291
292
293
294
295
296
# File 'lib/ruote/svc/dollar_sub.rb', line 289

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.



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

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”.



276
277
278
279
# File 'lib/ruote/svc/dollar_sub.rb', line 276

def d(s)

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

#engine_idObject

The engine_id, if any.



260
261
262
263
# File 'lib/ruote/svc/dollar_sub.rb', line 260

def engine_id

  @dict.fexp.context.engine_id
end

#feiObject

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



251
252
253
254
# File 'lib/ruote/svc/dollar_sub.rb', line 251

def fei

  @dict.fexp.fei
end

#flow_expressionObject Also known as: fe, fexp

The FlowExpression for which the rendering/substitution is occurring.



240
241
242
243
# File 'lib/ruote/svc/dollar_sub.rb', line 240

def flow_expression

  @dict.fexp
end