jsonapionify 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/jsonapionify/api/action.rb +0 -1
- data/lib/jsonapionify/api/context_delegate.rb +31 -26
- data/lib/jsonapionify/api/errors.rb +1 -0
- data/lib/jsonapionify/api/relationship/many.rb +1 -7
- data/lib/jsonapionify/api/relationship/one.rb +0 -2
- data/lib/jsonapionify/api/resource/defaults/response_contexts.rb +0 -2
- data/lib/jsonapionify/api/resource/definitions/relationships.rb +1 -7
- data/lib/jsonapionify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGM2MDNiNjEzZTljODYzYWNlYWI3M2ViNmFkNGQ4NTU5OTU1NmZhYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDlmZjlkYWU2MzA0YTkwNTBmNGUwZGRlZDE5NjliYjExNjYzMTc2YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mzg3Y2I0NTk3ZTYxMmIxZDQxMmI2MzgzZWU5ZjQxZTZhYjRhYjA3ZGE3YWVh
|
10
|
+
NGIzZjBhMWNmNWVhZGUxZWEwNmMxN2YxZjcxMDI5N2RlYTI5NjU5ZDlkZmZi
|
11
|
+
MmFlNGZkN2ExN2JkODllNjI3ZGYxNGE5ZjQyMjRlNzUxM2U3YjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWM0ZmNhMmIxYmQzNTQ2ZTJmY2YzMWM4NThhZTYwOTMxOWQ3YzdhMDg5NTYy
|
14
|
+
MWQ3ODA3M2I5MmExMTc3YmM1ZjAyZWI2MGQ5ZmQ4ZWI5NmY3NDgzMjM2NDVm
|
15
|
+
ZDU4YmYyZDIyNzY1ZGE2OTBlMGZiZDc2YmQyNmEwYTk0NGMyZWE=
|
@@ -12,47 +12,52 @@ module JSONAPIonify::Api
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
attr_reader :request
|
16
|
+
|
17
|
+
def initialize(request, resource_instance, definitions, **overrides)
|
18
|
+
@memo = {}
|
19
|
+
@request = request
|
20
|
+
@persisted_memo = {}
|
21
|
+
@definitions = definitions
|
22
|
+
@overrides = overrides
|
23
|
+
@resource_instance = resource_instance
|
24
|
+
delegate = self
|
24
25
|
|
25
26
|
%i{initialize_dup initialize_clone}.each do |method|
|
26
27
|
define_singleton_method method do |copy|
|
27
|
-
memo.each do |k, v|
|
28
|
+
@memo.each do |k, v|
|
28
29
|
copy.public_send "#{k}=", v
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
define_singleton_method(:reset) do |key|
|
34
|
-
memo.delete(key)
|
35
|
-
end
|
36
|
-
|
37
|
-
define_singleton_method(:clear) do
|
38
|
-
memo.clear
|
39
|
-
end
|
40
|
-
|
41
34
|
definitions.each do |name, context|
|
35
|
+
raise Errors::ReservedContextName if respond_to? name
|
42
36
|
define_singleton_method name do
|
43
|
-
return
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
context.call(instance, delegate)
|
49
|
-
end
|
37
|
+
return @overrides[name] if @overrides.has_key? name
|
38
|
+
return @persisted_memo[name] if @persisted_memo.has_key? name
|
39
|
+
return @memo[name] if @memo.has_key? name
|
40
|
+
write_memo = (context.persisted? ? @persisted_memo : @memo)
|
41
|
+
write_memo[name] = context.call(@resource_instance, delegate)
|
50
42
|
end
|
51
43
|
|
52
44
|
define_singleton_method "#{name}=" do |value|
|
53
|
-
persisted_memo[name] = value
|
45
|
+
@persisted_memo[name] = value
|
54
46
|
end unless context.readonly?
|
55
47
|
end
|
48
|
+
freeze
|
49
|
+
end
|
50
|
+
|
51
|
+
def reset key
|
52
|
+
@memo.delete(key)
|
53
|
+
end
|
54
|
+
|
55
|
+
def clear
|
56
|
+
@memo.clear
|
57
|
+
end
|
58
|
+
|
59
|
+
def inspect
|
60
|
+
to_s.chomp('>') << " memoed: #{@memo.keys.inspect}, persisted: #{@persisted_memo.keys.inspect}, overridden: #{@overrides.keys}" << '>'
|
56
61
|
end
|
57
62
|
|
58
63
|
end
|
@@ -30,8 +30,6 @@ module JSONAPIonify::Api
|
|
30
30
|
example_input: :resource_identifier
|
31
31
|
}
|
32
32
|
define_action(:replace, 'PATCH', **options, &block).response status: 200 do |context|
|
33
|
-
context.owner_context.reset(:instance)
|
34
|
-
context.reset(:collection)
|
35
33
|
context.response_object[:data] = build_identifier_collection(context.collection)
|
36
34
|
context.response_object.to_json
|
37
35
|
end
|
@@ -46,8 +44,6 @@ module JSONAPIonify::Api
|
|
46
44
|
example_input: :resource_identifier
|
47
45
|
}
|
48
46
|
define_action(:add, 'POST', **options, &block).response status: 200 do |context|
|
49
|
-
context.owner_context.reset(:instance)
|
50
|
-
context.reset(:collection)
|
51
47
|
context.response_object[:data] = build_identifier_collection(context.collection)
|
52
48
|
context.response_object.to_json
|
53
49
|
end
|
@@ -63,15 +59,13 @@ module JSONAPIonify::Api
|
|
63
59
|
}
|
64
60
|
options[:prepend] = 'relationships'
|
65
61
|
define_action(:remove, 'DELETE', **options, &block).response status: 200 do |context|
|
66
|
-
context.owner_context.reset(:instance)
|
67
|
-
context.reset(:collection)
|
68
62
|
context.response_object[:data] = build_identifier_collection(context.collection)
|
69
63
|
context.response_object.to_json
|
70
64
|
end
|
71
65
|
end
|
72
66
|
|
73
67
|
context :scope do |context|
|
74
|
-
instance_exec
|
68
|
+
instance_exec(rel.name, context.owner, context, &rel.resolve).dup
|
75
69
|
end
|
76
70
|
|
77
71
|
show
|
@@ -30,8 +30,6 @@ module JSONAPIonify::Api
|
|
30
30
|
prepend: 'relationships'
|
31
31
|
}
|
32
32
|
define_action(:replace, 'PATCH', **options, &block).response status: 200 do |context|
|
33
|
-
context.owner_context.reset(:instance)
|
34
|
-
context.reset(:instance)
|
35
33
|
context.response_object[:data] = build_resource_identifier(context.instance)
|
36
34
|
context.response_object.to_json
|
37
35
|
end
|
@@ -12,8 +12,7 @@ module JSONAPIonify::Api
|
|
12
12
|
define_relationship(name, Relationship::Many, **opts, &block).tap do
|
13
13
|
define_relationship_counter(
|
14
14
|
name,
|
15
|
-
count_attribute === true ? "#{name.to_s.singularize}_count" : count_attribute.to_s
|
16
|
-
include: include_count
|
15
|
+
count_attribute === true ? "#{name.to_s.singularize}_count" : count_attribute.to_s
|
17
16
|
) if count_attribute
|
18
17
|
end
|
19
18
|
end
|
@@ -24,11 +23,6 @@ module JSONAPIonify::Api
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def define_relationship_counter(rel_name, name, include: true)
|
27
|
-
before :response do |context|
|
28
|
-
if (context.scope.is_a?(ActiveRecord::Relation) || context.scope.is_a?(ActiveRecord::Base)) && context.scope._reflect_on_association(rel_name)
|
29
|
-
context.scope = context.scope.includes(rel_name)
|
30
|
-
end if context.fields[type&.to_sym].include? name.to_sym
|
31
|
-
end if include
|
32
26
|
attribute name.to_sym, types.Integer, "The number of #{rel_name}.", write: false do |_, instance, context|
|
33
27
|
rel = context.resource.class.relationship(rel_name)
|
34
28
|
blank_fields = context.fields.map { |k, _| [k, {}] }.to_h
|
data/lib/jsonapionify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonapionify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Waldrip
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|