module Deltacloud::CollectionHelper

Public Instance Methods

collection(name) click to toggle source
# File lib/deltacloud/helpers/collection_helper.rb, line 60
def collection(name)
  collections.find { |c| c.collection_name == name }
end
collection_names() click to toggle source
# File lib/deltacloud/helpers/collection_helper.rb, line 52
def collection_names
  collections.map { |c| c.collection_name }
end
collections() click to toggle source
# File lib/deltacloud/helpers/collection_helper.rb, line 56
def collections
  @collections ||= []
end
load_collections_for(frontend, opts={}) click to toggle source

This method will load all collections from given directory.

Syntax:

#load_collections_for :cimi, :from => DIRECTORY

# File lib/deltacloud/helpers/collection_helper.rb, line 78
def load_collections_for(frontend, opts={})
  frontend_module = (frontend == :cimi) ? CIMI : Deltacloud
  Dir[File.join(opts[:from], '*.rb')].each do |collection|
    base_collection_name = File.basename(collection).gsub('.rb', '')
    next if base_collection_name == 'base'
    require collection
    collection_module_class = frontend_module::Collections.const_get(
      base_collection_name.camelize
    )
    modules(frontend) << collection_module_class
    if collection_module_class.collections.nil?
      warn "WARNING: #{collection_module_class} does not include any collections"
    else
      collection_module_class.collections.each do |c|
        if frontend_module.collection_exists?(c)
          raise "ERROR: Collection already registred #{c}"
        end
        frontend_module.collections << c
      end
    end
  end
end
modules(frontend) click to toggle source
# File lib/deltacloud/helpers/collection_helper.rb, line 65
def modules(frontend)
  case frontend
    when :cimi then @cimi_modules ||= []
    when :deltacloud then @deltacloud_modules ||= []
  end
end