graphiti 1.0.beta.14 → 1.0.beta.15

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: b4ff13da582bf6e68e92f1b694d9fe17e4674e49
4
- data.tar.gz: ff7d0c4a107bfaa7680edcc821572df7a3a38c1a
3
+ metadata.gz: e06792e034635555f5687496aebef2ed8e0eac93
4
+ data.tar.gz: c3d10077cc25cff01a1adf79059dc3c3b6ee213d
5
5
  SHA512:
6
- metadata.gz: 32f81168be3c5b9207c0a8d5143f2efbaff904aade2161dea0cbf4af9f19b723a43f725283dce5116ae3cd30a3a46ff678d55f7cedea0f134b29a7faacfa41e1
7
- data.tar.gz: 9cb0bb2e85f0d98555ad5f2092a4800758e84377221e4ef47666f70c2966414f76376e8068dbb2871ea5c18d2ca89c21c5c50415ff311768ac0eeb57f35da486
6
+ metadata.gz: 4cba835660dc04c71d333703860acd47eb408a463bc1cdb5c4d29d75d0904ee680fddceb6497490fd4c47effaadef6bd65ddb3285984931f999d950073e8a894
7
+ data.tar.gz: 1d3f3b288997909c4763966ce32dab8cf4998f56a29122c630a3f953741e471d2bb5bcfa56676c710007f2a51eaff1948593d5619270c4f606093fa5ce886052
@@ -207,8 +207,8 @@ module Graphiti
207
207
 
208
208
  children.each do |child|
209
209
  if association_type == :many_to_many &&
210
- !parent.send(association_name).exists?(child.id) &&
211
- [:create, :update].include?(Graphiti.context[:namespace])
210
+ [:create, :update].include?(Graphiti.context[:namespace]) &&
211
+ !parent.send(association_name).exists?(child.id)
212
212
  parent.send(association_name) << child
213
213
  else
214
214
  target = association.instance_variable_get(:@target)
@@ -45,7 +45,7 @@ class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload:
45
45
 
46
46
  def parent_reflection
47
47
  parent_model = parent_resource_class.model
48
- parent_model.reflections[name.to_s]
48
+ parent_model.reflections[association_name.to_s]
49
49
  end
50
50
 
51
51
  def infer_foreign_key
@@ -16,6 +16,21 @@ The adapter #{@adapter.class} does not implement method '#{@method}', which was
16
16
  end
17
17
  end
18
18
 
19
+ class UnsupportedOperator < Base
20
+ def initialize(resource, filter_name, supported, operator)
21
+ @resource = resource
22
+ @filter_name = filter_name
23
+ @supported = supported
24
+ @operator = operator
25
+ end
26
+
27
+ def message
28
+ <<-MSG
29
+ #{@resource.class}: Tried to filter #{@filter_name.inspect} on operator #{@operator.inspect}, but not supported! Supported operators are #{@supported}.
30
+ MSG
31
+ end
32
+ end
33
+
19
34
  class UnwritableRelationship < Base
20
35
  def initialize(resource, sideload)
21
36
  @resource = resource
@@ -44,11 +44,11 @@ module Graphiti
44
44
  def to_hash(serializers, opts)
45
45
  {}.tap do |hash|
46
46
  if serializers.is_a?(Array)
47
- hash[@resource.type] = serializers.map do |s|
47
+ hash[:data] = serializers.map do |s|
48
48
  s.to_hash(opts)
49
49
  end
50
50
  else
51
- hash[@resource.type] = serializers.to_hash(opts)
51
+ hash[:data] = serializers.to_hash(opts)
52
52
  end
53
53
  end
54
54
  end
@@ -152,7 +152,7 @@ module Graphiti
152
152
  hash[k.to_sym] = v.to_i
153
153
  end
154
154
  elsif nested?(name)
155
- hash.merge!(value)
155
+ hash[name.to_s.split('.').last.to_sym] = value
156
156
  elsif top_level? && [:number, :size].include?(name.to_sym)
157
157
  hash[name.to_sym] = value.to_i
158
158
  end
@@ -73,6 +73,7 @@ module Graphiti
73
73
  filter_param.each_pair do |param_name, param_value|
74
74
  filter = find_filter!(param_name)
75
75
  value, operator = normalize_param(filter, param_value)
76
+ validate_operator(filter, operator)
76
77
  value = parse_string_value(filter.values[0], value) if value.is_a?(String)
77
78
  validate_singular(resource, filter, value)
78
79
  value = coerce_types(filter.values[0], param_name.to_sym, value)
@@ -111,6 +112,14 @@ module Graphiti
111
112
  [value, operator]
112
113
  end
113
114
 
115
+ def validate_operator(filter, operator)
116
+ supported = filter.values[0][:operators].keys
117
+ unless supported.include?(operator)
118
+ raise Errors::UnsupportedOperator.new \
119
+ resource, filter.keys[0], supported, operator
120
+ end
121
+ end
122
+
114
123
  def validate_singular(resource, filter, value)
115
124
  if filter.values[0][:single] && value.is_a?(Array)
116
125
  raise Errors::SingularFilter.new(resource, filter, value)
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.beta.14"
2
+ VERSION = "1.0.beta.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.beta.14
4
+ version: 1.0.beta.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-12 00:00:00.000000000 Z
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable