class OcciModel
Provides access to Occi::Model instances with added functionality:
-
Wraps Occi::Model instantiation
-
Automatically performs necessary registrations
-
Helps with filtering
Public Class Methods
Instantiates Occi::Model and registers necessary extensions.
@example
backend = Backend.new OcciModel.get(backend) #=> #<Occi::Model>
@param backend [Backend] instance of the currently active backend @param filter [Occi::Collection, Occi::Core::Category, String] filtration parameters @return [Occi::Model] an Occi::Model instance ready to use
# File app/models/occi_model.rb, line 17 def get(backend, filter = nil) fail ArgumentError, 'Backend is a mandatory argument!' unless backend filter ? get_filtered(backend, filter) : model_factory(backend) end
Instantiates Occi::Model, registers necessary extensions and filters its content according to `filter`.
@example
backend = Backend.new OcciModel.get_filtered(backend, collection) #=> Occi::Model
@param backend [Backend] instance of the currently active backend @param filter [Occi::Collection, Occi::Core::Category, String] filtration parameters @return [Occi::Model] an Occi::Model instance ready to use
# File app/models/occi_model.rb, line 32 def get_filtered(backend, filter) fail ArgumentError, 'Backend is a mandatory argument!' unless backend fail ArgumentError, 'Filter is a mandatory argument!' unless filter Rails.logger.debug "[#{self}] Building OCCI model with filter: #{filter.inspect}" single_filter = filter.kinds.first if filter.respond_to?(:kinds) single_filter = filter.mixins.first if single_filter.blank? && filter.respond_to?(:mixins) model_factory(backend).get(single_filter) end