Sha256: 3ea66a6d39f0aa6a7f3e87c366dd7bcb56adb1953bebc88d2dcf36b98c92eb7e

Contents?: true

Size: 974 Bytes

Versions: 64

Compression:

Stored size: 974 Bytes

Contents

require 'active_support'

class LHS::Record

  # Allows configuring endpoints
  # like which keys are used for the items, offset, total etc.
  module Configuration
    extend ActiveSupport::Concern

    mattr_accessor :configuration

    module ClassMethods
      def configuration(args)
        @configuration = args.freeze || {}
      end

      def items_key
        (@configuration.try(:[], :items_key) || :items).to_sym
      end

      def limit_key
        (@configuration.try(:[], :limit_key) || :limit).to_sym
      end

      def total_key
        (@configuration.try(:[], :total_key) || :total).to_sym
      end

      # Key used for determine current page
      def pagination_key
        (@configuration.try(:[], :pagination_key) || :offset).to_sym
      end

      # Strategy used for calculationg next pages and navigate pages
      def pagination_strategy
        (@configuration.try(:[], :pagination_strategy) || :offset).to_sym
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
lhs-7.2.1 lib/lhs/concerns/record/configuration.rb
lhs-7.2.0 lib/lhs/concerns/record/configuration.rb
lhs-7.1.0 lib/lhs/concerns/record/configuration.rb
lhs-7.0.3 lib/lhs/concerns/record/configuration.rb
lhs-7.0.2 lib/lhs/concerns/record/configuration.rb
lhs-7.0.1 lib/lhs/concerns/record/configuration.rb
lhs-7.0.0 lib/lhs/concerns/record/configuration.rb
lhs-6.8.2 lib/lhs/concerns/record/configuration.rb
lhs-6.8.1 lib/lhs/concerns/record/configuration.rb
lhs-6.8.0 lib/lhs/concerns/record/configuration.rb
lhs-6.7.2 lib/lhs/concerns/record/configuration.rb
lhs-6.7.1 lib/lhs/concerns/record/configuration.rb
lhs-6.7.0 lib/lhs/concerns/record/configuration.rb
lhs-6.6.2 lib/lhs/concerns/record/configuration.rb
lhs-6.6.1 lib/lhs/concerns/record/configuration.rb
lhs-6.6.0 lib/lhs/concerns/record/configuration.rb
lhs-6.5.0 lib/lhs/concerns/record/configuration.rb
lhs-6.4.0 lib/lhs/concerns/record/configuration.rb
lhs-6.3.1 lib/lhs/concerns/record/configuration.rb
lhs-6.3.0 lib/lhs/concerns/record/configuration.rb