Parent

Methods

Class/Module Index [+]

Quicksearch

Ruote::Exp::GivenExpression

This expressions corresponds to a “case” statement in Ruby or a “switch” in other languages.

It accepts two variants “given that” and “given an x of”.

‘given’ works in conjunction with the ‘that’ / ‘of’ expression.

“given that”

given do
  that "${location} == paris" do
    subprocess "notify_and_wait_for_pickup"
  end
  that "${state} == ready" do
    subprocess "deliver"
  end
  # else...
  subprocess "do_something_else"
end

“given an x of”

given "${status}" do
  of "ordered" do
    participant "alpha"
  end
  of "delivered" do
    participant "alpha"
  end
  # else...
  subprocess "do_something_else"
end

This variant also accepts regular expressions :

given "${target}" do
  of "/-manager$/" do
    # ...
  end
  of /^user-/ do
    # ...
  end
end

mixing ‘that’ and ‘of’

It’s OK to use a “that” inside a “given an x” :

given '${target}' do
  that "${location} == paris" do
    subprocess "notify_and_wait_for_pickup"
  end
  of "home" do
    subprocess "return_procedure"
  end
end

the else part

Anything that comes after the serie of ‘that’ and ‘of’ is considered in the ‘else’ zone and is executed if none of the ‘that’ or ‘of’ triggered.

given '${target}' do
  that "${location} == paris" do
    subprocess "notify_and_wait_for_pickup"
  end
  of "home" do
    subprocess "return_procedure"
  end
  subprocess "do_this"
  subprocess "and_then_that"
end

Yes, two ‘else’ subprocesses will get executed one after the other (the ‘given’ acting like a ‘sequence’ for them.

Interestingly :

given '${target}' do
  of "home" do
    subprocess "return_procedure"
  end
  subprocess "do_this"
  of "office" do
    subprocess "go_to_work"
  end
  subprocess "and_then_that"
end

If the workitem field ‘target’ is set to ‘home’ only the ‘return_procedure’ subprocess will get called.

If the workitem field ‘target’ is set to ‘office’, the ‘do_this’ subprocess, then the ‘go_to_work’ one will get called.

Public Instance Methods

reply(workitem) click to toggle source
# File lib/ruote/exp/fe_given.rb, line 133
def reply(workitem)

  if given = attribute(:t) || attribute_text
    workitem['fields']['__given__'] = given
  end

  # as soon as one child says true, reply to the parent expression

  if workitem['fields']['__result__'].to_s == 'true'

    workitem['fields'].delete('__given__')
    workitem['fields'].delete('__result__')
    reply_to_parent(workitem)

  else

    super
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.