Module: SourceMonitor::Jobs::CleanupOptions
- Defined in:
- lib/source_monitor/jobs/cleanup_options.rb
Class Method Summary collapse
- .batch_size(options, default:) ⇒ Object
- .extract_ids(value) ⇒ Object
- .integer(value) ⇒ Object
- .normalize(options) ⇒ Object
- .resolve_time(value, default: Time.current) ⇒ Object
Class Method Details
.batch_size(options, default:) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/source_monitor/jobs/cleanup_options.rb', line 59 def batch_size(, default:) value = integer([:batch_size]) return default unless value&.positive? value end |
.extract_ids(value) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/source_monitor/jobs/cleanup_options.rb', line 34 def extract_ids(value) Array(value) .flat_map do |entry| case entry when Integer [ entry ] when Array entry else entry.to_s.split(",") end end .map { |entry| entry.is_a?(String) ? entry.strip : entry } .reject { |entry| entry.respond_to?(:blank?) ? entry.blank? : entry.nil? } .map { |entry| integer(entry) } .compact .reject(&:zero?) end |
.integer(value) ⇒ Object
53 54 55 56 57 |
# File 'lib/source_monitor/jobs/cleanup_options.rb', line 53 def integer(value) return value if value.is_a?(Integer) Integer(value, exception: false) end |
.normalize(options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/source_monitor/jobs/cleanup_options.rb', line 10 def normalize() case when nil {} when Hash .respond_to?(:symbolize_keys) ? .symbolize_keys : symbolize_keys() else {} end end |
.resolve_time(value, default: Time.current) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/source_monitor/jobs/cleanup_options.rb', line 21 def resolve_time(value, default: Time.current) case value when nil default when Time value when String parse_time(value, default) else value.respond_to?(:to_time) ? value.to_time : default end end |