Class: Miasma::Types::ThinModel

Inherits:
Data
  • Object
show all
Defined in:
lib/miasma/types/thin_model.rb

Overview

Base data container

Direct Known Subclasses

Models::AutoScale::Group::Balancer, Models::AutoScale::Group::Server, Models::Compute::Server::Network, Models::LoadBalancer::Balancer::Server

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ThinModel) initialize(api, args = {})

Build new instance

Parameters:



40
41
42
43
# File 'lib/miasma/types/thin_model.rb', line 40

def initialize(api, args={})
  @api = api
  super args
end

Instance Attribute Details

- (Miasma::Types::Api) api (readonly)

Returns service API

Returns:



34
35
36
# File 'lib/miasma/types/thin_model.rb', line 34

def api
  @api
end

Class Method Details

+ (Class) model(klass = nil)

Get/Set fat model

Parameters:

  • klass (Class) (defaults to: nil)

    fat model class

Returns:

  • (Class)

    fat model class



15
16
17
18
19
20
21
22
23
24
# File 'lib/miasma/types/thin_model.rb', line 15

def model(klass=nil)
  if(klass)
    unless(klass.ancestors.include?(Miasma::Types::Model))
      raise TypeError.new "Expecting `Miasma::Types::Model` subclass! (got #{klass})"
    else
      self._model = klass
    end
  end
  self._model
end

Instance Method Details

- (Miasma::Types::Model) expand Also known as: instance

Build fat model instance



66
67
68
69
70
# File 'lib/miasma/types/thin_model.rb', line 66

def expand
  inst = model.new(api)
  inst.data[:id] = self.id
  inst.reload
end

- (Class) model

Note:

will deconstruct namespace and rebuild using provider

Associated model class

Returns:

  • (Class)

    of type Miasma::Types::Model



55
56
57
58
59
60
61
# File 'lib/miasma/types/thin_model.rb', line 55

def model
  if(self.class.model)
    self.class.model
  else
    raise NotImplementedError.new "No associated model for this thin model type (#{self.class})"
  end
end

- (FalseClass) persisted?

Note:

thin models are always false

Returns:

  • (FalseClass)


47
48
49
# File 'lib/miasma/types/thin_model.rb', line 47

def persisted?
  false
end