Class: ParamsReady::Pagination::OffsetPaginationDefinition

Inherits:
ParamsReady::Parameter::TupleParameterDefinition show all
Defined in:
lib/params_ready/pagination/offset_pagination.rb

Constant Summary collapse

MIN_LIMIT =
1

Instance Attribute Summary

Attributes inherited from ParamsReady::Parameter::Definition

#default

Attributes inherited from ParamsReady::Parameter::AbstractDefinition

#altn, #name

Instance Method Summary collapse

Methods inherited from ParamsReady::Parameter::TupleParameterDefinition

#add_fields, #arity, #ensure_canonical, #freeze

Methods included from ParamsReady::Parameter::ArrayParameterDefinition::ArrayLike

#duplicate_value, #freeze_value

Methods inherited from ParamsReady::Parameter::Definition

#canonical_default, #default_defined?, #fetch_callable_default, #fetch_default, #finish, #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, #finish, #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::Finalizer::InstanceMethods

#finish

Methods included from Extensions::Freezer::InstanceMethods

#freeze

Constructor Details

#initialize(default_offset, default_limit, max_limit = nil) ⇒ OffsetPaginationDefinition

Returns a new instance of OffsetPaginationDefinition.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/params_ready/pagination/offset_pagination.rb', line 114

def initialize(default_offset, default_limit, max_limit = nil)
  offset = Builder.define_integer(:offset, altn: :off) do
    constrain Value::OperatorConstraint.new(:>=, 0), strategy: :clamp
  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
  super :pagination,
        altn: :pgn,
        marshaller: { using: :string, separator: '-' },
        fields: [offset, limit],
        default: [default_offset, default_limit]
end