Class: CFoundry::Service

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

Overview

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

Goes 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) ⇒ Service

Create a Service object.

You’ll usually call Client#service instead.



33
34
35
36
37
# File 'lib/cfoundry/service.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/service.rb', line 28

def meta
  @meta
end

#nameObject (readonly)

Service name.



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

def name
  @name
end

#propertiesObject

Service properties.



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

def properties
  @properties
end

#tierObject

Service tier. Usually “free” for now.



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

def tier
  @tier
end

#typeObject

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



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

def type
  @type
end

#vendorObject

Service vendor (redis, mysql, etc.).



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

def vendor
  @vendor
end

#versionObject

Service version.



19
20
21
# File 'lib/cfoundry/service.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.



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

def create!
  @client.rest.create_service(@manifest.merge("name" => @name))
end

#createdObject

Timestamp of when the service was created.



64
65
66
# File 'lib/cfoundry/service.rb', line 64

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

#delete!Object

Delete the service from the target.



44
45
46
# File 'lib/cfoundry/service.rb', line 44

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

#exists?Boolean

Check if the service exists on the target.

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'lib/cfoundry/service.rb', line 56

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

#inspectObject

:nodoc:



39
40
41
# File 'lib/cfoundry/service.rb', line 39

def inspect # :nodoc:
  "#<Service '#@name'>"
end

#updatedObject

Timestamp of when the service was last updated.



69
70
71
# File 'lib/cfoundry/service.rb', line 69

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