standardapi 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/standard_api/orders.rb +8 -53
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f3dd80946f83f6fd0512ec5a1b18053006c30ee
4
- data.tar.gz: c0942e8eda944f221b15ba0fc39d897701128256
3
+ metadata.gz: aba7eb96fbb3c8dba47890e2871e70648bdda2e4
4
+ data.tar.gz: 0bf9b3de2a4122a8c091e8b34a177dd6911d0cd7
5
5
  SHA512:
6
- metadata.gz: 3e268419011bfa400dee7027e2ac961069f8f4beefc28a90e5b441577914552f2c01d992d6ec95cb0e22057cef29de9997b76a07a69310c737f77825b538c4f8
7
- data.tar.gz: a851e18f2e1491d0df72e8b5352da579ae59a4fd340617940e6609cac2a46fcaea75cdba7930b37328a1ecf4bc2f5bbfb3abc6be53d44b2d6c67b9d2ab624951
6
+ metadata.gz: fbd2ce6353c85738279cb7ceb455c462e1df71fe47b51d445500c6b2f278cd9a739731dce3f00e004c0a74baf9759f2eaf34702579d64e3ad0fde9c88ab8ac06
7
+ data.tar.gz: 455c0199f0ad92ed61581397ab53623c06b814f3c0b2ae5cdd07fe774df5aac00dec561765c3e712e16669ffe2e2e09d3c3bf3852df04536f53835f6ff339370
@@ -1,55 +1,8 @@
1
1
  module StandardAPI
2
2
  module Orders
3
3
 
4
- # # :size => [:size]
5
- # # { :size => :asc } => [{:size => :asc}]
6
- # # { :size => :desc } => [{:size => :desc}]
7
- # # {:size => {:desc => :nulls_first}} => [{:size => {:desc => :nulls_first}}]
8
- # # [:size, :id] => [:size, :id]
9
- # # { :size => :asc, :id => :desc } => [{ :size => :asc, :id => :desc }]
10
- # # 'listings.size' => [{:listings => [:size]}]
11
- # # { 'listings.size' => :asc } => [{:listings => [{:size => :asc}]}]
12
- # # { 'listings.size' => :desc } => [{:listings => [{:size => :desc}]}]
13
- # # ['listings.size', 'property.id'] => [{:listings => [:size]}, {:property => [:id]}]
14
- # # { 'size' => :asc, 'property.id' => :desc } => [{:size => :asc}, {:property => [{:id => :desc}]}]
15
- # # { :size => {:asc => :nulls_first}, 'property.id' => {:desc => :null_last} } => [{:size => {:asc => :nulls_first}}, {:property => [{:id => {:desc => :nulls_first}}]}]
16
- def self.normalize(orderings)
17
- return nil if orderings.nil?
18
- orderings = orderings.is_a?(Array) ? orderings : [orderings]
19
-
20
- orderings.map! do |order|
21
- case order
22
- when Hash
23
- normalized = ActiveSupport::HashWithIndifferentAccess.new
24
- order.each do |key, value|
25
- key = key.to_s
26
- if key.index(".")
27
- relation, column = key.split('.').map(&:to_sym)
28
- normalized[relation] ||= []
29
- normalized[relation] << { column => value }
30
- elsif value.is_a?(Hash) && value.keys.first.to_s != 'desc' && value.keys.first.to_s != 'asc'
31
- normalized[key.to_sym] ||= []
32
- normalized[key.to_sym] << value
33
- else
34
- normalized[key.to_sym] = value
35
- end
36
- end
37
- normalized
38
- else
39
- order = order.to_s
40
- if order.index(".")
41
- relation, column = order.split('.').map(&:to_sym)
42
- { relation => [column] }
43
- else
44
- order.to_sym
45
- end
46
- end
47
- end
48
- end
49
-
50
- def self.sanitize(orders, permit, normalized=false)
4
+ def self.sanitize(orders, permit)
51
5
  return nil if orders.nil?
52
- orders = StandardAPI::Orders.normalize(orders) if !normalized
53
6
 
54
7
  permit = [permit] if !permit.is_a?(Array)
55
8
  permit = permit.flatten.map { |x| x.is_a?(Hash) ? x.with_indifferent_access : x.to_s }
@@ -63,19 +16,21 @@ module StandardAPI
63
16
  permitted = { key.to_sym => value }
64
17
  elsif permit.find { |x| x.is_a?(Hash) && x.has_key?(key.to_s) }
65
18
  subpermit = permit.find { |x| x.is_a?(Hash) && x.has_key?(key.to_s) }[key.to_s]
66
- sanitized_value = sanitize(value, subpermit, true)
19
+ sanitized_value = sanitize(value, subpermit)
67
20
  permitted = { key.to_sym => sanitized_value }
68
21
  else
69
22
  raise(ActionDispatch::ParamsParser::ParseError.new("Invalid Ordering #{orders.inspect}", nil))
70
23
  end
71
24
  end
72
25
  when Array
73
- orders.each { |order| permitted << sanitize(order, permit, true); }
26
+ orders.each { |order| permitted << sanitize(order, permit); }
74
27
  else
75
- if permit.include?(orders.to_s)
28
+
29
+ if orders.to_s.count('.') == 1
30
+ key, value = *orders.to_s.split('.')
31
+ permitted = sanitize({key.to_sym => value.to_sym}, permit)
32
+ elsif permit.include?(orders.to_s)
76
33
  permitted = orders
77
- # elsif permit.split('.').size == 2
78
- # sanitize({permit.split('.')[0] => permit.split('.')[1]}, permit)
79
34
  else
80
35
  raise(ActionDispatch::ParamsParser::ParseError.new("Invalid Ordering #{orders.inspect}", nil))
81
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standardapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bracy