Class: Occi::Core::Kind

Inherits:
Category show all
Includes:
Helpers::Locatable
Defined in:
lib/occi/core/kind.rb

Overview

Defines the classification system of the OCCI Core Model. The `Kind` instance represents the type identification mechanism for all `Entity` instances present in the model.

Examples:

Kind.new schema: 'http://schemas.ogf.org/occi/infrastructure#',
         term: 'compute',
         title: 'Compute'

Author:

Constant Summary

Constants included from Helpers::IdentifierValidator

Helpers::IdentifierValidator::PROHIBITED_SCHEMA_CHARS, Helpers::IdentifierValidator::REGEXP_TERM

Constants included from Helpers::Renderable

Helpers::Renderable::RENDERER_FACTORY_CLASS

Instance Attribute Summary collapse

Attributes inherited from Category

#attributes, #identifier, #schema, #term, #title

Instance Method Summary collapse

Methods inherited from Category

#==, #eql?, #hash, #initialize, #to_s, #valid!, #valid?

Methods included from Helpers::YamlSummoner

#from_yaml, #needs_dereferencing?

Methods included from Helpers::IdentifierValidator

#prohibited_chars!, #valid_identifier!, #valid_identifier?, #valid_schema!, #valid_schema?, #valid_term!, #valid_term?, #valid_uri!

Methods included from Helpers::AttributesAccessor

#[], #[]=

Methods included from Helpers::Renderable

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

Constructor Details

This class inherits a constructor from Occi::Core::Category

Instance Attribute Details

#actionsSet

list of `Action` instances applicable to this `Kind`

Returns:

  • (Set)

    the current value of actions


17
18
19
# File 'lib/occi/core/kind.rb', line 17

def actions
  @actions
end

#locationURI

protocol agnostic location of this `Kind` instance

Returns:

  • (URI)

    the current value of location


17
18
19
# File 'lib/occi/core/kind.rb', line 17

def location
  @location
end

#parentKind

previous `Kind` in the OCCI kind hierarchy

Returns:

  • (Kind)

    the current value of parent


17
18
19
# File 'lib/occi/core/kind.rb', line 17

def parent
  @parent
end

Instance Method Details

For compatibility reasons, returns the parent instance of this `Kind` in an `Array`. For hierarchy roots, returns only an empty `Array`.

Returns:

  • (Array)

    a list containing the parent `Kind` instance, if any


62
63
64
# File 'lib/occi/core/kind.rb', line 62

def directly_related
  [parent].compact
end

#directly_related?(kind) ⇒ TrueClass, FalseClass

Checks whether the given `Kind` instance is related to this instance. The given `Kind` instance must be the immediate predecessor (see `#directly_related`) to succeed.

Parameters:

  • kind (Kind)

    suspected predecessor

Returns:


43
44
45
46
47
# File 'lib/occi/core/kind.rb', line 43

def directly_related?(kind)
  return false unless kind
  return true if kind == self
  directly_related.include? kind
end

#hierarchy_root?TrueClass, FalseClass

Indicates whether this instance is the base of the OCCI kind hierarchy, i.e. there are no predecessors. This helps to calculate the relationship status correctly, see `#related`.

Returns:


71
72
73
# File 'lib/occi/core/kind.rb', line 71

def hierarchy_root?
  parent.nil?
end

Transitively returns all predecessors of this `Kind` instance in a multi-element `Array`.

Returns:

  • (Array)

    list containing predecessors of this `Kind` instance


53
54
55
56
# File 'lib/occi/core/kind.rb', line 53

def related
  return directly_related if hierarchy_root?
  [parent, parent.related].flatten.compact
end

#related?(kind) ⇒ TrueClass, FalseClass

Checks whether the given `Kind` instance is related to this instance. The given `Kind` instance must be included in the list of predecessors (see `#related`) to succeed.

Parameters:

  • kind (Kind)

    suspected predecessor

Returns:


30
31
32
33
34
# File 'lib/occi/core/kind.rb', line 30

def related?(kind)
  return false unless kind
  return true if kind == self
  related.include? kind
end