Class: Kong::Target
- Inherits:
-
Object
show all
- Includes:
- Base
- Defined in:
- lib/kong/target.rb
Constant Summary
collapse
- ATTRIBUTE_NAMES =
%w(id upstream_id target weight).freeze
- API_END_POINT =
'/targets/'.freeze
Instance Attribute Summary
Attributes included from Base
#api_end_point, #attributes
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Base
#client, #create, #delete, #get, included, #method_missing, #new?, #respond_to?
Constructor Details
#initialize(attributes = {}) ⇒ Target
Returns a new instance of Target.
16
17
18
19
|
# File 'lib/kong/target.rb', line 16
def initialize(attributes = {})
super(attributes)
raise ArgumentError, 'You must specify an upstream_id' unless self.upstream_id
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Kong::Base
Class Method Details
.find(id) ⇒ Object
8
9
10
|
# File 'lib/kong/target.rb', line 8
def self.find(id)
raise NotImplementedError, 'Kong does not support direct access to targets, you must go via an upstream'
end
|
.list(params = {}) ⇒ Object
12
13
14
|
# File 'lib/kong/target.rb', line 12
def self.list(params = {})
raise NotImplementedError, 'Kong does not support direct access to targets, you must go via an upstream'
end
|
Instance Method Details
#active? ⇒ Boolean
21
22
23
|
# File 'lib/kong/target.rb', line 21
def active?
self.weight > 0
end
|
#create_or_update ⇒ Object
29
30
31
|
# File 'lib/kong/target.rb', line 29
def create_or_update
raise NotImplementedError, 'Kong does not support updating targets, you must delete and re-create'
end
|
#save ⇒ Object
25
26
27
|
# File 'lib/kong/target.rb', line 25
def save
create
end
|
#update ⇒ Object
33
34
35
|
# File 'lib/kong/target.rb', line 33
def update
raise NotImplementedError, 'Kong does not support updating targets, you must delete and re-create'
end
|
43
44
45
|
# File 'lib/kong/target.rb', line 43
def upstream
@upstream ||= Upstream.find(self.upstream_id)
end
|
#upstream=(upstream) ⇒ Object
49
50
51
52
|
# File 'lib/kong/target.rb', line 49
def upstream=(upstream)
@upstream = upstream
self.upstream_id = upstream.id
end
|
#upstream_id=(id) ⇒ Object
56
57
58
59
|
# File 'lib/kong/target.rb', line 56
def upstream_id=(id)
super(id)
use_upstream_end_point
end
|
#use_upstream_end_point ⇒ Object
37
38
39
|
# File 'lib/kong/target.rb', line 37
def use_upstream_end_point
self.api_end_point = "/upstreams/#{self.upstream_id}#{self.class::API_END_POINT}" if self.upstream_id
end
|