Class: Twingly::AMQP::PingOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/twingly/amqp/ping_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider_name: nil, source_ip: nil, priority: nil, custom_options: {}) {|_self| ... } ⇒ PingOptions

Returns a new instance of PingOptions.

Yields:

  • (_self)

Yield Parameters:


8
9
10
11
12
13
14
15
16
# File 'lib/twingly/amqp/ping_options.rb', line 8

def initialize(provider_name: nil, source_ip: nil, priority: nil,
               custom_options: {})
  self.provider_name  = provider_name
  self.source_ip      = source_ip
  self.priority       = priority
  self.custom_options = custom_options

  yield self if block_given?
end

Instance Attribute Details

#custom_optionsObject

Returns the value of attribute custom_options.


6
7
8
# File 'lib/twingly/amqp/ping_options.rb', line 6

def custom_options
  @custom_options
end

#priorityObject

Returns the value of attribute priority.


4
5
6
# File 'lib/twingly/amqp/ping_options.rb', line 4

def priority
  @priority
end

#provider_nameObject

Returns the value of attribute provider_name.


4
5
6
# File 'lib/twingly/amqp/ping_options.rb', line 4

def provider_name
  @provider_name
end

#source_ipObject

Returns the value of attribute source_ip.


4
5
6
# File 'lib/twingly/amqp/ping_options.rb', line 4

def source_ip
  @source_ip
end

Instance Method Details

#merge(other) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/twingly/amqp/ping_options.rb', line 45

def merge(other)
  PingOptions.new do |options|
    options.provider_name  = other.provider_name || provider_name
    options.source_ip      = other.source_ip     || source_ip
    options.priority       = other.priority      || priority
    options.custom_options = custom_options.merge(other.custom_options)
  end
end

#to_hObject


26
27
28
29
30
31
32
33
# File 'lib/twingly/amqp/ping_options.rb', line 26

def to_h
  {
    provider_name:  provider_name,
    source_ip:      source_ip,
    priority:       priority,
    custom_options: custom_options,
  }
end

#validateObject


35
36
37
38
39
40
41
42
43
# File 'lib/twingly/amqp/ping_options.rb', line 35

def validate
  missing_keys = to_h.select do |key, value|
    key != :custom_options && value.to_s.empty?
  end.keys

  if missing_keys.any?
    raise ArgumentError, "Required options not set: #{missing_keys}"
  end
end