jsonapi_compliable 0.6.8 → 0.6.9

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: 62ef8f2928ce29e36d96ed0eb6b79513a8e2966e
4
- data.tar.gz: 0a480dfac6e92b1c4e9491b46078c0a95bc15627
3
+ metadata.gz: 7f1eac7962a18b73dc60232ec1607f09b7f45eed
4
+ data.tar.gz: f7707bda77c712fdf7a7b1b34169156399c76a52
5
5
  SHA512:
6
- metadata.gz: 8bed61f5bc597f389a838ab43bfe411689b878aa12d2dc0395b58e8d66fb1ab39bc6cc3329872b5a77ecef5f73ffcdb9eaae90f135b685ea9237fc04d42c26c3
7
- data.tar.gz: 5ccffb4f60669279d560efe15ba667414f761fc0cfdb1b0cfe6f60eeb83fa07c9be69727e4f36e820a2c15a134b348f60935664a6ca58835f9110e7b5decfe60
6
+ metadata.gz: e0d21c56a530c7a9fe811b2f892e78b6f6a7140af521ea32fc70b654d62f6ba1c9c401b53e0c2d4b089a355adcdae7e7df1790f5ce79b14dcaff066db5eeea84
7
+ data.tar.gz: a560bd12cecdc55c81f909e7dd908aeb501d51fdc8fd72ef16935141d0ae8847d7a4fcb366510a6290c6a90ecceb81a18bfa4fd8696866858c8604bd7ed4e89f
@@ -88,10 +88,8 @@ module JsonapiCompliable
88
88
  # @api private
89
89
  # @yieldreturn Code to run within the current context
90
90
  def wrap_context
91
- if self.class._jsonapi_compliable
92
- jsonapi_resource.with_context(self, action_name.to_sym) do
93
- yield
94
- end
91
+ jsonapi_resource.with_context(self, action_name.to_sym) do
92
+ yield
95
93
  end
96
94
  end
97
95
 
@@ -446,12 +446,8 @@ module JsonapiCompliable
446
446
  # @param object The context (Rails controller or equivalent)
447
447
  # @param namespace One of index/show/etc
448
448
  def with_context(object, namespace = nil)
449
- begin
450
- prior = context
451
- @context = { object: object, namespace: namespace }
449
+ JsonapiCompliable.with_context(object, namespace) do
452
450
  yield
453
- ensure
454
- @context = prior
455
451
  end
456
452
  end
457
453
 
@@ -462,7 +458,11 @@ module JsonapiCompliable
462
458
  # @see #with_context
463
459
  # @return [Hash] the context hash
464
460
  def context
465
- @context || {}
461
+ JsonapiCompliable.context[:object]
462
+ end
463
+
464
+ def context_namespace
465
+ JsonapiCompliable.context[:namespace]
466
466
  end
467
467
 
468
468
  # Build a scope using this Resource configuration
@@ -592,7 +592,7 @@ module JsonapiCompliable
592
592
  def allowed_sideloads(namespace = nil)
593
593
  return {} unless sideloading
594
594
 
595
- namespace ||= context[:namespace]
595
+ namespace ||= context_namespace
596
596
  sideloads = sideloading.to_hash[:base]
597
597
  if !sideload_whitelist.empty? && namespace
598
598
  sideloads = Util::IncludeParams.scrub(sideloads, sideload_whitelist[namespace])
@@ -14,7 +14,7 @@ module JsonapiCompliable
14
14
  resource.filters.find { |_name, opts| opts[:aliases].include?(name.to_sym) }
15
15
  raise JsonapiCompliable::Errors::BadFilter unless filter_name
16
16
  if guard = filter_value[:if]
17
- raise JsonapiCompliable::Errors::BadFilter if resource.context[:object].send(guard) == false
17
+ raise JsonapiCompliable::Errors::BadFilter if resource.context.send(guard) == false
18
18
  end
19
19
  { filter_name => filter_value }
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module JsonapiCompliable
2
- VERSION = "0.6.8"
2
+ VERSION = "0.6.9"
3
3
  end
@@ -42,4 +42,25 @@ module JsonapiCompliable
42
42
  include Base
43
43
  end
44
44
  end
45
+
46
+ # @api private
47
+ def self.context
48
+ Thread.current[:context] ||= {}
49
+ end
50
+
51
+ # @api private
52
+ def self.context=(val)
53
+ Thread.current[:context] = val
54
+ end
55
+
56
+ # @api private
57
+ def self.with_context(obj, namespace)
58
+ begin
59
+ prior = self.context
60
+ self.context = { object: obj, namespace: namespace }
61
+ yield
62
+ ensure
63
+ self.context = prior
64
+ end
65
+ end
45
66
  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.6.8
4
+ version: 0.6.9
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: 2017-05-16 00:00:00.000000000 Z
12
+ date: 2017-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-serializable