api_me 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed39f052b8ffaff2339bce75592a4ba2ee371c451e496411333e3b472711be9d
4
- data.tar.gz: d24e777c24e9df8348937da77af6251f1e5a03e85e080cf48639a0e7a2ed0e1b
3
+ metadata.gz: 6edbf66319db35e695cd3b4b686e3b5688a2c2fe56d108eb954976732bc11bb5
4
+ data.tar.gz: 6063c1ca77185b64178360c103f6c3511b6fe9652575ee00da2a99d97d626dfc
5
5
  SHA512:
6
- metadata.gz: 4fef805b6c67b1d45e623e95386cda60de7ec62dd71cfb5590b4f7bd3c00b65e9ece521686e7c2a18d03eeb42fc0b91ae61b0e3c49fc7e69951d75b404142a95
7
- data.tar.gz: 60ace944bf79b1c168c32f471335f72a997b8bf3c868e2198a45a3cadbc8080eb2a85de09624e29d2edb97736f18c97b022adc7bf7537be476a80652a18be6dc
6
+ metadata.gz: d08b61cc42bcaa27102961bea0b54c651e1fa18adbc7034d69531147076e1acdcd5fd09204c83741880b8b527a6269d0ee2634e339159910dd043a7b8bb664c4
7
+ data.tar.gz: 7c610c2d85ca5009c265c1456e9c3e21d653a762e933ce8f00d6f245dd2efa57fa480c9feee608a9c52a4ff2299bb3f4ed6fd60b471989fb9071e04ffca37589
@@ -235,11 +235,11 @@ module ApiMe
235
235
  end
236
236
 
237
237
  def create_resource!
238
- @object.save!(object_params)
238
+ @object.save!
239
239
  end
240
240
 
241
241
  def update_resource!
242
- @object.save!(object_params)
242
+ @object.save!
243
243
  end
244
244
 
245
245
  def destroy_resource!
@@ -2,13 +2,16 @@
2
2
 
3
3
  module ApiMe
4
4
  class Sorting
5
- attr_accessor :sort_criteria, :sort_reverse, :scope
5
+ attr_accessor :sort_criteria, :sort_reverse, :scope, :custom_sort_options
6
6
 
7
- def initialize(scope:, sort_params:)
7
+ def initialize(scope:, sort_params:, custom_sort_options: {})
8
8
  self.scope = scope
9
+
9
10
  return unless sort_params
11
+
10
12
  self.sort_criteria = sort_params[:criteria] || default_sort_criteria
11
13
  self.sort_reverse = sort_params[:reverse] || false
14
+ self.custom_sort_options = custom_sort_options
12
15
  end
13
16
 
14
17
  def results
@@ -39,7 +42,14 @@ module ApiMe
39
42
  end
40
43
 
41
44
  def sorted_scope(criteria)
42
- if sort_reverse === 'true'
45
+ criteria_key = criteria.to_sym
46
+ if custom_sort_options.key?(criteria_key)
47
+ if sort_reverse == 'true'
48
+ custom_sort_scope(criteria_key).order(Arel.sql("#{custom_sort_options[criteria_key][:column]} DESC"))
49
+ else
50
+ custom_sort_scope(criteria_key).order(Arel.sql("#{custom_sort_options[criteria_key][:column]} ASC"))
51
+ end
52
+ elsif sort_reverse == 'true'
43
53
  scope.order(criteria => :desc)
44
54
  else
45
55
  scope.order(criteria => :asc)
@@ -48,6 +58,10 @@ module ApiMe
48
58
 
49
59
  private
50
60
 
61
+ def custom_sort_scope(criteria)
62
+ custom_sort_options[criteria].key?(:joins) ? scope.joins(custom_sort_options[criteria][:joins]) : scope
63
+ end
64
+
51
65
  def default_sort_criteria
52
66
  'id'
53
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiMe
4
- VERSION = '0.12.0'
4
+ VERSION = '0.13.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Clopton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-13 00:00:00.000000000 Z
12
+ date: 2020-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  version: '0'
200
200
  requirements: []
201
201
  rubyforge_project:
202
- rubygems_version: 2.7.6
202
+ rubygems_version: 2.7.6.2
203
203
  signing_key:
204
204
  specification_version: 4
205
205
  summary: Api Me