Module: Backends::Helpers::ExtensionsHelper

Included in:
Dummy::Base, Ec2::Base, Opennebula::Base
Defined in:
lib/backends/helpers/extensions_helper.rb

Overview

Provides helpers for loading model extensions from JSON files containing OCCI mixins and actions.

Instance Method Summary collapse

Instance Method Details

#read_extensions(backend_type, model_extensions_dir) ⇒ Occi::Collection

Returns a collection of custom mixins introduced (and specific for) the enabled backend. Only mixins and actions are allowed.


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/backends/helpers/extensions_helper.rb', line 12

def read_extensions(backend_type, model_extensions_dir)
  fail Backends::Errors::ResourceRetrievalError, 'Cannot retrieve extensions ' \
                                                 'for an unspecified backend type!' if backend_type.blank?
  fail Backends::Errors::ResourceRetrievalError, 'Cannot retrieve extensions ' \
                                             'w/o the extensions dir!' if model_extensions_dir.blank?

  collection = Occi::Collection.new
  path = File.join(model_extensions_dir, backend_type, '*.json')

  Dir.glob(path).each do |json_file|
    collection.merge! read_from_json(json_file) if File.readable?(json_file)
  end

  collection
end