Class: Kaal::SchedulerFileLoader::JobNormalizer
- Inherits:
-
Object
- Object
- Kaal::SchedulerFileLoader::JobNormalizer
- Includes:
- Kaal::Support::HashTools
- Defined in:
- lib/kaal/scheduler_file/job_normalizer.rb
Overview
Normalizes scheduler job payloads into application-ready hashes.
Instance Method Summary collapse
- #call(job_payload) ⇒ Object
-
#initialize(hash_transform:, placeholder_support:, cron_validator:) ⇒ JobNormalizer
constructor
A new instance of JobNormalizer.
Methods included from Kaal::Support::HashTools
constantize, deep_dup, deep_merge, duplicable?, stringify_keys, symbolize_keys
Constructor Details
#initialize(hash_transform:, placeholder_support:, cron_validator:) ⇒ JobNormalizer
Returns a new instance of JobNormalizer.
15 16 17 18 19 |
# File 'lib/kaal/scheduler_file/job_normalizer.rb', line 15 def initialize(hash_transform:, placeholder_support:, cron_validator:) @hash_transform = hash_transform @placeholder_support = placeholder_support @cron_validator = cron_validator end |
Instance Method Details
#call(job_payload) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kaal/scheduler_file/job_normalizer.rb', line 21 def call(job_payload) payload = @hash_transform.stringify_keys(job_payload) key = payload.fetch('key', '').to_s.strip raise SchedulerConfigError, 'Job key cannot be blank' if key.empty? cron = required_string(payload, field: 'cron', error_prefix: "Job cron cannot be blank for key '#{key}'") job_class_name = required_string(payload, field: 'job_class', error_prefix: "Job class cannot be blank for key '#{key}'") validate_cron(key:, cron:) = (payload, key:) { key: key, cron: cron, job_class_name: job_class_name, ** } end |