class Wor::Paginate::Utils::PreserveRecordsHelper
Attributes
content[R]
options[R]
url[R]
Public Class Methods
new(content, url, options)
click to toggle source
# File lib/wor/paginate/utils/preserve_records_helper.rb, line 8 def initialize(content, url, options) @content = content @url = url @options = options end
Public Instance Methods
call()
click to toggle source
# File lib/wor/paginate/utils/preserve_records_helper.rb, line 14 def call [content.where("#{field} <= :last_value", last_value: last_value), UriHelper.replace_query_params(url, query_param_name => last_value)] end
Private Instance Methods
by()
click to toggle source
# File lib/wor/paginate/utils/preserve_records_helper.rb, line 23 def by @by ||= begin by = options[:by]&.to_s || 'timestamp' raise ArgumentError, "'by' option should be 'id' or 'timestamp'" unless %w[timestamp id].include? by "Wor::Paginate::Utils::PreserveModes::#{by.classify}".constantize end end
field()
click to toggle source
# File lib/wor/paginate/utils/preserve_records_helper.rb, line 32 def field @field ||= options[:field] || by.default_field end
last_value()
click to toggle source
# File lib/wor/paginate/utils/preserve_records_helper.rb, line 36 def last_value @last_value ||= begin query_param_value = UriHelper.query_params(url)[query_param_name] by.last_value(query_param_value, content, field) end end
query_param_name()
click to toggle source
# File lib/wor/paginate/utils/preserve_records_helper.rb, line 43 def query_param_name @query_param_name ||= "#{field}_let" end