Class: Kongfigure::Resources::Upstream

Inherits:
Base
  • Object
show all
Defined in:
lib/kongfigure/resources/upstream.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#id, #kongfigure_ignore_fields, #plugins, #unchanged, #updated

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, build_all, #display_name, #has_to_be_deleted?, #initialize, #mark_as_unchanged, #mark_as_updated, #plugin_allowed?

Constructor Details

This class inherits a constructor from Kongfigure::Resources::Base

Instance Attribute Details

#hash_fallbackObject

Returns the value of attribute hash_fallback.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def hash_fallback
  @hash_fallback
end

#hash_fallback_headerObject

Returns the value of attribute hash_fallback_header.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def hash_fallback_header
  @hash_fallback_header
end

#hash_onObject

Returns the value of attribute hash_on.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def hash_on
  @hash_on
end

Returns the value of attribute hash_on_cookie.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def hash_on_cookie
  @hash_on_cookie
end

Returns the value of attribute hash_on_cookie_path.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def hash_on_cookie_path
  @hash_on_cookie_path
end

#hash_on_headerObject

Returns the value of attribute hash_on_header.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def hash_on_header
  @hash_on_header
end

#healthchecksObject

Returns the value of attribute healthchecks.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def healthchecks
  @healthchecks
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def name
  @name
end

#slotsObject

Returns the value of attribute slots.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def slots
  @slots
end

#targetsObject

Returns the value of attribute targets.



3
4
5
# File 'lib/kongfigure/resources/upstream.rb', line 3

def targets
  @targets
end

Class Method Details

.build(hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kongfigure/resources/upstream.rb', line 6

def self.build(hash)
  upstream                      = new(hash["id"], hash["kongfigure_ignore_fields"])
  upstream.name                 = hash["name"]
  upstream.hash_on              = hash["hash_on"]
  upstream.hash_fallback        = hash["hash_fallback"]
  upstream.hash_on_cookie_path  = hash["hash_on_cookie_path"]
  upstream.slots                = hash["slots"]
  upstream.healthchecks         = hash["healthchecks"]
  upstream.hash_on_header       = hash["hash_on_header"]
  upstream.hash_fallback        = hash["hash_fallback"]
  upstream.hash_fallback_header = hash["hash_fallback_header"]
  upstream.hash_on_cookie       = hash["hash_on_cookie"]
  upstream.targets              = Kongfigure::Resources::Target.build_all(hash["targets"] || [])
  upstream
end

Instance Method Details

#api_attributesObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/kongfigure/resources/upstream.rb', line 38

def api_attributes
  {
    "name"                 => name,
    "hash_on"              => hash_on,
    "hash_fallback"        => hash_fallback,
    "hash_on_cookie_path"  => hash_on_cookie_path,
    "slots"                => healthchecks,
    "hash_on_header"       => hash_on_header,
    "hash_fallback_header" => hash_fallback_header,
    "hash_on_cookie"       => hash_on_cookie
  }.compact
end

#api_nameObject



34
35
36
# File 'lib/kongfigure/resources/upstream.rb', line 34

def api_name
  "upstreams"
end

#has_target?(target) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/kongfigure/resources/upstream.rb', line 51

def has_target?(target)
  targets && targets.include?(target)
end

#identifierObject



22
23
24
# File 'lib/kongfigure/resources/upstream.rb', line 22

def identifier
  name
end

#to_sObject



26
27
28
29
30
31
32
# File 'lib/kongfigure/resources/upstream.rb', line 26

def to_s
  if targets.size > 0
    "#{name} with targets #{targets.map(&:target).join(', ')}"
  else
    "#{name} without target"
  end
end