Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplekit-ruby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sanchez, Paul
simplekit-ruby
Commits
7d775f99
Commit
7d775f99
authored
6 years ago
by
pjs
Browse files
Options
Downloads
Patches
Plain Diff
refactored cancellation check into private method for readability
parent
5d4aa1ac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/simplekit.rb
+37
-36
37 additions, 36 deletions
lib/simplekit.rb
with
37 additions
and
36 deletions
lib/simplekit.rb
+
37
−
36
View file @
7d775f99
...
...
@@ -83,25 +83,7 @@ module SimpleKit
@model_time
=
0.0
@user_model
.
init
while
(
current_event
=
@event_list
.
pop
)
e
=
current_event
.
event
if
@cancel_set
.
key?
e
if
@cancel_set
[
e
]
===
nil
@cancel_set
[
e
].
delete
nil
@cancel_set
.
delete
e
if
@cancel_set
[
e
].
empty?
next
else
arg_match
=
false
for
h
in
@cancel_set
[
e
]
do
if
current_event
.
args
>=
h
arg_match
=
true
@cancel_set
[
e
].
delete
h
@cancel_set
.
delete
e
if
@cancel_set
[
e
].
empty?
break
end
end
next
if
arg_match
end
end
next
if
should_cancel?
(
current_event
)
@model_time
=
current_event
.
time
if
current_event
.
args
.
empty?
@user_model
.
send
(
current_event
.
event
)
...
...
@@ -116,27 +98,46 @@ module SimpleKit
def
halt
@event_list
.
clear
end
end
private
private
# This is a private helper class for the EventScheduler class.
# Users should never try to access this directly.
class
EventNotice
attr_reader
:event
,
:time
,
:time_stamp
,
:priority
,
:args
def
initialize
(
event
,
time
,
delay
,
args
)
@event
=
event
@time_stamp
=
time
@time
=
time
+
delay
@args
=
args
@priority
=
(
@args
&&
@args
.
key?
(
:priority
))
?
@args
.
delete
(
:priority
)
:
10
def
should_cancel?
(
event_notice
)
e
=
event_notice
.
event
if
@cancel_set
.
key?
e
if
@cancel_set
[
e
]
===
nil
@cancel_set
[
e
].
delete
nil
@cancel_set
.
delete
e
if
@cancel_set
[
e
].
empty?
return
true
else
for
hsh
in
@cancel_set
[
e
]
do
next
unless
event_notice
.
args
>=
hsh
@cancel_set
[
e
].
delete
hsh
@cancel_set
.
delete
e
if
@cancel_set
[
e
].
empty?
return
true
end
end
end
false
end
include
Comparable
def
<
=>
(
other
)
(
time
<=>
other
.
time
).
tap
do
|
outcome
|
return
priority
<=>
other
.
priority
if
outcome
==
0
# This is a private helper class for the EventScheduler class.
# Users should never try to access this directly.
class
EventNotice
attr_reader
:event
,
:time
,
:time_stamp
,
:priority
,
:args
def
initialize
(
event
,
time
,
delay
,
args
)
@event
=
event
@time_stamp
=
time
@time
=
time
+
delay
@args
=
args
@priority
=
@args
&&
@args
.
key?
(
:priority
)
?
@args
.
delete
(
:priority
)
:
10
end
include
Comparable
def
<
=>
(
other
)
(
time
<=>
other
.
time
).
tap
do
|
outcome
|
return
priority
<=>
other
.
priority
if
outcome
==
0
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment