Class: Ruote::Dollar::Dict

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

Overview

Wrapping a flow expression and the current workitem as a Hash-like object ready for lookup at substitution time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flow_expression, workitem) ⇒ Dict

Returns a new instance of Dict.



120
121
122
123
124
# File 'lib/ruote/svc/dollar_sub.rb', line 120

def initialize(flow_expression, workitem)

  @fexp = flow_expression
  @workitem = workitem
end

Instance Attribute Details

#fexpObject (readonly)

Returns the value of attribute fexp.



117
118
119
# File 'lib/ruote/svc/dollar_sub.rb', line 117

def fexp
  @fexp
end

#workitemObject (readonly)

Returns the value of attribute workitem.



118
119
120
# File 'lib/ruote/svc/dollar_sub.rb', line 118

def workitem
  @workitem
end

Instance Method Details

#[](key) ⇒ Object



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
# File 'lib/ruote/svc/dollar_sub.rb', line 126

def [](key)

  return @fexp.fei.to_storage_id if key == 'fei'
  return @fexp.fei.wfid if key == 'wfid'
  return @fexp.fei.subid if key == 'subid'
  return @fexp.fei.subid if key == 'sub_wfid' # deprecated in 2.1.12
  return @fexp.fei.expid if key == 'expid'
  return @fexp.fei.engine_id if key == 'engine_id'
  return @fexp.fei.mnemo_id if key == 'mnemo_id'

  return @workitem['fields']['__tags__'] if key == 'tags'
  return (@workitem['fields']['__tags__'] || []).last if key == 'tag'
  return (@workitem['fields']['__tags__'] || []).join('/') if key == 'full_tag'

  pr, k = extract_prefix(key)

  # stage 0

  v = lookup(pr[0, 1], k)

  return v if v != nil

  # stage 1

  return '' if pr.size < 2

  lookup(pr[1, 1], k)
end

#[]=(key, value) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/ruote/svc/dollar_sub.rb', line 155

def []=(key, value)

  pr, k = extract_prefix(key)
  pr = pr[0, 1]

  if pr == 'f'

    @workitem.set_attribute(k, value)

  elsif @fexp

    @fexp.set_variable(k, value)
  end
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


170
171
172
173
174
175
176
177
# File 'lib/ruote/svc/dollar_sub.rb', line 170

def has_key?(key)

  pr, k = extract_prefix(key)

  return true if pr == 'r'

  (self[key] != nil)
end