Class: ParamsReady::Pagination::KeysetPaginationDefinition

Constant Summary collapse

MIN_LIMIT =
1

Instance Attribute Summary collapse

Attributes inherited from ParamsReady::Parameter::AbstractStructParameterDefinition

#key_map, #names

Attributes inherited from ParamsReady::Parameter::Definition

#default

Attributes inherited from ParamsReady::Parameter::AbstractDefinition

#altn, #name

Instance Method Summary collapse

Methods inherited from ParamsReady::Parameter::StructParameterDefinition

#add_map, #ensure_canonical, #remap?

Methods inherited from ParamsReady::Parameter::AbstractStructParameterDefinition

#add_child, #child_definition, #duplicate_value, #freeze_value, #has_child?, #infer_default, #set_default

Methods inherited from ParamsReady::Parameter::Definition

#canonical_default, #default_defined?, #fetch_callable_default, #fetch_default, #memoize?, #name_for_formatter, #no_input?, #no_output?, #postprocess, #preprocess, #restricted_for_format?, #set_local, #set_no_input, #set_postprocessor, #set_preprocessor

Methods inherited from ParamsReady::Parameter::AbstractDefinition

#create, #from_hash, #from_input, #normalize_alternative_name, #parameter_class

Methods included from Extensions::Freezer

#freeze_variable, #freeze_variables, #variables_to_freeze

Methods included from Extensions::Finalizer

#obligatory, #obligatory!

Methods included from Extensions::ClassReaderWriter

#class_reader_writer

Methods included from Extensions::LateInit

#late_init

Methods included from Extensions::Collection

#collection

Methods included from Extensions::Freezer::InstanceMethods

#freeze

Constructor Details

#initialize(default_limit, max_limit = nil) ⇒ KeysetPaginationDefinition

Returns a new instance of KeysetPaginationDefinition.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/params_ready/pagination/keyset_pagination.rb', line 187

def initialize(default_limit, max_limit = nil)
  super :pagination,
        altn: :pgn

  @default_limit = default_limit

  direction = Builder.define_symbol(:direction, altn: :dir) do
    constrain :enum, [:bfr, :aft]
  end

  limit = Builder.define_integer(:limit, altn: :lmt) do
    constrain Value::OperatorConstraint.new(:>=, MIN_LIMIT), strategy: :clamp
    constrain Value::OperatorConstraint.new(:<=, max_limit), strategy: :clamp unless max_limit.nil?
  end
  add_child(direction)
  add_child(limit)
end

Instance Attribute Details

#default_limitObject (readonly)

Returns the value of attribute default_limit.



185
186
187
# File 'lib/params_ready/pagination/keyset_pagination.rb', line 185

def default_limit
  @default_limit
end

Instance Method Details

#finishObject

Raises:



205
206
207
208
209
# File 'lib/params_ready/pagination/keyset_pagination.rb', line 205

def finish
  keyset = names[:keyset]
  raise ParamsReadyError, "No cursor defined" if keyset.nil? || keyset.names.length < 1
  super
end