Class: CFoundry::V1::ServiceInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/cfoundry/v1/service_instance.rb

Overview

Class for representing a user’s service on a given target (via Client).

Does not guarantee that the service exists; used for both service creation and retrieval, as the attributes are all lazily retrieved. Setting attributes does not perform any requests; use #update! to commit your changes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, client, manifest = nil) ⇒ ServiceInstance

Create a Service object.

You’ll usually call Client#service instead.



33
34
35
36
37
# File 'lib/cfoundry/v1/service_instance.rb', line 33

def initialize(name, client, manifest = nil)
  @name = name
  @client = client
  @manifest = manifest
end

Instance Attribute Details

#metaObject

Service metadata.



28
29
30
# File 'lib/cfoundry/v1/service_instance.rb', line 28

def meta
  @meta
end

#nameObject

Service name.



10
11
12
# File 'lib/cfoundry/v1/service_instance.rb', line 10

def name
  @name
end

#propertiesObject

Service properties.



22
23
24
# File 'lib/cfoundry/v1/service_instance.rb', line 22

def properties
  @properties
end

#tierObject

Service tier. Usually “free” for now.



25
26
27
# File 'lib/cfoundry/v1/service_instance.rb', line 25

def tier
  @tier
end

#typeObject

Service type (e.g. key-value).



13
14
15
# File 'lib/cfoundry/v1/service_instance.rb', line 13

def type
  @type
end

#vendorObject

Service vendor (redis, mysql, etc.).



16
17
18
# File 'lib/cfoundry/v1/service_instance.rb', line 16

def vendor
  @vendor
end

#versionObject

Service version.



19
20
21
# File 'lib/cfoundry/v1/service_instance.rb', line 19

def version
  @version
end

Instance Method Details

#create!Object

Create the service on the target.

Call this after setting the various attributes.



58
59
60
# File 'lib/cfoundry/v1/service_instance.rb', line 58

def create!
  @client.base.create_service(@manifest.merge(:name => @name))
end

#createdObject

Timestamp of when the service was created.



71
72
73
# File 'lib/cfoundry/v1/service_instance.rb', line 71

def created
  Time.at(meta[:created])
end

#delete!Object

Delete the service from the target.



51
52
53
# File 'lib/cfoundry/v1/service_instance.rb', line 51

def delete!
  @client.base.delete_service(@name)
end

#eql?(other) ⇒ Boolean Also known as: ==

Basic equality test by name.

Returns:

  • (Boolean)


45
46
47
# File 'lib/cfoundry/v1/service_instance.rb', line 45

def eql?(other)
  other.is_a?(self.class) && other.name == @name
end

#exists?Boolean

Check if the service exists on the target.

Returns:

  • (Boolean)


63
64
65
66
67
68
# File 'lib/cfoundry/v1/service_instance.rb', line 63

def exists?
  @client.base.service(@name)
  true
rescue CFoundry::NotFound
  false
end

#inspectObject

Show string representing the service.



40
41
42
# File 'lib/cfoundry/v1/service_instance.rb', line 40

def inspect
  "#<ServiceInstance '#@name'>"
end

#invalidate!Object



80
81
82
# File 'lib/cfoundry/v1/service_instance.rb', line 80

def invalidate!
  @manifest = nil
end

#updatedObject

Timestamp of when the service was last updated.



76
77
78
# File 'lib/cfoundry/v1/service_instance.rb', line 76

def updated
  Time.at(meta[:updated])
end