Module: Occi::Core::Helpers::InstanceAttributesAccessor

Included in:
ActionInstance, Entity
Defined in:
lib/occi/core/helpers/instance_attributes_accessor.rb

Overview

Introduces instance attributes accessor as a shortcut to getting to the `attributes` values inside the receiver.

Author:

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

:nodoc:


10
11
12
# File 'lib/occi/core/helpers/instance_attributes_accessor.rb', line 10

def [](key)
  attribute?(key) ? attributes[key].value : nil
end

#[]=(key, val) ⇒ Object

:nodoc:


20
21
22
23
24
25
26
# File 'lib/occi/core/helpers/instance_attributes_accessor.rb', line 20

def []=(key, val)
  unless attribute?(key)
    raise Occi::Core::Errors::AttributeDefinitionError, 'Attribute named ' \
          "#{key.inspect} has not been defined for #{self}"
  end
  attributes[key].value = val
end

#attribute?(key) ⇒ Boolean

:nodoc:


15
16
17
# File 'lib/occi/core/helpers/instance_attributes_accessor.rb', line 15

def attribute?(key)
  !attributes[key].nil?
end