Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/fbe/iterate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def initialize(fb:, loog:, options:, global:, epoch:, kickoff:)
@kickoff = kickoff
@label = nil
@since = 0
@custom = false
@query = nil
@sorting = nil
@repeats = 1
Expand Down Expand Up @@ -148,6 +149,24 @@ def repeats(repeats)
@repeats = repeats
end

# Sets the initial marker value.
#
# This value is used when no marker fact exists yet, and when iteration
# restarts after the query returns nil.
#
# @param [Integer] value The initial marker value
# @return [nil] Nothing is returned
# @raise [RuntimeError] If value is nil, not an Integer, or already set
# @example Start scanning after issue 100
# iterator.since(100)
def since(value)
raise(Fbe::Error, 'Since is already set') if @custom

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@akmhatey-ai should be since!()

raise(Fbe::Error, 'Cannot set "since" to nil') if value.nil?
raise(Fbe::Error, 'The "since" must be an Integer') unless value.is_a?(Integer)
@since = value
@custom = true
end

# Sets the query to execute for each iteration.
#
# The query can use two special variables:
Expand Down
48 changes: 48 additions & 0 deletions test/fbe/test_iterate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,54 @@ def test_raises_when_repeats_is_not_positive
end
end

def test_configures_since_start
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL)
seen = []
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do
as('custom_since_test')
since(7)
by('(plus $before 1)')
repeats(1)
over do |_, nxt|
seen << nxt
nxt
end
end
assert_equal([8], seen)
end

def test_raises_when_since_is_nil
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL)
assert_raises(Fbe::Error) do
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do
since(nil)
end
end
end

def test_raises_when_since_is_not_integer
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL)
assert_raises(Fbe::Error) do
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do
since('7')
end
end
end

def test_raises_when_since_set_twice
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL)
assert_raises(Fbe::Error) do
Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do
since(1)
since(2)
end
end
end

def test_raises_when_label_is_nil
opts = Judges::Options.new(['repositories=foo/bar', 'testing=true'])
fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL)
Expand Down
Loading