jsonapi_compliable 0.11.1 → 0.11.2

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
  SHA1:
3
- metadata.gz: ff9f3051203426cebee5e62694cf097f0aba942d
4
- data.tar.gz: f427616b68314981ec7dd9d46a5941042e234637
3
+ metadata.gz: 6db73195ae7cc73877b7d3bf32fa81bb89f0e747
4
+ data.tar.gz: 186d279c3221ab57bf08ab86145bac235c621c17
5
5
  SHA512:
6
- metadata.gz: 2ec6bf442ea94a3213137860adf61e12aff5a29897a1eebee53850c1f69a927ba636c8ad98bf4523adcc976182777abdc314ff75af165e80d7e3d65110b2cca3
7
- data.tar.gz: 0ade2b736330f5267b58d97c10ad669ec285d25fffc705436d3398b5869ea2e7d07eabcb81b0767109a8898fdc24a6e23ccf6d2ea7a4280963d02e8a246a2b09
6
+ metadata.gz: df42aaa0b32e2fdb0aa6c1dd288fb93765e8d52bc48ba676751c280c96b1a6ee81348ec75bad9a2b08cd9e02e73e6905c10057ba8c69634cc2e39d788d68a0d4
7
+ data.tar.gz: d60190e16b515697be4b6167034815d1f265c753cb7e2bf57c9345f2a1d592b83f1a1b2cc9289750a6008f01be6daed66d8147047caaed09c4bf99894aa03b30
File without changes
@@ -487,7 +487,7 @@ module JsonapiCompliable
487
487
  # @see .model
488
488
  # @see Adapters::ActiveRecord#update
489
489
  # @param [Hash] update_params The relevant attributes, including id and foreign keys
490
- # @return [Object] an instance of the just-created model
490
+ # @return [Object] an instance of the just-updated model
491
491
  def update(update_params)
492
492
  adapter.update(model, update_params)
493
493
  end
@@ -507,7 +507,7 @@ module JsonapiCompliable
507
507
  # @see .model
508
508
  # @see Adapters::ActiveRecord#destroy
509
509
  # @param [String] id The +id+ of the relevant Model
510
- # @return [Object] an instance of the just-created model
510
+ # @return [Object] an instance of the just-destroyed model
511
511
  def destroy(id)
512
512
  adapter.destroy(model, id)
513
513
  end
@@ -38,7 +38,7 @@ module JsonapiCompliable
38
38
  def apply
39
39
  resource.default_filters.each_pair do |name, opts|
40
40
  next if overridden?(name)
41
- @scope = opts[:filter].call(@scope)
41
+ @scope = opts[:filter].call(@scope, resource.context)
42
42
  end
43
43
 
44
44
  @scope
@@ -35,7 +35,7 @@ module JsonapiCompliable
35
35
  # @return the scope object we are chaining/modofying
36
36
  def apply
37
37
  each_extra_field do |callable|
38
- @scope = callable.call(@scope)
38
+ @scope = callable.call(@scope, resource.context)
39
39
  end
40
40
 
41
41
  @scope
@@ -41,7 +41,7 @@ module JsonapiCompliable
41
41
  # specified in the adapter.
42
42
  def filter_scope(filter, value)
43
43
  if custom_scope = filter.values.first[:filter]
44
- custom_scope.call(@scope, value)
44
+ custom_scope.call(@scope, value, resource.context)
45
45
  else
46
46
  resource.adapter.filter(@scope, filter.keys.first, value)
47
47
  end
@@ -52,8 +52,31 @@ module JsonapiCompliable
52
52
  filter = find_filter!(param_name.to_sym)
53
53
  value = param_value
54
54
  value = value.split(',') if value.is_a?(String) && value.include?(',')
55
+ value = normalize_string_values(value)
55
56
  yield filter, value
56
57
  end
57
58
  end
59
+
60
+ # Convert a string of "true" to true, etc
61
+ #
62
+ # NB - avoid Array(value) here since we might want to
63
+ # return a single element instead of array
64
+ def normalize_string_values(value)
65
+ if value.is_a?(Array)
66
+ value.map { |v| normalize_string_value(v) }
67
+ else
68
+ normalize_string_value(value)
69
+ end
70
+ end
71
+
72
+ def normalize_string_value(value)
73
+ case value
74
+ when 'true' then true
75
+ when 'false' then false
76
+ when 'nil', 'null' then nil
77
+ else
78
+ value
79
+ end
80
+ end
58
81
  end
59
82
  end
@@ -61,7 +61,7 @@ module JsonapiCompliable
61
61
 
62
62
  # Apply the custom pagination proc
63
63
  def apply_custom_scope
64
- custom_scope.call(@scope, number, size)
64
+ custom_scope.call(@scope, number, size, resource.context)
65
65
  end
66
66
 
67
67
  private
@@ -31,7 +31,8 @@ module JsonapiCompliable
31
31
  # @return the scope we are chaining/modifying
32
32
  def apply_custom_scope
33
33
  each_sort do |attribute, direction|
34
- @scope = custom_scope.call(@scope, attribute, direction)
34
+ @scope = custom_scope
35
+ .call(@scope, attribute, direction, resource.context)
35
36
  end
36
37
  @scope
37
38
  end
@@ -1,3 +1,3 @@
1
1
  module JsonapiCompliable
2
- VERSION = "0.11.1"
2
+ VERSION = "0.11.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_compliable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-01-13 00:00:00.000000000 Z
12
+ date: 2018-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-serializable
@@ -202,6 +202,7 @@ files:
202
202
  - gemfiles/rails_4.gemfile
203
203
  - gemfiles/rails_5.gemfile
204
204
  - jsonapi_compliable.gemspec
205
+ - lib/generators/jsonapi/field_generator.rb
205
206
  - lib/generators/jsonapi/resource_generator.rb
206
207
  - lib/generators/jsonapi/templates/application_resource.rb.erb
207
208
  - lib/generators/jsonapi/templates/controller.rb.erb