Module: Deltacloud::CollectionHelper

Included in:
CIMI::Collections, Collections
Defined in:
lib/deltacloud/helpers/collection_helper.rb

Instance Method Summary collapse

Instance Method Details

#collection(name) ⇒ Object



60
61
62
# File 'lib/deltacloud/helpers/collection_helper.rb', line 60

def collection(name)
  collections.find { |c| c.collection_name == name }
end

#collection_namesObject



52
53
54
# File 'lib/deltacloud/helpers/collection_helper.rb', line 52

def collection_names
  collections.map { |c| c.collection_name }
end

#collectionsObject



56
57
58
# File 'lib/deltacloud/helpers/collection_helper.rb', line 56

def collections
  @collections ||= []
end

#load_collections_for(frontend, opts = {}) ⇒ Object

This method will load all collections from given directory.

Syntax:

load_collections_for :cimi, :from => DIRECTORY



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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) ⇒ Object



65
66
67
68
69
70
# 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