graphiti 1.0.alpha.9 → 1.0.alpha.10

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: caacb7b46b4b6380d1202102d599ea89292883e4
4
- data.tar.gz: e1817089ad066f588c1b7b4d43e595e923bd93fc
3
+ metadata.gz: d73c18bd56aa9ce3103c3e1be9d6aa53df14d246
4
+ data.tar.gz: da7f2ff960fb4592610dfb6ea30a5ff981378bda
5
5
  SHA512:
6
- metadata.gz: c77ef723750a6220eafec17a1312886c75cb20e60fda62ea1a648916c8ddedf4f670abd0be7b7a62806755036aa674f78bb8ec98e587df2c8304e6c89c678d33
7
- data.tar.gz: 97aa9cf93a8af91459b402b2379c81a461330fd47a467c5eb79a4a768569a6c15ba4ad2238f08bb41d7563607918d7b30c2dfdc2be5197e8d97cfaf77a3f6fe0
6
+ metadata.gz: 69a8290f78ca0abcee5971e6ffec58c3884d9f81a44f5b2bb59967cfb18311cb9274ad3329689b31c338586347fa2089df0d82e136d1d74a91c2073d591062a3
7
+ data.tar.gz: ac000566edc5afc1c05af3db4a179454a9766da798995b3c35fcdda9bc01bbff40d697b598c217b39619378a8052f56c7961e931c44ced3663361e9950409503
@@ -12,6 +12,7 @@ module Graphiti
12
12
  attr_accessor :context_for_endpoint
13
13
  attr_accessor :schema_path
14
14
  attr_accessor :links_on_demand
15
+ attr_accessor :typecast_reads
15
16
 
16
17
  # Set defaults
17
18
  # @api private
@@ -20,6 +21,7 @@ module Graphiti
20
21
  @concurrency = false
21
22
  @respond_to = [:json, :jsonapi, :xml]
22
23
  @links_on_demand = false
24
+ @typecast_reads = true
23
25
 
24
26
  if defined?(::Rails)
25
27
  @schema_path = "#{::Rails.root}/public/schema.json"
@@ -35,25 +35,6 @@ module Graphiti
35
35
  end
36
36
  end
37
37
 
38
- # Temporary fix until fixed upstream
39
- # https://github.com/jsonapi-rb/jsonapi-serializable/pull/102
40
- module ResourceOverrides
41
- def requested_relationships(fields)
42
- @_relationships
43
- end
44
-
45
- # Allow access to resource methods
46
- def method_missing(id, *args, &blk)
47
- if @resource.respond_to?(id, true)
48
- @resource.send(id, *args, &blk)
49
- else
50
- super
51
- end
52
- end
53
- end
54
-
55
- JSONAPI::Serializable::Resource
56
- .send(:prepend, ResourceOverrides)
57
38
  JSONAPI::Serializable::Relationship
58
39
  .send(:prepend, RelationshipOverrides)
59
40
  JSONAPI::Serializable::Renderer
@@ -25,9 +25,11 @@ module Graphiti
25
25
  end
26
26
 
27
27
  def decorate_record(record)
28
- serializer = serializer_for(record)
29
- record.instance_variable_set(:@__graphiti_serializer, serializer)
30
- record.instance_variable_set(:@__graphiti_resource, self)
28
+ unless record.instance_variable_get(:@__graphiti_serializer)
29
+ serializer = serializer_for(record)
30
+ record.instance_variable_set(:@__graphiti_serializer, serializer)
31
+ record.instance_variable_set(:@__graphiti_resource, self)
32
+ end
31
33
  end
32
34
 
33
35
  def with_context(object, namespace = nil)
@@ -75,7 +75,12 @@ module Graphiti
75
75
  _resource = @resource.new
76
76
  _typecast = typecast(Graphiti::Types[@attr[:type]][:read])
77
77
  ->(_) {
78
- _typecast.call(@object.send(_name))
78
+ val = @object.send(_name)
79
+ if Graphiti.config.typecast_reads
80
+ _typecast.call(val)
81
+ else
82
+ val
83
+ end
79
84
  }
80
85
  end
81
86
 
@@ -84,7 +89,12 @@ module Graphiti
84
89
  _name = @name
85
90
  _typecast = typecast(Graphiti::Types[@attr[:type]][:read])
86
91
  ->(serializer_instance = nil) {
87
- _typecast.call(serializer_instance.instance_eval(&inner))
92
+ val = serializer_instance.instance_eval(&inner)
93
+ if Graphiti.config.typecast_reads
94
+ _typecast.call(val)
95
+ else
96
+ val
97
+ end
88
98
  }
89
99
  end
90
100
 
@@ -38,21 +38,40 @@ module Graphiti
38
38
  private
39
39
 
40
40
  def block
41
- if link?
41
+ if _link = link?
42
42
  validate_link! unless @sideload.link_proc
43
- sl = @sideload
44
- proc do
43
+ end
44
+
45
+ _sl = @sideload
46
+ _data_proc = data_proc
47
+ proc do
48
+ data { instance_eval(&_data_proc) }
49
+
50
+ if _link
45
51
  if @proxy.query.links?
46
52
  link(:related) do
47
- ::Graphiti::Util::Link.new(sl, @object).generate
53
+ ::Graphiti::Util::Link.new(_sl, @object).generate
48
54
  end
49
55
  end
50
56
  end
51
- else
52
- proc { }
53
57
  end
54
58
  end
55
59
 
60
+ def data_proc
61
+ _sl = @sideload
62
+ ->(_) {
63
+ if records = @object.public_send(_sl.name)
64
+ if records.respond_to?(:to_ary)
65
+ records.each { |r| _sl.resource.decorate_record(r) }
66
+ else
67
+ _sl.resource.decorate_record(records)
68
+ end
69
+
70
+ records
71
+ end
72
+ }
73
+ end
74
+
56
75
  def validate_link!
57
76
  unless Graphiti.config.context_for_endpoint
58
77
  raise Errors::Unlinkable.new(@resource_class, @sideload)
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.alpha.9"
2
+ VERSION = "1.0.alpha.10"
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.alpha.9
4
+ version: 1.0.alpha.10
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-08-24 00:00:00.000000000 Z
11
+ date: 2018-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable