Class: ParamsReady::Pagination::OffsetPaginationDefinition
- Inherits:
-
ParamsReady::Parameter::TupleParameterDefinition
- Object
- ParamsReady::Parameter::AbstractDefinition
- ParamsReady::Parameter::Definition
- ParamsReady::Parameter::TupleParameterDefinition
- ParamsReady::Pagination::OffsetPaginationDefinition
- Defined in:
- lib/params_ready/pagination/offset_pagination.rb
Constant Summary collapse
- MIN_LIMIT =
1
Instance Attribute Summary
Attributes inherited from ParamsReady::Parameter::Definition
Attributes inherited from ParamsReady::Parameter::AbstractDefinition
Instance Method Summary collapse
-
#initialize(default_offset, default_limit, max_limit = nil) ⇒ OffsetPaginationDefinition
constructor
A new instance of OffsetPaginationDefinition.
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
Methods included from Extensions::ClassReaderWriter
Methods included from Extensions::LateInit
Methods included from Extensions::Collection
Methods included from Extensions::Finalizer::InstanceMethods
Methods included from Extensions::Freezer::InstanceMethods
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 |