Class: Sidekiq::WebCustom::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/web_custom/configuration.rb

Constant Summary collapse

ALLOWED_BASED =
[ACTIONS = :actions, LOCAL_ERBS = :local_erbs]
INTEGERS =
[:drain_rate, :max_execution_time, :warn_execution_time]
DEFAULT_DRAIN_RATE =
10
DEFAULT_EXEC_TIME =
6
DEFAULT_WARN_TIME =
5

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



15
16
17
18
19
20
21
22
23
# File 'lib/sidekiq/web_custom/configuration.rb', line 15

def initialize
  ALLOWED_BASED.each do |var|
    instance_variable_set(:"@#{var}", {})
  end

  @drain_rate = DEFAULT_DRAIN_RATE
  @max_execution_time = DEFAULT_EXEC_TIME
  @warn_execution_time = DEFAULT_WARN_TIME
end

Instance Method Details

#merge(base:, params:, action_type: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sidekiq/web_custom/configuration.rb', line 39

def merge(base:, params:, action_type: nil)
  unless _allow_write_block?
    raise Sidekiq::WebCustom::ConfigurationEstablished, "Unable to assign base [#{base}]. Assignment must happen on boot"
  end
  raise Sidekiq::WebCustom::ArgumentError, "Unexpected base: #{base}" unless ALLOWED_BASED.include?(base)
  raise Sidekiq::WebCustom::ArgumentError, "Expected object for #{base} to be a Hash" unless params.is_a?(Hash)

  value = instance_variable_get(:"@#{base}")
  value =
    if action_type && base == ACTIONS
      value[action_type.to_sym] ||= {}
      value[action_type.to_sym].merge!(params)
      value
    else
      value.merge(params)
    end
  instance_variable_set(:"@#{base}", value)
end

#validate!Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sidekiq/web_custom/configuration.rb', line 58

def validate!
  ALLOWED_BASED.each do |key|
    value = instance_variable_get(:"@#{key}")

    _validate!(value, key)
  end

  unless @warn_execution_time <= @max_execution_time
    raise Sidekiq::WebCustom::ArgumentError, "Expected warn_execution_time to be less than max_execution_time"
  end

  unless actions.keys.all? { |k| local_erbs.keys.include?(k) }
    raise Sidekiq::WebCustom::ArgumentError, "Unexpected actions keys#{actions.keys} -- Expected to be part of #{local_erbs.keys}"
  end

  define_convenienve_methods!
  _unset_allow_write!
end