Class: Mio::Model::LaunchWorkflowAction::WorkflowVariable

Inherits:
Mio::Model
  • Object
show all
Defined in:
lib/mio/model/launchworkflow/workflow_variable.rb

Instance Attribute Summary

Attributes inherited from Mio::Model

#args, #client, #search

Instance Method Summary collapse

Methods inherited from Mio::Model

#configure, #create, field, #go, #initialize, mappings, nested, #set_enable, set_resource, #set_start

Constructor Details

This class inherits a constructor from Mio::Model

Instance Method Details

#asset_by_idObject



26
27
28
29
30
31
32
33
# File 'lib/mio/model/launchworkflow/workflow_variable.rb', line 26

def asset_by_id
  asset = @client.find 'assets', @args.value

  if asset[:status] == 404
    raise Mio::Model::NoSuchResource, 'No such asset [' + @args.value + ']'
  end
  @args.value
end

#create_hashObject



13
14
15
16
17
# File 'lib/mio/model/launchworkflow/workflow_variable.rb', line 13

def create_hash
  {@args.type+'-variable-key' => {value: @args.key, isExpression: false},
   @args.type+'-variable-value' => {value: @args.value, isExpression: false}
  }
end

#validateObject Also known as: valid?



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mio/model/launchworkflow/workflow_variable.rb', line 42

def validate
  super
  if @args.type == 'date'
    validate_date_value
  end
  if @args.type == 'object'
    validate_object_value
  end

  true
end

#validate_date_valueObject



19
20
21
22
23
24
# File 'lib/mio/model/launchworkflow/workflow_variable.rb', line 19

def validate_date_value
  # Ensure value conforms to dd-MM-yyyy HH:mm:ss
  unless @args.value =~ /^(?:0?[1-9]|[1-2]\d|3[01])-(?:0?[1-9]|1[0-2])-\d{4}\s([0]?\d|1\d|2[0-3]):([0-5]\d):([0-5]\d)$/
    raise Mio::Model::DateVariableInvalid, 'Workflow variable of type date must conform to dd-MM-yy HH:mm:ss [' + @args.value + ']'
  end
end

#validate_object_valueObject



35
36
37
38
39
40
# File 'lib/mio/model/launchworkflow/workflow_variable.rb', line 35

def validate_object_value
  unless @args.value =~ /^[0-9]*$/
    raise Mio::Model::ObjectVariableInvalid, 'Workflow variable of type object must be a number [' + @args.value + ']'
  end
  asset_by_id
end