graphiti 1.0.rc.6 → 1.0.rc.7

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: f971a82f6fc8d3493a4ad0ddbd0856664afca53a
4
- data.tar.gz: c093f5b9a3659de79095d57bec4185995a5f2c04
3
+ metadata.gz: 64397d57cb7c6414bb46e577ab78b0a603d1873a
4
+ data.tar.gz: 9feb0b39e7dce3d6a6899e1b78495b97bd53509a
5
5
  SHA512:
6
- metadata.gz: 456137cd5a1b0c8e30b1841775e1ac26ffc4987fe4f9976a2584d27d52626fbcf3cc9cabf3d30878fb3eee6a8c266435a0c306ac8866f110ef495bf55b9e7771
7
- data.tar.gz: af6b86c27306a98f14262b09d3f4bca32dbdc45e01407566884cd71b1a12e4a16d84fb864e4b10923d7959ab5a397ce940bdd7ae588cd4b5515e27713c91b7a3
6
+ metadata.gz: f9a163bee97a77e99ad461cc5ebf48c1bdab164e1308fb0bdb13e96eb4ec9036b0e9bfc916ebe1e67ac5a5df5fea7360baef7afaf6fc37cc9132f92569988cc4
7
+ data.tar.gz: 44fc30042c0cbc1567b1127ebffa09c538a56dd8e0884dd23ed63d1bfbce6489e3c7d6de1f707fe6378e36bc95d09aede3646d76c47276eb2999e9c58e2af3df
@@ -15,9 +15,24 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
15
15
  class Grouper
16
16
  attr_reader :field_name
17
17
 
18
- def initialize(field_name)
18
+ def initialize(field_name, opts={})
19
19
  @field_name = field_name
20
20
  @groups = []
21
+ @except = Array(opts[:except]).map(&:to_sym)
22
+ @only = Array(opts[:only]).map(&:to_sym)
23
+ end
24
+
25
+ def expected?(group_sym)
26
+ @only.empty? || @only.include?(group_sym)
27
+ end
28
+
29
+ def excluded?(group_sym)
30
+ @except.include?(group_sym)
31
+ end
32
+
33
+ def ignore?(group_name)
34
+ group_sym = group_name.to_sym
35
+ !expected?(group_sym) || excluded?(group_sym)
21
36
  end
22
37
 
23
38
  def on(name, &blk)
@@ -61,8 +76,8 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
61
76
  :"#{name}_id"
62
77
  end
63
78
 
64
- def self.group_by(name, &blk)
65
- self.grouper = Grouper.new(name)
79
+ def self.group_by(name, opts={}, &blk)
80
+ self.grouper = Grouper.new(name, opts)
66
81
  self.grouper.instance_eval(&blk)
67
82
  end
68
83
 
@@ -80,7 +95,7 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
80
95
 
81
96
  def resolve(parents, query, graph_parent)
82
97
  parents.group_by(&grouper.field_name).each_pair do |group_name, group|
83
- next if group_name.nil?
98
+ next if group_name.nil? || grouper.ignore?(group_name)
84
99
 
85
100
  match = ->(c) { c.group_name == group_name.to_sym }
86
101
  if sideload = children.values.find(&match)
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.rc.6"
2
+ VERSION = "1.0.rc.7"
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.rc.6
4
+ version: 1.0.rc.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-23 00:00:00.000000000 Z
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable