as_json_representations 0.5.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +7 -5
- data/README.md +2 -0
- data/as_json_representations.gemspec +2 -2
- data/lib/as_json_representations/collection.rb +9 -6
- data/lib/as_json_representations/version.rb +1 -1
- data/lib/as_json_representations.rb +3 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a8d39dc3e4957b77b602263d9193606cd5ab4989fbb035512eb921c7df2bd8d
|
4
|
+
data.tar.gz: bd36c60219711176968616cebc6851afbd73e8e4af4543d4eb319570fc1d5be0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57cfcc22d77af7b41ab3540c7692ef12e49e9fad3c1b23f347782154db756a5717438e115d52d5b4bad32b6fd8cf3afac303ce4277797483ff9c7bd842154d31
|
7
|
+
data.tar.gz: 546a24dea5c3e795761b1ff9ad693401da479ab38061865920372bb3272b1c89207f7c46d4b6af41bc00d613e6dd35ead5b24eafa2e7748c34667f1394bebfd7
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [v0.6.1] - 2022-02-24
|
8
|
+
- Fixed bug when use string as representation name with collections
|
9
|
+
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in as_json_representations.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'byebug'
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
as_json_representations (0.
|
4
|
+
as_json_representations (0.6.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
byebug (11.0.1)
|
9
10
|
diff-lcs (1.3)
|
10
|
-
rake (
|
11
|
+
rake (13.0.1)
|
11
12
|
rspec (3.7.0)
|
12
13
|
rspec-core (~> 3.7.0)
|
13
14
|
rspec-expectations (~> 3.7.0)
|
@@ -27,9 +28,10 @@ PLATFORMS
|
|
27
28
|
|
28
29
|
DEPENDENCIES
|
29
30
|
as_json_representations!
|
30
|
-
bundler (~>
|
31
|
-
|
31
|
+
bundler (~> 2.3)
|
32
|
+
byebug
|
33
|
+
rake (~> 13.0)
|
32
34
|
rspec (~> 3.0)
|
33
35
|
|
34
36
|
BUNDLED WITH
|
35
|
-
|
37
|
+
2.3.8
|
data/README.md
CHANGED
@@ -155,6 +155,8 @@ When you includes representation module (parent) into other module (child):
|
|
155
155
|
You can use this ActiveRecord option when you define a representation:
|
156
156
|
|
157
157
|
* [includes](https://apidock.com/rails/ActiveRecord/QueryMethods/includes)
|
158
|
+
* [eager_load](https://apidock.com/rails/ActiveRecord/QueryMethods/eager_load)
|
159
|
+
* [preload](https://apidock.com/rails/ActiveRecord/QueryMethods/preload)
|
158
160
|
|
159
161
|
```
|
160
162
|
representation :private, includes: [:city]
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
-
spec.add_development_dependency 'rake', '~>
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2.3'
|
25
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
26
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
27
|
end
|
@@ -8,15 +8,18 @@ module AsJsonRepresentations
|
|
8
8
|
base.class_eval do
|
9
9
|
def as_json(options={})
|
10
10
|
subject = self
|
11
|
+
representation = options[:representation]&.to_sym
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
if representation && respond_to?(:klass) && klass.respond_to?(:representations)
|
14
|
+
# call supported methods of ActiveRecord::QueryMethods
|
15
|
+
QUERY_METHODS.each do |method|
|
16
|
+
next unless respond_to? method
|
15
17
|
|
16
|
-
|
18
|
+
args = klass.representations.dig(representation, method)
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
+
# we need to reassign because ActiveRecord returns new object
|
21
|
+
subject = subject.public_send(method, args) if args
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
return super if respond_to? :super
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'as_json_representations/collection.rb'
|
2
2
|
|
3
3
|
module AsJsonRepresentations
|
4
|
+
QUERY_METHODS = %i[includes eager_load preload].freeze
|
5
|
+
|
4
6
|
module ClassMethods
|
5
7
|
def representation(name, options={}, &block)
|
6
8
|
@representations ||= {}
|
@@ -11,7 +13,7 @@ module AsJsonRepresentations
|
|
11
13
|
extend_representation_name = options[:extend] == true ? name : options[:extend]
|
12
14
|
extend_representation = (parent_entity || self).representations[extend_representation_name]
|
13
15
|
|
14
|
-
|
16
|
+
QUERY_METHODS.each do |option|
|
15
17
|
next unless (extend_option_value = extend_representation[option])
|
16
18
|
@representations[name][option] = extend_option_value + (options[option] || [])
|
17
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: as_json_representations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado01
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- Gemfile.lock
|
67
68
|
- LICENSE.txt
|
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
- !ruby/object:Gem::Version
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.1.4
|
96
97
|
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: Creates representations of your model data
|