diff --git a/.rubocop.yml b/.rubocop.yml index 91063a1..e0334e8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,7 @@ AllCops: - TargetRubyVersion: 3.2 + TargetRubyVersion: 2.6 + NewCops: enable +Metrics/BlockLength: + Exclude: + - spec/cron_calc_spec.rb diff --git a/cron_calc.gemspec b/cron_calc.gemspec index dc9fb10..ce0e9c9 100644 --- a/cron_calc.gemspec +++ b/cron_calc.gemspec @@ -17,6 +17,7 @@ Gem::Specification.new do |spec| spec.metadata['homepage_uri'] = spec.homepage spec.metadata['source_code_uri'] = 'https://github.com/mizinsky/cron_calc' spec.metadata['changelog_uri'] = 'https://github.com/mizinsky/cron_calc/blob/main/CHANGELOG.md' + spec.metadata['rubygems_mfa_required'] = 'true' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. diff --git a/lib/cron_calc.rb b/lib/cron_calc.rb index 4adc35d..b1a5597 100644 --- a/lib/cron_calc.rb +++ b/lib/cron_calc.rb @@ -3,6 +3,7 @@ require_relative 'cron_calc/version' require 'time' +# The CronCalc is gem-wrapper module for the Parser class module CronCalc class Error < StandardError; end @@ -10,6 +11,9 @@ def self.new(cron_string, period) Parser.new(cron_string, period) end + # The Parser class provides functionality to parse and calculate occurrences + # of cron jobs within a given time period. It interprets cron strings and + # calculates when cron jobs will occur class Parser attr_reader :cron_string, :cron_parts, :period @@ -54,6 +58,7 @@ def parse_cron_expression %i[minutes hours days months].map { |unit| parse_cron_part(unit) } << (period.min.year..period.max.year).to_a end + # rubocop:disable Metrics def parse_cron_part(time_unit) range = RANGE[time_unit] part = cron_parts[time_unit] @@ -71,9 +76,12 @@ def parse_cron_part(time_unit) [part.to_i] end end + # rubocop:enable Metrics def cron_string_valid? + # rubocop:disable Layout/LineLength regex = %r{\A(\*|([0-5]?\d)(,([0-5]?\d))*|(\*/\d+)|(\d+-\d+)) (\*|([01]?\d|2[0-3])(,([01]?\d|2[0-3]))*|(\*/\d+)|(\d+-\d+)) (\*|([12]?\d|3[01])(,([12]?\d|3[01]))*|(\*/\d+)|(\d+-\d+)) (\*|([1-9]|1[0-2])(,([1-9]|1[0-2]))*|(\*/\d+)|(\d+-\d+)) \*\z} + # rubocop:enable Layout/LineLength cron_string.match?(regex) end end diff --git a/spec/cron_calc_spec.rb b/spec/cron_calc_spec.rb index 75abcc0..01acb17 100644 --- a/spec/cron_calc_spec.rb +++ b/spec/cron_calc_spec.rb @@ -102,7 +102,7 @@ let(:period) { Time.new(2023, 1, 1)..Time.new(2023, 1, 2) } it do - expect { subject }.to raise_error(RuntimeError, 'Cron expression is not supported or invalid') + expect { subject }.to raise_error(RuntimeError, 'Cron expression is not supported or invalid test') end end