Class: SidekiqUniqueJobs::Lock::Validator
- Inherits:
-
Object
- Object
- SidekiqUniqueJobs::Lock::Validator
- Defined in:
- lib/sidekiq_unique_jobs/lock/validator.rb
Overview
Validator base class to avoid some duplication
Constant Summary collapse
- DEPRECATED_KEYS =
Returns a hash mapping of deprecated keys and their new value.
{ UNIQUE.to_sym => LOCK.to_sym, UNIQUE_ARGS.to_sym => LOCK_ARGS_METHOD.to_sym, LOCK_ARGS.to_sym => LOCK_ARGS_METHOD.to_sym, UNIQUE_PREFIX.to_sym => LOCK_PREFIX.to_sym, }.freeze
Instance Attribute Summary collapse
-
#lock_config ⇒ Object
readonly
Returns the value of attribute lock_config.
Class Method Summary collapse
-
.validate(options) ⇒ LockConfig
Shorthand for ‘new(options).validate`.
Instance Method Summary collapse
-
#handle_deprecations ⇒ void
Validate deprecated keys adds useful information about how to proceed with fixing handle_deprecations.
-
#initialize(options) ⇒ Validator
constructor
Initialize a new validator.
-
#validate ⇒ LockConfig
Validate the workers lock configuration.
-
#validate_client ⇒ Object
Validates the client configuration.
-
#validate_server ⇒ Object
Validates the server configuration.
Constructor Details
#initialize(options) ⇒ Validator
Initialize a new validator
41 42 43 44 45 |
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 41 def initialize() @options = .transform_keys(&:to_sym) @lock_config = LockConfig.new() handle_deprecations end |
Instance Attribute Details
#lock_config ⇒ Object (readonly)
Returns the value of attribute lock_config.
34 35 36 |
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 34 def lock_config @lock_config end |
Class Method Details
.validate(options) ⇒ LockConfig
Shorthand for ‘new(options).validate`
27 28 29 |
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 27 def self.validate() new().validate end |
Instance Method Details
#handle_deprecations ⇒ void
This method returns an undefined value.
Validate deprecated keys
adds useful information about how to proceed with fixing handle_deprecations
73 74 75 76 77 78 79 |
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 73 def handle_deprecations DEPRECATED_KEYS.each do |old, new| next unless @options.key?(old) lock_config.errors[old] = "is deprecated, use `#{new}: #{@options[old]}` instead." end end |
#validate ⇒ LockConfig
Validate the workers lock configuration
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 53 def validate case lock_config.type when :while_executing validate_server when :until_executing validate_client else validate_client validate_server end lock_config end |
#validate_client ⇒ Object
Validates the client configuration
84 85 86 |
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 84 def validate_client ClientValidator.validate(lock_config) end |
#validate_server ⇒ Object
Validates the server configuration
91 92 93 |
# File 'lib/sidekiq_unique_jobs/lock/validator.rb', line 91 def validate_server ServerValidator.validate(lock_config) end |