Class: ExcessFlow::ThrottleConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/excess_flow/throttle_configuration.rb

Overview

ExcessFlow::ThrottleConfiguration

Wrapper class for throttle execution result that does provide some basic transformation of provided values.

Constant Summary collapse

MANDATORY_KEYS =
i[
  key
  limit
  ttl
].freeze
OPTIONAL_KEYS =
i[
  strategy
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ThrottleConfiguration

Returns a new instance of ThrottleConfiguration.



35
36
37
38
39
40
41
42
# File 'lib/excess_flow/throttle_configuration.rb', line 35

def initialize(args)
  @raw_args = args
  validate_args

  args.each do |key, value|
    instance_variable_set("@#{key}", value) unless value.nil?
  end
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



33
34
35
# File 'lib/excess_flow/throttle_configuration.rb', line 33

def key
  @key
end

#limitObject (readonly)

Returns the value of attribute limit.



33
34
35
# File 'lib/excess_flow/throttle_configuration.rb', line 33

def limit
  @limit
end

#ttlObject (readonly)

Returns the value of attribute ttl.



33
34
35
# File 'lib/excess_flow/throttle_configuration.rb', line 33

def ttl
  @ttl
end

Instance Method Details

#counter_keyObject



44
45
46
# File 'lib/excess_flow/throttle_configuration.rb', line 44

def counter_key
  ExcessFlow::COUNTER_PREFIX + key
end

#lock_keyObject



48
49
50
# File 'lib/excess_flow/throttle_configuration.rb', line 48

def lock_key
  ExcessFlow::LOCK_PREFIX + key
end

#strategyObject



52
53
54
55
56
57
58
# File 'lib/excess_flow/throttle_configuration.rb', line 52

def strategy
  case @strategy
  when :fixed_window then ExcessFlow::FixedWindowStrategy
  when :sliding_window then ExcessFlow::SlidingWindowStrategy
  else ExcessFlow::FixedWindowStrategy
  end
end