Class: Boxcutter::LoadBalancer::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/boxcutter/load_balancer/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, attrs) ⇒ Application

Returns a new instance of Application.



15
16
17
18
# File 'lib/boxcutter/load_balancer/application.rb', line 15

def initialize(api, attrs)
  @api = api
  @attrs = attrs
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



13
14
15
# File 'lib/boxcutter/load_balancer/application.rb', line 13

def api
  @api
end

Class Method Details

.allObject



3
4
5
6
# File 'lib/boxcutter/load_balancer/application.rb', line 3

def self.all
  api = ::Boxcutter::Api.new(*ENV['BBG_API_KEY'].split(':'))
  api.applications.map {|attrs| new(api, attrs)}
end

.find(id, api = nil) ⇒ Object



8
9
10
11
# File 'lib/boxcutter/load_balancer/application.rb', line 8

def self.find(id, api = nil)
  api = ::Boxcutter::Api.new(*ENV['BBG_API_KEY'].split(':')) if api.nil?
  new(api, api.application(id))
end

Instance Method Details

#idObject



24
25
26
# File 'lib/boxcutter/load_balancer/application.rb', line 24

def id
  @attrs["id"]
end

#ip_v4Object



28
29
30
# File 'lib/boxcutter/load_balancer/application.rb', line 28

def ip_v4
  @attrs["ip_v4"]
end

#ip_v6Object



32
33
34
# File 'lib/boxcutter/load_balancer/application.rb', line 32

def ip_v6
  @attrs["ip_v6"]
end

#nameObject



36
37
38
# File 'lib/boxcutter/load_balancer/application.rb', line 36

def name
  @attrs["name"]
end

#servicesObject



40
41
42
# File 'lib/boxcutter/load_balancer/application.rb', line 40

def services
  api.services(id).map {|attrs| Service.new(api, attrs)}
end

#to_sObject



20
21
22
# File 'lib/boxcutter/load_balancer/application.rb', line 20

def to_s
  "#<Application id:'#{id}' name:'#{name}' ip_v4:'#{ip_v4}' ip_v6:'#{ip_v6}'>"
end