Class: Kongfigure::Resources::Service

Inherits:
Base
  • Object
show all
Defined in:
lib/kongfigure/resources/service.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

#connect_timeoutObject

Returns the value of attribute connect_timeout.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def connect_timeout
  @connect_timeout
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def host
  @host
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def name
  @name
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def path
  @path
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def protocol
  @protocol
end

#read_timeoutObject

Returns the value of attribute read_timeout.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def read_timeout
  @read_timeout
end

#retriesObject

Returns the value of attribute retries.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def retries
  @retries
end

#routesObject

Returns the value of attribute routes.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def routes
  @routes
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def url
  @url
end

#write_timeoutObject

Returns the value of attribute write_timeout.



4
5
6
# File 'lib/kongfigure/resources/service.rb', line 4

def write_timeout
  @write_timeout
end

Class Method Details

.build(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kongfigure/resources/service.rb', line 7

def self.build(hash)
  service = new(hash["id"], hash["kongfigure_ignore_fields"])
  service.name            = hash["name"]
  service.retries         = hash["retries"]
  service.protocol        = hash["protocol"]
  service.host            = hash["host"]
  service.port            = hash["port"]
  service.path            = hash["path"]
  service.connect_timeout = hash["connect_timeout"]
  service.write_timeout   = hash["write_timeout"]
  service.read_timeout    = hash["read_timeout"]
  service.plugins         = Kongfigure::Resources::Plugin.build_all(hash["plugins"] || [])
  service.routes          = Kongfigure::Resources::Route.build_all(hash["routes"] || [])
  service.url             = hash["url"] || URI::Generic.build({
    scheme: hash["protocol"],
    host:   hash["host"],
    port:   hash["port"],
    path:   hash["path"]
  }).to_s
  service
end

Instance Method Details

#api_attributesObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kongfigure/resources/service.rb', line 49

def api_attributes
  {
    "name"            => name,
    "retries"         => retries,
    "protocol"        => protocol,
    "host"            => host,
    "port"            => port,
    "path"            => path,
    "connect_timeout" => connect_timeout,
    "write_timeout"   => write_timeout,
    "read_timeout"    => read_timeout,
    "url"             => url
  }.compact
end

#api_nameObject



29
30
31
# File 'lib/kongfigure/resources/service.rb', line 29

def api_name
  "services"
end

#has_route?(other_route) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/kongfigure/resources/service.rb', line 37

def has_route?(other_route)
  routes && routes.find do |route|
    other_route == route
  end
end

#has_routes?(other_routes) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/kongfigure/resources/service.rb', line 43

def has_routes?(other_routes)
  other_routes.reject do |other_route|
    has_route?(other_route)
  end.size == 0
end

#identifierObject



33
34
35
# File 'lib/kongfigure/resources/service.rb', line 33

def identifier
  name
end

#to_sObject



64
65
66
# File 'lib/kongfigure/resources/service.rb', line 64

def to_s
  name
end