Class: Miasma::Models::Orchestration::Stack::Resource

Inherits:
Types::Model show all
Includes:
Utils::Immutable
Defined in:
lib/miasma/models/orchestration/resource.rb

Overview

Stack resource

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Resource) initialize(stack, args = {})

Returns a new instance of Resource



21
22
23
24
# File 'lib/miasma/models/orchestration/resource.rb', line 21

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

Instance Attribute Details

- (Miasma::Types::Api) api (readonly) Originally defined in class Types::Model

Returns underlying service API

Returns:

- (Object) stack (readonly)

Returns the value of attribute stack



19
20
21
# File 'lib/miasma/models/orchestration/resource.rb', line 19

def stack
  @stack
end

Instance Method Details

- (Miasma::Types::Model) dereference

Returns provides mapped resource class

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/miasma/models/orchestration/resource.rb', line 27

def dereference
  # Insert provider to namespace
  provider_const = self.class.name.split('::').insert(3, Utils.camel(api.provider))
  provider_const.slice!(-2, 2)
  # Insert mapping constant name and fetch
 const = provider_const.push(:RESOURCE_MAPPING).inject(Object) do |memo, konst|
    res = memo.const_get(konst)
    break unless res
    res
  end
  unless(const[self.type])
    raise KeyError.new "Failed to locate requested mapping! (`#{self.type}`)"
  end
  const[self.type]
end

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

Provide proper instance from resource



46
47
48
49
# File 'lib/miasma/models/orchestration/resource.rb', line 46

def expand
  info = dereference
  api.api_for(info[:api]).send(info[:collection]).get(self.id)
end

- (Object) frozen_valid_state(*args) Originally defined in module Utils::Immutable

Freezes underlying data hash

- (Object) perform_reload

Proxy reload action up to the API



53
54
55
# File 'lib/miasma/models/orchestration/resource.rb', line 53

def perform_reload
  api.resource_reload(self)
end

- (Object) save Originally defined in module Utils::Immutable

- (TrueClass, FalseClass) within?(api, collection)

Resource is within the collection on the api

Parameters:

  • api (Symbol)

    api type (:compute, :auto_scale, etc)

  • collection (Symbol)

    collection within api (:servers, :groups, etc)

Returns:

  • (TrueClass, FalseClass)


62
63
64
65
66
67
68
69
70
# File 'lib/miasma/models/orchestration/resource.rb', line 62

def within?(api, collection)
  begin
    info = dereference
    info[:api] == api &&
      info[:collection] == collection
  rescue KeyError
    false
  end
end