Skip to content

Conversation

@avit
Copy link
Collaborator

@avit avit commented Sep 18, 2017

Fixes #416
Fixes #406

Limit each example to 1 second in case of infinite loops. Can be redefined with
timeout: 0 on example metadata.
Reject illogical combinations of rule types with intervals that would never
align with any occurrences.
When time parts (hour_of_day, minute_of_hour, second_of_minute) are specified on
recurrence rules, the rules would jump over valid occurrences unless they were
realigned.
Some combinations of rule parts do not apply. Rather than exposing all possible
validations on all recurrence rule types, limit to ones that produce results.
schedule.add_recurrence_rule Rule.minutely(60).day(4).hour_of_day(14, 15, 16).minute_of_hour(0)
expect(schedule.occurring_at?(Time.local(2011, 11, 17, 15, 30))).to be_falsey
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spec originally fixed an infinite loop by skipping over valid occurrences. It should actually occur on the time in this example so I removed it.

@avit avit requested a review from seejohnrun September 18, 2017 16:09
Copy link
Collaborator

@seejohnrun seejohnrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to need a minor version bump on this I think 👍

There's a lot to unpack here, but this looks good - thank you for taking it on!


include Validations::ScheduleLock

include Validations::HourOfDay
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to splitting these out so we can only have them where they make sense

return unless freq == :wday || freq == :day
return unless @validations[:interval]

interval_validation = @validations[:interval].first
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth moving this interval-checking into a util that we can use in both places

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm not 100% happy with some of the duplication & super-calling either. I'll see what I can do.

end

def other_fixed_value_validations
@validations.values.flatten.select { |v|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do / end on multi-line blocks

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sure. 😄

I've always been more partial to Jim Weirich's semantic brace style, and I try to sneak it in when I can:

  • Use { } for blocks that return values (functional)
  • Use do / end for blocks that are executed for side effects (procedural)

It actually turns out that doing it this way, it works out that very often it's the same as the single-line vs. multi-line style, because of the kinds of things that go into procedural vs. functional blocks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I can be down with that - I like the idea :)

def interval(interval)
@interval = normalized_interval(interval)
interval = normalized_interval(interval)
verify_alignment(interval, :wday, :interval) { |error| raise error }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we yield this error up instead of just raiseing it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that it gives a more relevant trace, since it appears from the called interval public method interface, instead of raising from somewhere deeper down.

Move methods related to input verification into their own object.
@avit avit merged commit d0a6b6a into ice-cube-ruby:master Sep 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants