Skip to content

Commit

Permalink
Update supported version of ruby and rails (ice-cube-ruby#552)
Browse files Browse the repository at this point in the history
* Updaet supported version of ruby and rails

* linting

* Update CHANGELOG.md

* Linting

* Linting

* Fix spec

* Update checkout action

* Update changelog enforcer

* Update checkout to v4
  • Loading branch information
pacso authored May 9, 2024
1 parent 10ae8dc commit 02ce88e
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 59 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- id: read-version
run: |
echo "::set-output name=VERSION::`cat lib/ice_cube/version.rb | grep -i version | awk '{ print $3 }' | sed -e 's/\"//g'`"
- uses: dangoslen/changelog-enforcer@v2.3.1
- uses: dangoslen/changelog-enforcer@v3
with:
skipLabels: 'skip-changelog'
expectedLatestVersion: ${{ steps.read-version.outputs.VERSION }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.6'
ruby-version: '3.1'
bundler-cache: true
- run: bundle exec standardrb
test:
Expand All @@ -42,22 +42,13 @@ jobs:
- lint
strategy:
matrix:
rails: ['5.2', '6.0.4', '6.1', '7.0']
ruby: ['2.6', '2.7', '3.0', '3.1']
exclude:
- rails: '5.2'
ruby: '3.0'
- rails: '5.2'
ruby: '3.1'
- rails: '7.0'
ruby: '2.6'
- rails: '7.0'
ruby: '2.7'
rails: ['6.1', '7.0', '7.1']
ruby: ['3.1', '3.2', '3.3']
runs-on: ubuntu-latest
env:
RAILS_VERSION: ${{ matrix.rails }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Removed use of `delegate` method added in [66f1d797](https://github.com/ice-cube-ruby/ice_cube/commit/66f1d797092734563bfabd2132c024c7d087f683) , reverting to previous implementation. ([#522](https://github.com/ice-cube-ruby/ice_cube/pull/522)) by [@pacso](https://github.com/pacso)
- Updated supported versions of Ruby and Rails and fixed standardrb lint issues. ([#552](https://github.com/ice-cube-ruby/ice_cube/pull/552)) by [@pacso](https://github.com/pacso)

### Fixed
- Fix for weekly interval results when requesting `occurrences_between` on a narrow range ([#487](https://github.com/seejohnrun/ice_cube/pull/487)) by [@jakebrady5](https://github.com/jakebrady5)
Expand Down
1 change: 0 additions & 1 deletion ice_cube.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Gem::Specification.new do |s|
s.version = IceCube::VERSION
s.platform = Gem::Platform::RUBY
s.files = Dir["lib/**/*.rb", "config/**/*.yml"]
s.test_files = Dir.glob("spec/*.rb")
s.require_paths = ["lib"]

s.add_development_dependency("rake")
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/builders/string_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def ordinal(number)
ord = IceCube::I18n.t("ice_cube.integer.ordinals")[number] ||
IceCube::I18n.t("ice_cube.integer.ordinals")[number % 10] ||
IceCube::I18n.t("ice_cube.integer.ordinals")[:default]
number >= 0 ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord)
(number >= 0) ? ord : IceCube::I18n.t("ice_cube.integer.negative", ordinal: ord)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/ice_cube/flexible_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def delete(key)

def _match_key(key)
return key if __getobj__.has_key? key
if Symbol == key.class
if key.instance_of?(Symbol)
__getobj__.keys.detect { |k| return k if k == key.to_s }
elsif String == key.class
elsif key.instance_of?(String)
__getobj__.keys.detect { |k| return k if k.to_s == key }
end
key
Expand Down
12 changes: 6 additions & 6 deletions lib/ice_cube/input_alignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def initialize(rule, value, rule_part)

attr_reader :rule, :value, :rule_part

def verify(freq, options = {}, &block)
def verify(freq, options = {}, &)
@rule.validations[:interval] or return

case @rule
when DailyRule
verify_wday_alignment(freq, &block)
verify_wday_alignment(freq, &)
when MonthlyRule
verify_month_alignment(freq, &block)
verify_month_alignment(freq, &)
else
verify_freq_alignment(freq, &block)
verify_freq_alignment(freq, &)
end
end

Expand All @@ -28,12 +28,12 @@ def interval_validation
end

def interval_value
@interval_value ||= rule_part == :interval ? value : interval_validation.interval
@interval_value ||= (rule_part == :interval) ? value : interval_validation.interval
end

def fixed_validations
@fixed_validations ||= @rule.validations.values.flatten.select { |v|
interval_type = (v.type == :wday ? :day : v.type)
interval_type = ((v.type == :wday) ? :day : v.type)
v.class < Validations::FixedValue &&
interval_type == rule.base_interval_validation.type
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/null_i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module NullI18n
def self.t(key, options = {})
base = key.to_s.split(".").reduce(config) { |hash, current_key| hash[current_key] }

base = base[options[:count] == 1 ? "one" : "other"] if options[:count]
base = base[(options[:count] == 1) ? "one" : "other"] if options[:count]

case base
when Hash
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/occurrence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def to_s(format = nil)
else
t0, t1 = start_time.to_s, end_time.to_s
end
duration > 0 ? "#{t0} - #{t1}" : t0
(duration > 0) ? "#{t0} - #{t1}" : t0
end

def overnight?
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/rules/weekly_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def realign(step_time, start_time)
time = TimeUtil::TimeWrapper.new(start_time)
offset = wday_offset(step_time, start_time)
time.add(:day, offset)
super step_time, time.to_time
super(step_time, time.to_time)
end

# Calculate how many days to the first wday validation in the correct
Expand Down
6 changes: 3 additions & 3 deletions lib/ice_cube/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def all_occurrences_enumerator
end

# Iterate forever
def each_occurrence(&block)
enumerate_occurrences(start_time, &block).to_a
def each_occurrence(&)
enumerate_occurrences(start_time, &).to_a
self
end

Expand Down Expand Up @@ -191,7 +191,7 @@ def previous_occurrences(num, from)
from = TimeUtil.match_zone(from, start_time) or raise ArgumentError, "Time required, got #{from.inspect}"
return [] if from <= start_time
a = enumerate_occurrences(start_time, from - 1).to_a
a.size > num ? a[-1 * num, a.size] : a
(a.size > num) ? a[-1 * num, a.size] : a
end

# The remaining occurrences (same requirements as all_occurrences)
Expand Down
22 changes: 11 additions & 11 deletions lib/ice_cube/time_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.match_zone(input_time, reference)
else
time.getlocal(reference.utc_offset)
end
Date === input_time ? beginning_of_date(time, reference) : time
(Date === input_time) ? beginning_of_date(time, reference) : time
end

# Ensure that this is either nil, or a time
Expand Down Expand Up @@ -286,12 +286,12 @@ def to_time
def add(type, val)
type = :day if type == :wday
@time += case type
when :year then TimeUtil.days_in_n_years(@time, val) * ONE_DAY
when :month then TimeUtil.days_in_n_months(@time, val) * ONE_DAY
when :day then val * ONE_DAY
when :hour then val * ONE_HOUR
when :min then val * ONE_MINUTE
when :sec then val
when :year then TimeUtil.days_in_n_years(@time, val) * ONE_DAY
when :month then TimeUtil.days_in_n_months(@time, val) * ONE_DAY
when :day then val * ONE_DAY
when :hour then val * ONE_HOUR
when :min then val * ONE_MINUTE
when :sec then val
end
end

Expand All @@ -318,20 +318,20 @@ def sec=(value)
end

def clear_sec
@time.sec > 0 ? @time -= @time.sec : @time
(@time.sec > 0) ? @time -= @time.sec : @time
end

def clear_min
@time.min > 0 ? @time -= (@time.min * ONE_MINUTE) : @time
(@time.min > 0) ? @time -= (@time.min * ONE_MINUTE) : @time
end

def clear_hour
@time.hour > 0 ? @time -= (@time.hour * ONE_HOUR) : @time
(@time.hour > 0) ? @time -= (@time.hour * ONE_HOUR) : @time
end

# Move to the first of the month, 0 hours
def clear_day
@time.day > 1 ? @time -= (@time.day - 1) * ONE_DAY : @time
(@time.day > 1) ? @time -= (@time.day - 1) * ONE_DAY : @time
end

# Clear to january 1st
Expand Down
4 changes: 2 additions & 2 deletions lib/ice_cube/validations/day_of_week.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def dst_adjust?

def validate(step_time, start_time)
wday = step_time.wday
offset = day < wday ? (7 - wday + day) : (day - wday)
offset = (day < wday) ? (7 - wday + day) : (day - wday)
wrapper = TimeUtil::TimeWrapper.new(step_time)
wrapper.add :day, offset
loop do
which_occ, num_occ = TimeUtil.which_occurrence_in_month(wrapper.to_time, day)
this_occ = occ < 0 ? (num_occ + occ + 1) : occ
this_occ = (occ < 0) ? (num_occ + occ + 1) : occ
break offset if which_occ == this_occ
wrapper.add :day, 7
offset += 7
Expand Down
4 changes: 2 additions & 2 deletions lib/ice_cube/validations/day_of_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def dst_adjust?

def validate(step_time, start_time)
days_in_year = TimeUtil.days_in_year(step_time)
yday = day < 0 ? day + days_in_year + 1 : day
yday = (day < 0) ? day + days_in_year + 1 : day
offset = yday - step_time.yday
offset >= 0 ? offset : offset + days_in_year
(offset >= 0) ? offset : offset + days_in_year
end

def build_s(builder)
Expand Down
8 changes: 4 additions & 4 deletions lib/ice_cube/validations/fixed_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def validate(time, start_time)
def validate_interval_lock(time, start_time)
t0 = starting_unit(start_time)
t1 = time.send(type)
t0 >= t1 ? t0 - t1 : INTERVALS[type] - t1 + t0
(t0 >= t1) ? t0 - t1 : INTERVALS[type] - t1 + t0
end

# Lock the hour if explicitly set by hour_of_day, but allow for the nearest
Expand Down Expand Up @@ -73,16 +73,16 @@ def validate_day_lock(time, start_time)
if value && value > 0
until_next_month = days_in_month + sleeps
else
until_next_month = start < 28 ? days_in_month : TimeUtil.days_to_next_month(date)
until_next_month = (start < 28) ? days_in_month : TimeUtil.days_to_next_month(date)
until_next_month += sleeps - month_overflow
end

sleeps >= 0 ? sleeps : until_next_month
(sleeps >= 0) ? sleeps : until_next_month
end

def starting_unit(start_time)
start = value || start_time.send(type)
start = start % INTERVALS[type] if start < 0
start %= INTERVALS[type] if start < 0
start
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/validations/hour_of_day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def realign(opening_time, start_time)
time.hour = first_hour.value
end

super opening_time, time.to_time
super(opening_time, time.to_time)
end

class Validation < Validations::FixedValue
Expand Down
6 changes: 3 additions & 3 deletions lib/ice_cube/validations/lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def validate(time, start_time)
def validate_interval_lock(time, start_time)
t0 = starting_unit(start_time)
t1 = time.send(type)
t0 >= t1 ? t0 - t1 : INTERVALS[type] - t1 + t0
(t0 >= t1) ? t0 - t1 : INTERVALS[type] - t1 + t0
end

# Lock the hour if explicitly set by hour_of_day, but allow for the nearest
Expand Down Expand Up @@ -73,11 +73,11 @@ def validate_day_lock(time, start_time)
if value && value > 0
until_next_month = days_in_month + sleeps
else
until_next_month = start < 28 ? days_in_month : TimeUtil.days_to_next_month(date)
until_next_month = (start < 28) ? days_in_month : TimeUtil.days_to_next_month(date)
until_next_month += sleeps - month_overflow
end

sleeps >= 0 ? sleeps : until_next_month
(sleeps >= 0) ? sleeps : until_next_month
end

def starting_unit(start_time)
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/validations/minute_of_hour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def realign(opening_time, start_time)
first_minute = validations[:minute_of_hour].min_by(&:value)
time = TimeUtil::TimeWrapper.new(start_time, false)
time.min = first_minute.value
super opening_time, time.to_time
super(opening_time, time.to_time)
end

class Validation < Validations::FixedValue
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/validations/second_of_minute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def realign(opening_time, start_time)
first_second = Array(validations[:second_of_minute]).min_by(&:value)
time = TimeUtil::TimeWrapper.new(start_time, false)
time.sec = first_second.value
super opening_time, time.to_time
super(opening_time, time.to_time)
end

class Validation < Validations::FixedValue
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/ice_cube_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@
def quick_attempt_test
time = Time.now
10.times do
(yield).next_occurrence(Time.now)
yield.next_occurrence(Time.now)
end
total = Time.now - time
expect(total).to be < 0.1
Expand Down
7 changes: 6 additions & 1 deletion spec/examples/occurrence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
time_now = Time.current
occurrence = Occurrence.new(time_now)

expect(occurrence.to_s(:short)).to eq time_now.to_s(:short)
# From Rails 7.1 onwards, support for format options was removed
if time_now.public_method(:to_s).arity != 0
expect(occurrence.to_s(:short)).to eq time_now.to_s(:short)
else
expect(occurrence.to_s(:short)).to eq time_now.to_s
end
end
end

Expand Down

0 comments on commit 02ce88e

Please sign in to comment.