class AWS::SimpleWorkflow::HistoryEvent::Attributes

A collection off attributes that provides method and hash style access to a collection of attributes.

If you are exploring a history event, you can call {#keys} to get a complete list of attribute names present. You can also reference the service API documentation that lists all history event types along with their returned attributes.

Indifferent Access

Here are a few examples showing the different ways to access an attribute:

event = workflow_executions.events.first

# equivalent
event.attributes.task_list
event.attributes[:task_list]
event.attributes['task_list']
event.attributes['taskList']

As shown in the example above keys and method names can be snake_cased or camelCased (strings or symbols).

Special Attributes

The following list of attributes are treated specially. Generally this means they return

Public Class Methods

new(workflow_execution, data) click to toggle source

@private

# File lib/aws/simple_workflow/history_event.rb, line 170
def initialize workflow_execution, data
  @workflow_execution = workflow_execution
  @data = data
end

Public Instance Methods

[](key) click to toggle source

@param [String,Symbol] key @return Returns the attribute with the given name (key).

# File lib/aws/simple_workflow/history_event.rb, line 177
def [] key
  key = _camel_case(key)
  if @data.key?(key)
    _cast(key, @data[key])
  else
    msg = "no such attribute `#{key}`, valid keys are #{_key_string}"
    raise ArgumentError, msg
  end
end
has_key?(key)
Alias for: key?
include?(key)
Alias for: key?
inspect() click to toggle source

@private

# File lib/aws/simple_workflow/history_event.rb, line 221
def inspect
  "<Attributes #{to_h.inspect}>"
end
key?(key) click to toggle source

@return [Boolean] Returns true if the attribute with the given

name is set.
# File lib/aws/simple_workflow/history_event.rb, line 195
def key? key
  @data.key?(_camel_case(key))
end
Also aliased as: member?, include?, has_key?
keys() click to toggle source

@return [Array<Symbol>] Returns a list of valid keys for this

set of attributes.
# File lib/aws/simple_workflow/history_event.rb, line 189
def keys
  @data.keys.collect{|key| _snake_case(key) }
end
member?(key)
Alias for: key?
method_missing(method) click to toggle source

(see {#[]})

# File lib/aws/simple_workflow/history_event.rb, line 203
def method_missing method
  self[method]
end
to_h() click to toggle source

@return [Hash] Returns all of the attributes in a hash with

snaked_cased and symbolized keys.
# File lib/aws/simple_workflow/history_event.rb, line 209
def to_h
  @data.inject({}) do |h,(key,value)|
    value = _cast(key,value)
    if value.is_a?(Array)
      value = value.map{|v| v.is_a?(Attributes) ? v.to_h : v }
    end
    h[_snake_case(key)] = value.is_a?(Attributes) ? value.to_h : value
    h
  end
end

Protected Instance Methods

_camel_case(key) click to toggle source
# File lib/aws/simple_workflow/history_event.rb, line 266
def _camel_case key
  key = key.to_s.split(/_/).collect{|k| k[0] = k[0,1].upcase; k}.join
  key[0] = key[0,1].downcase
  key
end
_cast(key, value) click to toggle source
# File lib/aws/simple_workflow/history_event.rb, line 231
def _cast key, value
  case key
  when /Timeout$/
    value.to_s =~ /^\d+$/ ? value.to_i : value.downcase.to_sym
  when 'taskList'
    value['name']
  when 'childPolicy'
    value.downcase.to_sym
  when 'activityType'
    name = value['name']
    version = value['version']
    @workflow_execution.domain.activity_types[name,version]
  when 'workflowType'
    name = value['name']
    version = value['version']
    @workflow_execution.domain.workflow_types[name,version]
  when 'workflowExecution'
    workflow_id = value['workflowId']
    run_id = value['runId']
    @workflow_execution.domain.workflow_executions[workflow_id, run_id]
  else
    case value
    when Array then value.collect{|v| _cast(key,v) }
    when Hash then Attributes.new(@workflow_execution, value)
    else value
    end
  end
end
_key_string() click to toggle source
# File lib/aws/simple_workflow/history_event.rb, line 226
def _key_string
  keys.map(&:inspect).join(', ')
end
_snake_case(key) click to toggle source
# File lib/aws/simple_workflow/history_event.rb, line 261
def _snake_case key
  Core::Inflection.ruby_name(key.to_s).to_sym
end