Module: LogicalModel::ResponsesConfiguration::ClassMethods

Defined in:
lib/logical_model/responses_configuration.rb

Instance Method Summary collapse

Instance Method Details

#collection_keyObject



26
27
28
# File 'lib/logical_model/responses_configuration.rb', line 26

def collection_key
  @collection_key ||= 'collection'
end

#configure_index_response(hash_response) ⇒ Object

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. If collection is nil then array is expected at root and total will be ignored. If total is nil it will be ignored

Examples:

configure_index_response {collection: 'items', total: 'count'}
This will expect response to have format: {items: [...], count: X}


21
22
23
24
# File 'lib/logical_model/responses_configuration.rb', line 21

def configure_index_response(hash_response)
  @collection_key = hash_response[:collection]
  @total_key      = hash_response[:total]
end

#total_keyObject



30
31
32
# File 'lib/logical_model/responses_configuration.rb', line 30

def total_key
  @total_key ||= 'total'
end