Class: Mystro::Cloud::Fog::Connect

Inherits:
Connect
  • Object
show all
Defined in:
lib/mystro/cloud/connect/fog.rb

Direct Known Subclasses

Aws::Connect, Dynect::Connect

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Connect

#config

Instance Method Summary collapse

Methods inherited from Connect

#decode, #encode

Constructor Details

#initialize(options, config = nil) ⇒ Connect

Returns a new instance of Connect.



10
11
12
13
14
15
# File 'lib/mystro/cloud/connect/fog.rb', line 10

def initialize(options, config=nil)
  @options = options
  @config = config
  @service = nil
  @fog = nil
end

Class Attribute Details

.collectionObject (readonly)

Returns the value of attribute collection.



54
55
56
# File 'lib/mystro/cloud/connect/fog.rb', line 54

def collection
  @collection
end

.modelObject (readonly)

Returns the value of attribute model.



54
55
56
# File 'lib/mystro/cloud/connect/fog.rb', line 54

def model
  @model
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/mystro/cloud/connect/fog.rb', line 8

def options
  @options
end

Instance Method Details

#allObject



17
18
19
# File 'lib/mystro/cloud/connect/fog.rb', line 17

def all
  decode(service.send(collection).all)
end

#collectionObject



41
42
43
# File 'lib/mystro/cloud/connect/fog.rb', line 41

def collection
  @collection ||= self.class.collection
end

#create(model) ⇒ Object



27
28
29
30
31
# File 'lib/mystro/cloud/connect/fog.rb', line 27

def create(model)
  enc = encode(model)
  o = service.send(collection).create(enc)
  decode(o)
end

#destroy(model) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/mystro/cloud/connect/fog.rb', line 33

def destroy(model)
  Mystro::Log.debug "destroy: #{model.inspect}"
  raise "destroy argument should be Mystro::Cloud::Model: #{model.inspect}" unless model.is_a?(Mystro::Cloud::Model)
  e = service.send(collection).get(model.identity)
  raise "object not found for id: #{model.identity}" unless e
  e.destroy
end

#find(id) ⇒ Object



21
22
23
24
25
# File 'lib/mystro/cloud/connect/fog.rb', line 21

def find(id)
  i = service.send(collection).get(id)
  raise Mystro::Cloud::NotFound, "could not find #{id}" unless i
  decode(i)
end

#serviceObject



45
46
47
48
49
50
51
# File 'lib/mystro/cloud/connect/fog.rb', line 45

def service
  @service ||= begin
    model = self.class.model
    s = model.constantize.new(@options)
    s
  end
end