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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daa006efc48883832cee9320fdd7c6f97857739664befca6e43a9926b7e32f87
4
- data.tar.gz: aca509444daca9ce848074ddab33a5e7db143d5bc4aef381fb55e8c62f208fc5
3
+ metadata.gz: 1a8d39dc3e4957b77b602263d9193606cd5ab4989fbb035512eb921c7df2bd8d
4
+ data.tar.gz: bd36c60219711176968616cebc6851afbd73e8e4af4543d4eb319570fc1d5be0
5
5
  SHA512:
6
- metadata.gz: 171f411f75287d344bfc1372dbde7fdaf97384c149ca704ef948eff4330d23fbb91e2f15057a42f3184e783a767025da2de26aaa931e3e68c062a25dcdcd372c
7
- data.tar.gz: 0257036af2c8696a39a11afe994523c178185c705a00bb448cbfd04125cd457701420c3c122cad7605ca14ddd6cc89f1039742e18f5176c3c22d51d962b94840
6
+ metadata.gz: 57cfcc22d77af7b41ab3540c7692ef12e49e9fad3c1b23f347782154db756a5717438e115d52d5b4bad32b6fd8cf3afac303ce4277797483ff9c7bd842154d31
7
+ data.tar.gz: 546a24dea5c3e795761b1ff9ad693401da479ab38061865920372bb3272b1c89207f7c46d4b6af41bc00d613e6dd35ead5b24eafa2e7748c34667f1394bebfd7
data/.gitignore CHANGED
@@ -9,4 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .byebug_history
12
13
  *.gem
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 "https://rubygems.org"
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.5.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 (10.5.0)
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 (~> 1.15)
31
- rake (~> 10.0)
31
+ bundler (~> 2.3)
32
+ byebug
33
+ rake (~> 13.0)
32
34
  rspec (~> 3.0)
33
35
 
34
36
  BUNDLED WITH
35
- 1.17.2
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', '~> 1.15'
25
- spec.add_development_dependency 'rake', '~> 10.0'
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
- # call supported methods of ActiveRecord::QueryMethods
13
- %i[includes eager_load].each do |method|
14
- next unless respond_to? method
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
- args = klass.representations.dig(options[:representation], method)
18
+ args = klass.representations.dig(representation, method)
17
19
 
18
- # we need to reassign because ActiveRecord returns new object
19
- subject = subject.public_send(method, args) if args
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,3 +1,3 @@
1
1
  module AsJsonRepresentations
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -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
- %i[includes eager_load].each do |option|
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.5.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: 2019-08-24 00:00:00.000000000 Z
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: '1.15'
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: '1.15'
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: '10.0'
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: '10.0'
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.0.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