Sha256: 7ab10c2c37942863bc0df84ff60bde44c287500316122ad3ba88fc0692db5108

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 KB

Contents

class LogicalModel
  module ResponsesConfiguration

    def self.included(base)
      base.send(:extend, ClassMethods)
    end

    module ClassMethods
      # By default paginate and all will expect a response in the format:
      # { collection: [....], total: X }
      # Where collection contains an array of hashes that initialize the Object and
      # total contains the total number of elements in result (used for pagination)
      #
      # configure_index_response allows to change this defaults.
      # @example
      #    configure_index_response {collection: 'items', total: 'count'}
      #    This will expect response to have format: {items: [...], count: X}
      #
      # If collection is nil then array is expected at root and total will be ignored.
      # If total is nil it will be ignored
      def configure_index_response(hash_response)
        @collection_key = hash_response[:collection]
        @total_key      = hash_response[:total]
      end

      def collection_key
        @collection_key ||= 'collection'
      end

      def total_key
        @total_key ||= 'total'
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
logical_model-0.7.6 lib/logical_model/responses_configuration.rb
logical_model-0.7.5 lib/logical_model/responses_configuration.rb
logical_model-0.7.4 lib/logical_model/responses_configuration.rb
logical_model-0.7.3 lib/logical_model/responses_configuration.rb
logical_model-0.7.2 lib/logical_model/responses_configuration.rb
logical_model-0.7.1 lib/logical_model/responses_configuration.rb
logical_model-0.7.0 lib/logical_model/responses_configuration.rb
logical_model-0.6.6 lib/logical_model/responses_configuration.rb
logical_model-0.6.5 lib/logical_model/responses_configuration.rb
logical_model-0.6.4 lib/logical_model/responses_configuration.rb
logical_model-0.6.3 lib/logical_model/responses_configuration.rb
logical_model-0.6.2 lib/logical_model/responses_configuration.rb
logical_model-0.6.1 lib/logical_model/responses_configuration.rb
logical_model-0.6.0 lib/logical_model/responses_configuration.rb
logical_model-0.5.13 lib/logical_model/responses_configuration.rb
logical_model-0.5.12 lib/logical_model/responses_configuration.rb
logical_model-0.5.11 lib/logical_model/responses_configuration.rb
logical_model-0.5.10 lib/logical_model/responses_configuration.rb
logical_model-0.5.8 lib/logical_model/responses_configuration.rb
logical_model-0.5.7 lib/logical_model/responses_configuration.rb