Class: OcciModel

Inherits:
Object
  • Object
show all
Defined in:
app/models/occi_model.rb

Overview

Provides access to Occi::Model instances with added functionality:

  • Wraps Occi::Model instantiation

  • Automatically performs necessary registrations

  • Helps with filtering

Class Method Summary collapse

Class Method Details

.get(backend, filter = nil) ⇒ Occi::Model

Instantiates Occi::Model and registers necessary extensions.

Examples:

backend = Backend.new
OcciModel.get(backend) #=> #<Occi::Model>

Parameters:

  • backend (Backend)

    instance of the currently active backend

  • filter (Occi::Collection, Occi::Core::Category, String) (defaults to: nil)

    filtration parameters

Returns:

  • (Occi::Model)

    an Occi::Model instance ready to use


17
18
19
20
# 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

.get_filtered(backend, filter) ⇒ Occi::Model

Instantiates Occi::Model, registers necessary extensions and filters its content according to `filter`.

Examples:

backend = Backend.new
OcciModel.get_filtered(backend, collection) #=> Occi::Model

Parameters:

  • backend (Backend)

    instance of the currently active backend

  • filter (Occi::Collection, Occi::Core::Category, String)

    filtration parameters

Returns:

  • (Occi::Model)

    an Occi::Model instance ready to use


32
33
34
35
36
37
38
39
40
# 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