Class: Occi::Core::ActionInstance

Inherits:
Object
  • Object
show all
Includes:
Helpers::ArgumentValidator, Helpers::InstanceAttributeResetter, Helpers::InstanceAttributesAccessor, Helpers::Renderable, Yell::Loggable
Defined in:
lib/occi/core/action_instance.rb

Overview

Class representing executable instances of actions. Every instance carries the original action definition (instance of `Action`) together with attributes chosen for this invocation of the action. Validity of `ActionInstance` instances is determined by the validity of included `Action` instance and validity of provided attribute values.

Author:

Constant Summary collapse

ERRORS =
[
  Occi::Core::Errors::AttributeValidationError,
  Occi::Core::Errors::AttributeDefinitionError,
  Occi::Core::Errors::InstanceValidationError
].freeze

Constants included from Helpers::Renderable

Helpers::Renderable::RENDERER_FACTORY_CLASS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::InstanceAttributeResetter

#attribute_names, #remove_undef_attributes, #reset_added_attributes, #reset_added_attributes!, #reset_attribute, #reset_attributes, #reset_attributes!, #reset_base_attributes, #reset_base_attributes!

Methods included from Helpers::InstanceAttributesAccessor

#[], #[]=, #attribute?

Methods included from Helpers::Renderable

extended, included, #render, #renderer_factory, renderer_factory, renderer_factory_class, #renderer_for

Constructor Details

#initialize(args = {}) ⇒ ActionInstance

Returns a new instance of ActionInstance.


27
28
29
30
31
32
33
34
# File 'lib/occi/core/action_instance.rb', line 27

def initialize(args = {})
  default_args! args

  @action = args.fetch(:action)
  @attributes = args.fetch(:attributes)

  reset_attributes
end

Instance Attribute Details

#actionAction Also known as: kind

original action definition

Returns:

  • (Action)

    the current value of action


12
13
14
# File 'lib/occi/core/action_instance.rb', line 12

def action
  @action
end

#attributesHash

attributes for this action instance

Returns:

  • (Hash)

    the current value of attributes


12
13
14
# File 'lib/occi/core/action_instance.rb', line 12

def attributes
  @attributes
end

Instance Method Details

#action_identifierString, NilClass

Short-hand for accessing the identifier of assigned `Action` instance.

Returns:

  • (String)

    identifier of the included `Action` instance

  • (NilClass)

    if no action is present


41
42
43
# File 'lib/occi/core/action_instance.rb', line 41

def action_identifier
  action ? action.identifier : nil
end

#valid!Object

Checks whether this action instance is valid. Validity is determined by the validity of the included action object and attribute value(s). This method will raise an error when the validation fails.

Raises:


90
91
92
93
94
95
# File 'lib/occi/core/action_instance.rb', line 90

def valid!
  raise Occi::Core::Errors::InstanceValidationError, 'Missing valid action object' unless action
  raise Occi::Core::Errors::InstanceValidationError, 'Missing valid attributes object' unless attributes

  attributes.each_pair { |name, attribute| valid_attribute!(name, attribute) }
end

#valid?TrueClass, FalseClass

Checks whether this action instance is valid. Validity is determined by the validity of the included action object and attribute value(s).

Returns:


71
72
73
74
75
76
77
78
79
80
# File 'lib/occi/core/action_instance.rb', line 71

def valid?
  begin
    valid!
  rescue *ERRORS => ex
    logger.warn "ActionInstance invalid: #{ex.message}"
    return false
  end

  true
end