Module: RestPack::Service

Defined in:
lib/restpack-resource/service.rb

Instance Method Summary collapse

Instance Method Details

#paged_resource(klass, params, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/restpack-resource/service.rb', line 6

def paged_resource(klass, params, options = {})
  options[:page] ||= params['page'].to_i if params['page']
  options[:includes] ||= extract_includes_from_params(params) unless params['includes'].nil?
  options[:sort_by] ||= params['sort_by'].to_sym if params['sort_by']
  options[:sort_direction] ||= params['sort_direction'].to_sym if params['sort_direction']
  
  filters = extract_filters_from_params(klass, params)
  options[:filters] ||= filters unless filters.empty?

  klass.paged_resource(options)
end

#single_resource(klass, params, options = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/restpack-resource/service.rb', line 18

def single_resource(klass, params, options = {})      
  options[:id] ||= params['id'] if params['id']
  options[:includes] ||= extract_includes_from_params(params) unless params['includes'].nil?
  
  klass.single_resource(options)
end