Class: CFoundry::V2::App

Inherits:
Model
  • Object
show all
Defined in:
lib/cfoundry/v2/app.rb

Overview

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

Does not guarantee that the app exists; used for both app 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

Attributes inherited from Model

#id

Instance Method Summary collapse

Methods inherited from Model

#==, attribute, #create!, defaults, #delete!, #exists?, #initialize, #inspect, #manifest, #object_name, to_many, to_one, #update!

Constructor Details

This class inherits a constructor from CFoundry::V2::Model

Instance Method Details

#bind(*service_names) ⇒ Object

Bind services to application.



124
125
126
# File 'lib/cfoundry/v2/app.rb', line 124

def bind(*service_names)
  update!(:services => services + service_names)
end

#debug_modeObject Also known as: console

TODO v2



56
57
58
# File 'lib/cfoundry/v2/app.rb', line 56

def debug_mode # TODO v2
  nil
end

#envObject



44
45
46
47
48
# File 'lib/cfoundry/v2/app.rb', line 44

def env
  @env ||= CFoundry::ChattyHash.new(
    method(:env=),
    JSON.parse(environment_json))
end

#env=(hash) ⇒ Object



50
51
52
53
54
# File 'lib/cfoundry/v2/app.rb', line 50

def env=(hash)
  @env = hash
  @diff["environment_json"] = hash
  hash
end

#healthObject

Determine application health.

If all instances are running, returns “RUNNING”. If only some are started, returns the precentage of them that are healthy.

Otherwise, returns application’s status.



98
99
100
# File 'lib/cfoundry/v2/app.rb', line 98

def health
  state
end

#healthy?Boolean Also known as: running?

Check that all application instances are running.

Returns:

  • (Boolean)


103
104
105
106
107
# File 'lib/cfoundry/v2/app.rb', line 103

def healthy?
  # invalidate cache so the check is fresh
  @manifest = nil
  health == "RUNNING"
end

#restart!Object

Restart the application.



87
88
89
90
# File 'lib/cfoundry/v2/app.rb', line 87

def restart!
  stop!
  start!
end

#start!Object

Start the application.



82
83
84
# File 'lib/cfoundry/v2/app.rb', line 82

def start!
  update! :state => "STARTED"
end

#started?Boolean

Is the application started?

Note that this does not imply that all instances are running. See #healthy?

Returns:

  • (Boolean)


119
120
121
# File 'lib/cfoundry/v2/app.rb', line 119

def started?
  state == "STARTED"
end

#stop!Object

Stop the application.



77
78
79
# File 'lib/cfoundry/v2/app.rb', line 77

def stop!
  update! :state => "STOPPED"
end

#stopped?Boolean

Is the application stopped?

Returns:

  • (Boolean)


111
112
113
# File 'lib/cfoundry/v2/app.rb', line 111

def stopped?
  state == "STOPPED"
end

#unbind(*service_names) ⇒ Object

Unbind services from application.



129
130
131
132
133
134
# File 'lib/cfoundry/v2/app.rb', line 129

def unbind(*service_names)
  update!(:services =>
            services.reject { |s|
              service_names.include?(s)
            })
end

#uriObject Also known as: url



71
72
73
# File 'lib/cfoundry/v2/app.rb', line 71

def uri
  uris[0]
end

#urisObject Also known as: urls

TODO v2



61
62
63
# File 'lib/cfoundry/v2/app.rb', line 61

def uris # TODO v2
  []
end

#uris=(x) ⇒ Object Also known as: urls=



66
67
68
# File 'lib/cfoundry/v2/app.rb', line 66

def uris=(x)
  nil
end