Sha256: 4ea39a7abb24e789de5b40ba2d66016be5d0eb708f2173545fbdb34f1d8773db

Contents?: true

Size: 468 Bytes

Versions: 4

Compression:

Stored size: 468 Bytes

Contents

# frozen_string_literal: true

module TasksScheduler
  class CronSchedulingValidator < ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      return if value_valid?(value)

      record.errors.add(attribute, (options[:message] ||
          I18n.t(:cron_scheduling_validator_error_message)))
    end

    private

    def value_valid?(value)
      ::CronParser.new(value).next
      true
    rescue ArgumentError
      false
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tasks_scheduler-0.9.2 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.9.1 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.9.0 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.8.0 lib/tasks_scheduler/cron_scheduling_validator.rb