Class: OpenWFE::RawExpression::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/openwfe/expressions/raw.rb

Overview

Encapsulating

<parameter field="x" default="y" type="z" match="m" />

Somehow I have that : OpenWFEru is not a strongly typed language … Anyway I implemented that to please Pat.

Instance Method Summary collapse

Constructor Details

#initialize(field, match, default, type) ⇒ Parameter

Returns a new instance of Parameter.



431
432
433
434
435
436
437
# File 'lib/openwfe/expressions/raw.rb', line 431

def initialize (field, match, default, type)

    @field = to_s field
    @match = to_s match
    @default = to_s default
    @type = to_s type
end

Instance Method Details

#check(workitem) ⇒ Object

Will raise an exception if this param requirement is not met by the workitem.



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/openwfe/expressions/raw.rb', line 443

def check (workitem)

    unless @field
        raise \
            OpenWFE::ParameterException,
            "'parameter'/'param' without a 'field' attribute"
    end

    field_value = workitem.attributes[@field]
    field_value = @default unless field_value

    unless field_value
        raise \
            OpenWFE::ParameterException, 
            "field '#{@field}' is missing" \
    end

    check_match(field_value)

    enforce_type(workitem, field_value)
end