Class: Miasma::Types::ThinModel

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

Overview

Base data container

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

from_json, #from_json, #to_json

Methods included from Utils::Lazy

included

Constructor Details

#initialize(api, args = {}) ⇒ ThinModel

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

#apiMiasma::Types::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

.model(klass = nil) ⇒ Class

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

#expandMiasma::Types::Model 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

#modelClass

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

#persisted?FalseClass

Note:

thin models are always false

Returns:

  • (FalseClass)


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

def persisted?
  false
end