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
timeout attributes (e.g. taskStartToCloseTimeout) are returned as integers (number of seconds) or the special symbol :none, implying there is no timeout.
childPolicy is cast to a symbol
activityType is returned as a {ActivityType} object.
workflowType is returned as a {WorkflowType} object.
workflowExecution is returned as a {WorkflowExecution} object.
taskList is returned as a string, not a hash.
taskPriority is returned as an Integer, not a String.
@api private
# File lib/aws/simple_workflow/history_event.rb, line 172 def initialize workflow_execution, data @workflow_execution = workflow_execution @data = data end
@param [String,Symbol] key @return Returns the attribute with the given name (key).
# File lib/aws/simple_workflow/history_event.rb, line 179 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
@api private
# File lib/aws/simple_workflow/history_event.rb, line 223 def inspect "<Attributes #{to_h.inspect}>" end
@return [Boolean] Returns true if the attribute with the given
name is set.
# File lib/aws/simple_workflow/history_event.rb, line 197 def key? key @data.key?(_camel_case(key)) end
@return [Array<Symbol>] Returns a list of valid keys for this
set of attributes.
# File lib/aws/simple_workflow/history_event.rb, line 191 def keys @data.keys.collect{|key| _snake_case(key) } end
(see {#[]})
# File lib/aws/simple_workflow/history_event.rb, line 205 def method_missing method self[method] end
@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 211 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
# File lib/aws/simple_workflow/history_event.rb, line 270 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
# File lib/aws/simple_workflow/history_event.rb, line 233 def _cast key, value case key when /Timeout$/ value.to_s =~ /^\d+$/ ? value.to_i : value.downcase.to_sym when 'taskList' value['name'] when 'taskPriority' value.to_i 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
# File lib/aws/simple_workflow/history_event.rb, line 228 def _key_string keys.map(&:inspect).join(', ') end
# File lib/aws/simple_workflow/history_event.rb, line 265 def _snake_case key Core::Inflection.ruby_name(key.to_s).to_sym end