Sha256: 7b1c1e9279a23d5c87f1307dae7e9be34c8a93570c3cfe7c8eff3c7fbd4e1cb0

Contents?: true

Size: 466 Bytes

Versions: 2

Compression:

Stored size: 466 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.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

2 entries across 2 versions & 1 rubygems

Version Path
tasks_scheduler-0.7.0 lib/tasks_scheduler/cron_scheduling_validator.rb
tasks_scheduler-0.6.13 lib/tasks_scheduler/cron_scheduling_validator.rb