Class: Imperium::Service

Inherits:
APIObject show all
Defined in:
lib/imperium/service.rb

Overview

Service is a container for data being received from and sent to the agent services APIs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from APIObject

#==, #attribute_map, #ruby_attribute_names, #to_h

Constructor Details

#initialize(*args) ⇒ Service



46
47
48
49
50
51
# File 'lib/imperium/service.rb', line 46

def initialize(*args)
  # So we can << onto these w/o having to nil check everywhere first
  @tags ||= []
  @checks ||= []
  super
end

Instance Attribute Details

#addressString



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#checksArray<ServiceCheck>



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#create_indexInteger (readonly)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#enable_tag_overrideBoolean



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#idString



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#modify_indexInteger (readonly)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#nameString



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#portInteger



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

#tagsArary<String>



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/imperium/service.rb', line 32

class Service < APIObject
  self.attribute_map = {
    'ID' => :id,
    'Name' => :name,
    'Tags' => :tags,
    'Address' => :address,
    'Port' => :port,
    'Check' => :check,
    'Checks' => :checks,
    'EnableTagOverride' => :enable_tag_override,
    'CreateIndex' => :create_index,
    'ModifyIndex' => :modify_index
  }

  def initialize(*args)
    # So we can << onto these w/o having to nil check everywhere first
    @tags ||= []
    @checks ||= []
    super
  end

  def add_check(val)
    @checks <<  maybe_convert_service_check(val) unless val.nil?
  end
  alias check= add_check


  def checks=(val)
    @checks = (val || []).map { |obj| maybe_convert_service_check(obj) }
  end

  def tags=(val)
    @tags = (val.nil? ? [] : val)
  end

  # Generate a hash containing the data necessary for registering this service.
  #
  # If both Check and Checks are present in the object they're coalesced into
  # a single Checks key.
  #
  # @return [Hash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]
  def registration_data
    to_h.tap do |h|
      h.delete('CreateIndex')
      h.delete('ModifyIndex')
      h.delete('Checks') if checks.empty?
    end
  end

  private

  def maybe_convert_service_check(attrs_or_check)
    attrs_or_check.is_a?(Hash) ? ServiceCheck.new(attrs_or_check) : attrs_or_check
  end
end

Instance Method Details

#add_check(val) ⇒ Object Also known as: check=



53
54
55
# File 'lib/imperium/service.rb', line 53

def add_check(val)
  @checks <<  maybe_convert_service_check(val) unless val.nil?
end

#registration_dataHash<String => String,Integer,Hash<String => String>,Array<Hash<String => String>>]

Generate a hash containing the data necessary for registering this service.

If both Check and Checks are present in the object they’re coalesced into a single Checks key.



73
74
75
76
77
78
79
# File 'lib/imperium/service.rb', line 73

def registration_data
  to_h.tap do |h|
    h.delete('CreateIndex')
    h.delete('ModifyIndex')
    h.delete('Checks') if checks.empty?
  end
end