Class: Ruote::Dollar::RubyContext
- Inherits:
-
BlankSlate
- Object
- BlankSlate
- Ruote::Dollar::RubyContext
- 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
-
#workitem ⇒ Object
(also: #wi)
readonly
Returns the value of attribute workitem.
Instance Method Summary collapse
-
#d(s) ⇒ Object
This ‘d’ function can be called from inside $r:… notations.
-
#engine_id ⇒ Object
The engine_id, if any.
-
#fei ⇒ Object
The FlowExpressionId of the expression for which the rendering/substitution is occurring.
-
#flow_expression ⇒ Object
(also: #fe, #fexp)
The FlowExpression for which the rendering/substitution is occurring.
-
#initialize(dict) ⇒ RubyContext
constructor
A new instance of RubyContext.
-
#method_missing(m, *args) ⇒ Object
Given a workitem with the field “newspaper” set to “NYT”, “$r:newspaper” will eval to “NYT”.
Constructor Details
#initialize(dict) ⇒ RubyContext
Returns a new instance of RubyContext.
230 231 232 233 234 |
# File 'lib/ruote/svc/dollar_sub.rb', line 230 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.
287 288 289 290 291 292 293 294 |
# File 'lib/ruote/svc/dollar_sub.rb', line 287 def method_missing(m, *args) if args.length < 1 && v = @workitem.fields[m.to_s] return v end super end |
Instance Attribute Details
#workitem ⇒ Object (readonly) Also known as: wi
Returns the value of attribute workitem.
228 229 230 |
# File 'lib/ruote/svc/dollar_sub.rb', line 228 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”.
274 275 276 277 |
# File 'lib/ruote/svc/dollar_sub.rb', line 274 def d(s) Rufus.dsub("${#{s}}", @dict) end |
#engine_id ⇒ Object
The engine_id, if any.
258 259 260 261 |
# File 'lib/ruote/svc/dollar_sub.rb', line 258 def engine_id @dict.fexp.context.engine_id end |
#fei ⇒ Object
The FlowExpressionId of the expression for which the rendering/substitution is occurring.
249 250 251 252 |
# File 'lib/ruote/svc/dollar_sub.rb', line 249 def fei @dict.fexp.fei end |
#flow_expression ⇒ Object Also known as: fe, fexp
The FlowExpression for which the rendering/substitution is occurring.
238 239 240 241 |
# File 'lib/ruote/svc/dollar_sub.rb', line 238 def flow_expression @dict.fexp end |