Skip to content

Commit 0bee751

Browse files
author
BjornMelgaard
committed
prefixed, tests are working
1 parent f03d168 commit 0bee751

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

lib/jsonapi_compliable/base.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ def jsonapi(foo = 'bar', resource: nil, &blk)
6363
# This returns MyResource.new
6464
#
6565
# @return [Resource] the configured Resource for this controller
66-
def resource
67-
@resource ||= self.class._jsonapi_compliable.new
66+
def jsonapi_resource
67+
@jsonapi_resource ||= self.class._jsonapi_compliable.new
6868
end
6969

7070
# Instantiates the relevant Query object
7171
#
7272
# @see Query
7373
# @return [Query] the Query object for this resource/params
7474
def query
75-
@query ||= Query.new(resource, params)
75+
@query ||= Query.new(jsonapi_resource, params)
7676
end
7777

7878
# @see Query#to_hash
7979
# @return [Hash] the normalized query hash for only the *current* resource
8080
def query_hash
81-
@query_hash ||= query.to_hash[resource.type]
81+
@query_hash ||= query.to_hash[jsonapi_resource.type]
8282
end
8383

8484
# Tracks the current context so we can refer to it within any
@@ -89,7 +89,7 @@ def query_hash
8989
# @yieldreturn Code to run within the current context
9090
def wrap_context
9191
if self.class._jsonapi_compliable
92-
resource.with_context(self, action_name.to_sym) do
92+
jsonapi_resource.with_context(self, action_name.to_sym) do
9393
yield
9494
end
9595
end
@@ -113,7 +113,7 @@ def wrap_context
113113
# @see Resource#build_scope
114114
# @return [Scope] the configured scope
115115
def jsonapi_scope(scope, opts = {})
116-
resource.build_scope(scope, query, opts)
116+
jsonapi_resource.build_scope(scope, query, opts)
117117
end
118118

119119
# @see Deserializer#initialize
@@ -148,7 +148,7 @@ def deserialized_params
148148
# @return [Util::ValidationResponse]
149149
def jsonapi_create
150150
_persist do
151-
resource.persist_with_relationships \
151+
jsonapi_resource.persist_with_relationships \
152152
deserialized_params.meta,
153153
deserialized_params.attributes,
154154
deserialized_params.relationships
@@ -179,7 +179,7 @@ def jsonapi_create
179179
# @return [Util::ValidationResponse]
180180
def jsonapi_update
181181
_persist do
182-
resource.persist_with_relationships \
182+
jsonapi_resource.persist_with_relationships \
183183
deserialized_params.meta,
184184
deserialized_params.attributes,
185185
deserialized_params.relationships
@@ -254,7 +254,7 @@ def perform_render_jsonapi(opts)
254254

255255
def _persist
256256
validation_response = nil
257-
resource.transaction do
257+
jsonapi_resource.transaction do
258258
object = yield
259259
validation_response = Util::ValidationResponse.new \
260260
object, deserialized_params

spec/jsonapi_compliable_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def config(obj)
7878

7979
it 'wraps in the resource context' do
8080
instance.wrap_context do
81-
expect(instance.resource.context).to eq({
81+
expect(instance.jsonapi_resource.context).to eq({
8282
object: instance,
8383
namespace: :index
8484
})

0 commit comments

Comments
 (0)