Sha256: e3abb95fb3dcc239ecd18a7f7f790eb8a08309fbf2b434d27cdd7c2e444682e3

Contents?: true

Size: 1017 Bytes

Versions: 14

Compression:

Stored size: 1017 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

    DEFAULT_ITEMS_KEY = :items

    mattr_accessor :configuration

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

      def items_key
        (@configuration.try(:[], :items_key) || DEFAULT_ITEMS_KEY).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

14 entries across 14 versions & 1 rubygems

Version Path
lhs-12.0.3 lib/lhs/concerns/record/configuration.rb
lhs-12.0.2 lib/lhs/concerns/record/configuration.rb
lhs-12.0.1 lib/lhs/concerns/record/configuration.rb
lhs-12.0.0 lib/lhs/concerns/record/configuration.rb
lhs-11.3.3 lib/lhs/concerns/record/configuration.rb
lhs-11.3.2 lib/lhs/concerns/record/configuration.rb
lhs-11.3.1 lib/lhs/concerns/record/configuration.rb
lhs-11.3.0 lib/lhs/concerns/record/configuration.rb
lhs-11.2.2 lib/lhs/concerns/record/configuration.rb
lhs-11.2.1 lib/lhs/concerns/record/configuration.rb
lhs-11.2.0 lib/lhs/concerns/record/configuration.rb
lhs-11.1.0 lib/lhs/concerns/record/configuration.rb
lhs-11.0.3 lib/lhs/concerns/record/configuration.rb
lhs-11.0.2 lib/lhs/concerns/record/configuration.rb