Sha256: 111c939ddf7dca50fe02aa0e5a038df3bf8f76a7291568289fbdc9b4f203751a

Contents?: true

Size: 474 Bytes

Versions: 21

Compression:

Stored size: 474 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[attribute] << (options[:message] ||
          I18n.translate(: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

21 entries across 21 versions & 1 rubygems

Version Path
tasks_scheduler-0.6.12 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.11 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.10 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.9 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.8 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.7 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.6 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.5 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.4 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.3 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.2 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.1 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.0 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.5.4 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.5.3 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.5.2 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.5.1 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.5.0 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.4.2 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.4.1 lib/tasks_scheduler/cron_scheduling_validator.rb