Module: OCCI::Registry

Defined in:
lib/occi/registry.rb

Overview


Constant Summary

@@categories =
{}
@@locations =
{}

Class Method Summary collapse

Class Method Details

.get(filter = []) ⇒ Hashie::Mash

Return all categories from category registry. If filter is present, return only the categories specified by filter

Parameters:

  • filter (Hashie:Hash) (defaults to: [])

Returns:

  • (Hashie::Mash)

    collection



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/occi/registry.rb', line 69

def self.get(filter = [])
  collection = Hashie::Mash.new({:kinds => [], :mixins => [], :actions => []})
  filter.each do |cat|
    category = get_by_id(cat.type_identifier)
    collection.kinds << category if category.kind_of?(OCCI::Core::Kind)
    collection.mixins << category if category.kind_of?(OCCI::Core::Mixin)
    collection.actions << category if category.kind_of?(OCCI::Core::Action)
  end
  if filter.empty?
    @@categories.each_value do |category|
      collection.kinds << category if category.kind_of? OCCI::Core::Kind
      collection.mixins << category if category.kind_of? OCCI::Core::Mixin
      collection.actions << category if category.kind_of? OCCI::Core::Action
    end
  end
  return collection
end

.get_by_id(id) ⇒ Object

Returns the category corresponding to a given type identifier

Parameters:

  • type (URI)

    identifier of a category



53
54
55
# File 'lib/occi/registry.rb', line 53

def self.get_by_id(id)
  @@categories.fetch(id) { OCCI::Log.debug("Category with id #{id} not found"); nil }
end

.get_by_location(location) ⇒ Object

Returns the category corresponding to a given location

Parameters:

  • Location (URI)

    of a category



60
61
62
63
# File 'lib/occi/registry.rb', line 60

def self.get_by_location(location)
  id = @@locations.fetch(location) { OCCI::Log.debug("Category with location #{location} not found"); nil }
  self.get_by_id(id)
end

.register(category) ⇒ Object




37
38
39
40
41
# File 'lib/occi/registry.rb', line 37

def self.register(category)
  OCCI::Log.debug("### Registering category #{category.type_identifier}")
  @@categories[category.type_identifier] = category
  @@locations[category.location] = category.type_identifier unless category.kind_of?(OCCI::Core::Action)
end

.resetObject



32
33
34
# File 'lib/occi/registry.rb', line 32

def self.reset()
  @@categories.each_value.each {|category| category.entities = [] if category.entities}
end

.unregister(category) ⇒ Object




44
45
46
47
48
# File 'lib/occi/registry.rb', line 44

def self.unregister(category)
  OCCI::Log.debug("### Unregistering category #{category.type_identifier}")
  @@categories.delete(category.type_identifier)
  @@locations.delete(category.location) unless category.kind_of?(OCCI :Core::Action)
end