class Occi::Core::Mixin

Attributes

actions[RW]
applies[RW]
depends[RW]
entities[RW]

Public Class Methods

new(scheme='http://schemas.ogf.org/occi/core click to toggle source

@param [String] scheme @param [String] term @param [String] title @param [Occi::Core::Attributes,Hash,NilClass] attributes @param [Occi::Core::Categories,Hash,NilClass] depends @param [Occi::Core::Actions,Hash,NilClass] actions @param [String] location @param [Occi::Core::Kinds, NilClass] applies

Calls superclass method Occi::Core::Category.new
# File lib/occi/core/mixin.rb, line 15
def initialize(scheme='http://schemas.ogf.org/occi/core#',
    term='mixin',
    title=nil,
    attributes=Occi::Core::Attributes.new,
    depends=Occi::Core::Dependencies.new,
    actions=Occi::Core::Actions.new,
    location='',
    applies=Occi::Core::Kinds.new)

  super(scheme, term, title, attributes)
  @depends = Occi::Core::Dependencies.new depends
  @actions = Occi::Core::Actions.new actions
  @entities = Occi::Core::Entities.new
  @location = location.blank? ? "/mixin/#{term}/" : URI.parse(location).path
  @applies = Occi::Core::Kinds.new applies
end

Public Instance Methods

as_json(options={}) click to toggle source

@param [Hash] options @return [Hashie::Mash] json representation

Calls superclass method Occi::Core::Category#as_json
# File lib/occi/core/mixin.rb, line 58
def as_json(options={})
  mixin = Hashie::Mash.new
  mixin.depends = self.depends.to_a.collect { |m| m.type_identifier } if self.depends.any?
  mixin.applies = self.applies.to_a.collect { |m| m.type_identifier } if self.applies.any?
  mixin.related = self.related.to_a.collect { |m| m.type_identifier } if self.related.any?
  mixin.actions = self.actions if self.actions.any?
  mixin.location = self.location if self.location
  mixin.merge! super
  mixin
end
location() click to toggle source
# File lib/occi/core/mixin.rb, line 48
def location
  @location ? @location.clone : nil
end
location=(location) click to toggle source

set location attribute of kind @param [String] location

# File lib/occi/core/mixin.rb, line 42
def location=(location)
  location = URI.parse(location).path if location
  raise "Mixin locations must end with a slash!" unless location.blank? || location =~ /^\/\S+\/$/
  @location = location
end
to_string() click to toggle source

@return [String] text representation

Calls superclass method Occi::Core::Category#to_string
# File lib/occi/core/mixin.rb, line 70
def to_string
  string = super
  string << ";rel=#{self.related.join(' ').inspect}" if self.related.any?
  string << ";location=#{self.location.inspect}"
  string << self.attributes.to_string_short
  string << ";actions=#{self.actions.join(' ').inspect}" if self.actions.any?
  string
end