graphiti 1.2.17 → 1.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af3b1ec7bee727eb7526b6ce3057576e323f029bdda9f57447021973fa35b2ed
4
- data.tar.gz: 34deda0508ba3d23299272cb387cc19a3f90e90ee1f084b930858488dcf1222b
3
+ metadata.gz: f286647b00c9b97ec5c280e48e4758f31fbee7f00e19d22073b95c8f10956ad6
4
+ data.tar.gz: bf208a2b4971f7603bf287c2cfe4787b36525a8b6612e62a99b3bacd7cd80b45
5
5
  SHA512:
6
- metadata.gz: 649b13c8e55456bfe9a06a9c26cdb36cd345e69137b50afc3c0861b77c334841b5cccb993d1b263986bc2e385e2fb8c28a64c718ff734ccffadb5e3b2d7d76eb
7
- data.tar.gz: f78993e3439b19afb85520c9955415ac03a4332eefc9f683828a2da0cd999b933f07b50df141e1d305ecd3799c9bef3142d4af2020bb356694ce97872b7f80c9
6
+ metadata.gz: 1af7ee296afbe6cf900ceb6e3c7fd4e05fd8b0df81d91b748d2b970fdf77245298e755c024c150cde26e86636c3814a20ab45934b810af8ed501b2ec43449549
7
+ data.tar.gz: f51c1183ede1fd0e4e5aa91ec145b3cd1bc5f7e4633cd61e59232fc6575cb39ca85240fa8590d5b264b29b0522352888b6a7c684cd48a7f4e46b5e47a692155e
@@ -20,13 +20,17 @@ module Graphiti
20
20
 
21
21
  private
22
22
 
23
+ def pagination_params
24
+ @pagination_params ||= @proxy.query.params.reject { |key, _| [:action, :controller, :format].include?(key) }
25
+ end
26
+
23
27
  def pagination_link(page)
24
28
  return nil unless @proxy.resource.endpoint
25
29
 
26
30
  uri = URI(@proxy.resource.endpoint[:url].to_s)
27
31
 
28
32
  # Overwrite the pagination query params with the desired page
29
- uri.query = @proxy.query.hash.merge({
33
+ uri.query = pagination_params.merge({
30
34
  page: {
31
35
  number: page,
32
36
  size: page_size
@@ -148,5 +148,15 @@ module Graphiti
148
148
  end
149
149
  response
150
150
  end
151
+
152
+ def links?
153
+ self.class.links.any?
154
+ end
155
+
156
+ def links(model)
157
+ self.class.links.each_with_object({}) do |(name, blk), memo|
158
+ memo[name] = instance_exec(model, &blk)
159
+ end
160
+ end
151
161
  end
152
162
  end
@@ -199,7 +199,8 @@ module Graphiti
199
199
  attributes: {},
200
200
  extra_attributes: {},
201
201
  sideloads: {},
202
- callbacks: {}
202
+ callbacks: {},
203
+ links: {}
203
204
  }
204
205
  end
205
206
 
@@ -238,6 +239,10 @@ module Graphiti
238
239
  def default_filters
239
240
  config[:default_filters]
240
241
  end
242
+
243
+ def links
244
+ config[:links]
245
+ end
241
246
  end
242
247
 
243
248
  def get_attr!(name, flag, options = {})
@@ -147,6 +147,10 @@ module Graphiti
147
147
  end
148
148
  end
149
149
 
150
+ def link(name, &blk)
151
+ config[:links][name.to_sym] = blk
152
+ end
153
+
150
154
  def all_attributes
151
155
  attributes.merge(extra_attributes)
152
156
  end
@@ -25,6 +25,7 @@ module Graphiti
25
25
  def as_jsonapi(*)
26
26
  super.tap do |hash|
27
27
  strip_relationships!(hash) if strip_relationships?
28
+ add_links!(hash)
28
29
  end
29
30
  end
30
31
 
@@ -49,6 +50,12 @@ module Graphiti
49
50
 
50
51
  private
51
52
 
53
+ def add_links!(hash)
54
+ return unless @resource.respond_to?(:links?)
55
+
56
+ hash[:links] = @resource.links(@object) if @resource.links?
57
+ end
58
+
52
59
  def strip_relationships!(hash)
53
60
  hash[:relationships]&.select! do |name, payload|
54
61
  payload.key?(:data)
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.2.17"
2
+ VERSION = "1.2.18"
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.2.17
4
+ version: 1.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable