Skip to content

Commit f66ade5

Browse files
committed
DRY idiosyncratic handling of str/int 'last' value
1 parent 4d6f476 commit f66ade5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/oai/provider/resumption_token.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def self.extract_format(token_string)
6969
def initialize(options, expiration = nil, total = nil)
7070
@prefix = options[:metadata_prefix]
7171
@set = options[:set]
72-
@last = options[:last].to_i
73-
@last_str = options[:last].to_s
72+
self.last = options[:last]
7473
@from = options[:from] if options[:from]
7574
@until = options[:until] if options[:until]
7675
@expiration = expiration if expiration
@@ -79,8 +78,7 @@ def initialize(options, expiration = nil, total = nil)
7978

8079
# convenience method for setting the offset of the next set of results
8180
def next(last)
82-
@last_str = last.to_s
83-
@last = last.to_i
81+
self.last = last
8482
self
8583
end
8684

@@ -117,6 +115,13 @@ def to_s
117115

118116
private
119117

118+
# take care of our logic to store an integer and a str version, for backwards
119+
# compat where it was assumed to be an integer, as well as supporting string.
120+
def last=(value)
121+
@last = value.to_i
122+
@last_str = value.to_s
123+
end
124+
120125
def encode_conditions
121126
encoded_token = @prefix.to_s.dup
122127
encoded_token << ".s(#{set})" if set

0 commit comments

Comments
 (0)