Class: CFoundry::V2::AppInstance

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name, app_guid, id, client, manifest = {}) ⇒ AppInstance

Returns a new instance of AppInstance.



11
12
13
14
15
16
17
# File 'lib/cfoundry/v2/app_instance.rb', line 11

def initialize(app_name, app_guid, id, client, manifest = {})
  @app_name = app_name
  @app_guid = app_guid
  @id = id
  @client = client
  @manifest = manifest
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/cfoundry/v2/app_instance.rb', line 3

def id
  @id
end

Class Method Details

.for_app(name, guid, client) ⇒ Object



5
6
7
8
9
# File 'lib/cfoundry/v2/app_instance.rb', line 5

def self.for_app(name, guid, client)
  client.base.instances(guid).collect do |i, m|
    AppInstance.new(name, guid, i.to_s, client, m)
  end
end

Instance Method Details

#consoleObject



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

def console
  return unless @manifest[:console_ip] and @manifest[:console_port]

  {:ip => @manifest[:console_ip],
    :port => @manifest[:console_port]
  }
end

#debuggerObject



35
36
37
38
39
40
41
# File 'lib/cfoundry/v2/app_instance.rb', line 35

def debugger
  return unless @manifest[:debug_ip] and @manifest[:debug_port]

  {:ip => @manifest[:debug_ip],
    :port => @manifest[:debug_port]
  }
end

#file(*path) ⇒ Object



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

def file(*path)
  @client.base.files(@app_guid, @id, *path)
end

#files(*path) ⇒ Object



60
61
62
63
64
# File 'lib/cfoundry/v2/app_instance.rb', line 60

def files(*path)
  @client.base.files(@app_guid, @id, *path).split("\n").collect do |entry|
    path + [entry.split(/\s+/, 2)[0]]
  end
end

#healthy?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
# File 'lib/cfoundry/v2/app_instance.rb', line 51

def healthy?
  case state
  when "STARTING", "RUNNING"
    true
  when "DOWN", "FLAPPING"
    false
  end
end

#inspectObject



19
20
21
# File 'lib/cfoundry/v2/app_instance.rb', line 19

def inspect
  "#<App::Instance '#{@app_name}' \##@id>"
end

#sinceObject



29
30
31
32
33
# File 'lib/cfoundry/v2/app_instance.rb', line 29

def since
  if since = @manifest[:since]
    Time.at(@manifest[:since])
  end
end

#stateObject Also known as: status



23
24
25
# File 'lib/cfoundry/v2/app_instance.rb', line 23

def state
  @manifest[:state]
end

#stream_file(*path, &blk) ⇒ Object



70
71
72
# File 'lib/cfoundry/v2/app_instance.rb', line 70

def stream_file(*path, &blk)
  @client.base.stream_file(@app_guid, @id, *path, &blk)
end