jsonapi_compliable 0.3.10 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/jsonapi_compliable.gemspec +2 -3
- data/lib/jsonapi_compliable.rb +3 -5
- data/lib/jsonapi_compliable/base.rb +8 -7
- data/lib/jsonapi_compliable/extensions/boolean_attribute.rb +21 -0
- data/lib/jsonapi_compliable/extensions/extra_attribute.rb +34 -0
- data/lib/jsonapi_compliable/version.rb +1 -1
- metadata +5 -32
- data/lib/jsonapi_compliable/railtie.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06adc2e0a9833b1556d62814a1f88c81a4beac2e
|
4
|
+
data.tar.gz: 53d1f7f2d515a1c9dd18fe02f0ab7fe72069f5a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b5e0517b385fe8fe14234570db9a07c27dc552454d3d7197740708828ad1a84faa496e593148f469ca609262f5047905d7a06f5942c30c60c03ac1b4f692455
|
7
|
+
data.tar.gz: d80f8f709221fd66c313409129bb7aac91c9c53bd8d1c8d7ad8affa646c84e7b3eb5eac511a97eb3067519a2f785f15c9ea2885fa3199507b87dbec8fdf64141
|
data/Gemfile
CHANGED
data/jsonapi_compliable.gemspec
CHANGED
@@ -18,9 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_dependency "rails", ['>= 4.1', '< 6']
|
21
|
-
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency "jsonapi_ams_extensions", "~> 0.1"
|
21
|
+
|
22
|
+
spec.add_dependency 'jsonapi-rails', '~> 0.1'
|
24
23
|
|
25
24
|
spec.add_development_dependency "kaminari"
|
26
25
|
spec.add_development_dependency "active_model_serializers"
|
data/lib/jsonapi_compliable.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'jsonapi'
|
3
|
-
require 'jsonapi_ams_extensions'
|
1
|
+
require 'jsonapi/rails'
|
4
2
|
|
5
3
|
require "jsonapi_compliable/version"
|
6
4
|
require "jsonapi_compliable/errors"
|
@@ -19,8 +17,8 @@ require "jsonapi_compliable/util/include_params"
|
|
19
17
|
require "jsonapi_compliable/util/field_params"
|
20
18
|
require "jsonapi_compliable/util/scoping"
|
21
19
|
require "jsonapi_compliable/util/pagination"
|
22
|
-
|
23
|
-
require
|
20
|
+
require "jsonapi_compliable/extensions/extra_attribute"
|
21
|
+
require "jsonapi_compliable/extensions/boolean_attribute"
|
24
22
|
|
25
23
|
module JsonapiCompliable
|
26
24
|
autoload :Base, 'jsonapi_compliable/base'
|
@@ -51,25 +51,26 @@ module JsonapiCompliable
|
|
51
51
|
Util::FieldParams.parse!(params, :extra_fields)
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
54
|
+
def render_jsonapi(scope, opts = {})
|
55
55
|
scoped = Util::Scoping.apply?(self, scope, opts.delete(:scope)) ? jsonapi_scope(scope) : scope
|
56
|
-
options =
|
56
|
+
options = default_jsonapi_render_options
|
57
57
|
options[:include] = forced_includes || Util::IncludeParams.scrub(self)
|
58
58
|
options[:jsonapi] = JsonapiCompliable::Util::Pagination.zero?(params) ? [] : scoped
|
59
59
|
options[:fields] = Util::FieldParams.fieldset(params, :fields) if params[:fields]
|
60
|
-
options[:extra_fields] = Util::FieldParams.fieldset(params, :extra_fields) if params[:extra_fields]
|
61
60
|
options[:meta] ||= {}
|
62
61
|
options.merge!(opts)
|
63
62
|
options[:meta][:stats] = Stats::Payload.new(self, scoped).generate if params[:stats]
|
63
|
+
options[:expose] ||= {}
|
64
|
+
options[:expose][:context] = self
|
65
|
+
options[:expose][:extra_fields] = Util::FieldParams.fieldset(params, :extra_fields) if params[:extra_fields]
|
64
66
|
|
65
67
|
render(options)
|
66
68
|
end
|
67
69
|
|
68
|
-
#
|
69
|
-
# render
|
70
|
-
def
|
70
|
+
# render_jsonapi(foo) equivalent to
|
71
|
+
# render jsonapi: foo, default_jsonapi_render_options
|
72
|
+
def default_jsonapi_render_options
|
71
73
|
{}.tap do |options|
|
72
|
-
options[:adapter] = :json_api
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module JsonapiCompliable
|
2
|
+
module Extensions
|
3
|
+
module BooleanAttribute
|
4
|
+
def self.included(klass)
|
5
|
+
klass.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def boolean_attribute(name, options = {}, &blk)
|
10
|
+
blk ||= proc { @object.public_send(name) }
|
11
|
+
field_name = :"is_#{name.to_s.gsub('?', '')}"
|
12
|
+
attribute field_name, options, &blk
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
JSONAPI::Serializable::Resource.class_eval do
|
20
|
+
include JsonapiCompliable::Extensions::BooleanAttribute
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'jsonapi/serializable/resource/conditional_fields'
|
2
|
+
|
3
|
+
module JsonapiCompliable
|
4
|
+
module Extensions
|
5
|
+
module ExtraAttribute
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def extra_attribute(name, options = {}, &blk)
|
12
|
+
allow_field = proc {
|
13
|
+
if options[:if]
|
14
|
+
next false unless instance_eval(&options[:if])
|
15
|
+
end
|
16
|
+
|
17
|
+
if @extra_fields && @extra_fields[jsonapi_type]
|
18
|
+
@extra_fields[jsonapi_type].include?(name)
|
19
|
+
else
|
20
|
+
false
|
21
|
+
end
|
22
|
+
}
|
23
|
+
|
24
|
+
attribute name, if: allow_field, &blk
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
JSONAPI::Serializable::Resource.class_eval do
|
32
|
+
prepend JSONAPI::Serializable::Resource::ConditionalFields
|
33
|
+
include JsonapiCompliable::Extensions::ExtraAttribute
|
34
|
+
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.
|
4
|
+
version: 0.4.0
|
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: 2016-
|
12
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -32,35 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name: jsonapi
|
36
|
-
requirement: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.1.beta2
|
41
|
-
type: :runtime
|
42
|
-
prerelease: false
|
43
|
-
version_requirements: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.1.beta2
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: active_model_serializers
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.10'
|
55
|
-
type: :runtime
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.10'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: jsonapi_ams_extensions
|
35
|
+
name: jsonapi-rails
|
64
36
|
requirement: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
38
|
- - "~>"
|
@@ -219,7 +191,8 @@ files:
|
|
219
191
|
- lib/jsonapi_compliable/deserializable.rb
|
220
192
|
- lib/jsonapi_compliable/dsl.rb
|
221
193
|
- lib/jsonapi_compliable/errors.rb
|
222
|
-
- lib/jsonapi_compliable/
|
194
|
+
- lib/jsonapi_compliable/extensions/boolean_attribute.rb
|
195
|
+
- lib/jsonapi_compliable/extensions/extra_attribute.rb
|
223
196
|
- lib/jsonapi_compliable/scope/base.rb
|
224
197
|
- lib/jsonapi_compliable/scope/default_filter.rb
|
225
198
|
- lib/jsonapi_compliable/scope/extra_fields.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rails/railtie'
|
2
|
-
require 'action_controller'
|
3
|
-
require 'action_controller/railtie'
|
4
|
-
require 'action_controller/serialization'
|
5
|
-
|
6
|
-
module ActiveModelSerializers
|
7
|
-
class Railtie < Rails::Railtie
|
8
|
-
initializer 'jsonapi_compliable.register_renderer' do
|
9
|
-
require 'active_model_serializers/register_jsonapi_renderer'
|
10
|
-
end
|
11
|
-
|
12
|
-
initializer 'jsonapi_compliable.configure_ams' do
|
13
|
-
if ActiveModelSerializers.config.respond_to?(:include_data_default)
|
14
|
-
ActiveModelSerializers.config.include_data_default = :if_sideloaded
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|