Class: AWS::SimpleWorkflow::HistoryEvent::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/simple_workflow/history_event.rb

Overview

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.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



203
204
205
# File 'lib/aws/simple_workflow/history_event.rb', line 203

def method_missing method
  self[method]
end

Instance Method Details

#[](key) ⇒ Object

Returns the attribute with the given name (key).

Parameters:

  • key (String, Symbol)

Returns:

  • Returns the attribute with the given name (key).



177
178
179
180
181
182
183
184
185
# 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

#key?(key) ⇒ Boolean Also known as: member?, include?, has_key?

Returns true if the attribute with the given name is set.

Returns:

  • (Boolean)

    Returns true if the attribute with the given name is set.



195
196
197
# File 'lib/aws/simple_workflow/history_event.rb', line 195

def key? key
  @data.key?(_camel_case(key))
end

#keysArray<Symbol>

Returns a list of valid keys for this set of attributes.

Returns:

  • (Array<Symbol>)

    Returns a list of valid keys for this set of attributes.



189
190
191
# File 'lib/aws/simple_workflow/history_event.rb', line 189

def keys
  @data.keys.collect{|key| _snake_case(key) }
end

#to_hHash

Returns all of the attributes in a hash with snaked_cased and symbolized keys.

Returns:

  • (Hash)

    Returns all of the attributes in a hash with snaked_cased and symbolized keys.



209
210
211
212
213
214
215
216
217
218
# 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