grape-entity 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +81 -1
- data/.travis.yml +5 -5
- data/CHANGELOG.md +8 -1
- data/Gemfile +1 -1
- data/bench/serializing.rb +5 -0
- data/lib/grape_entity/delegator/fetchable_object.rb +1 -1
- data/lib/grape_entity/delegator/openstruct_object.rb +1 -1
- data/lib/grape_entity/delegator/plain_object.rb +1 -1
- data/lib/grape_entity/entity.rb +11 -4
- data/lib/grape_entity/options.rb +3 -2
- data/lib/grape_entity/version.rb +1 -1
- data/spec/grape_entity/entity_spec.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb3365afa36454c797c3d44adfa51ecc757a105fe6cb6644f3f3896ff06af48d
|
4
|
+
data.tar.gz: 1e3c91d73fb17727c931443910b2f602e037384eb4f04e055207bbaf471c3962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba4bd4207a7c5f5f09806017b29723ba0f3ed0fc749cd360d55ebba9a41465165f91a7ae974d6af4baed71109c2ad5b7f19514a6f510953fe3733b46d35f405e
|
7
|
+
data.tar.gz: 4ac4db65df766dd004c35e926a6a43e08023d86b4477d6e396b8c9ce9b125ee889bbbe86fecf7f6f4a60f847c2ae5d38beb829ce017957737de7a52f0ab802d3
|
data/.rubocop.yml
CHANGED
@@ -6,9 +6,14 @@ AllCops:
|
|
6
6
|
- example/**/*
|
7
7
|
TargetRubyVersion: 2.7
|
8
8
|
|
9
|
+
# Layout stuff
|
10
|
+
#
|
9
11
|
Layout/EmptyLinesAroundArguments:
|
10
12
|
Enabled: false
|
11
13
|
|
14
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
15
|
+
Enabled: true
|
16
|
+
|
12
17
|
Layout/FirstHashElementIndentation:
|
13
18
|
EnforcedStyle: consistent
|
14
19
|
|
@@ -17,6 +22,28 @@ Layout/LineLength:
|
|
17
22
|
Exclude:
|
18
23
|
- spec/**/*
|
19
24
|
|
25
|
+
Layout/SpaceAroundMethodCallOperator:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
# Lint stuff
|
29
|
+
#
|
30
|
+
Lint/DeprecatedOpenSSLConstant:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Lint/DuplicateElsifCondition:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Lint/MixedRegexpCaptureTypes:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Lint/RaiseException:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Lint/StructNewOverride:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
# Metrics stuff
|
46
|
+
#
|
20
47
|
Metrics/AbcSize:
|
21
48
|
Max: 25
|
22
49
|
|
@@ -25,7 +52,7 @@ Metrics/BlockLength:
|
|
25
52
|
- spec/**/*
|
26
53
|
|
27
54
|
Metrics/CyclomaticComplexity:
|
28
|
-
Max:
|
55
|
+
Max: 13
|
29
56
|
|
30
57
|
Metrics/ClassLength:
|
31
58
|
Max: 300
|
@@ -38,11 +65,64 @@ Metrics/MethodLength:
|
|
38
65
|
Metrics/PerceivedComplexity:
|
39
66
|
Max: 11
|
40
67
|
|
68
|
+
# Naming stuff
|
69
|
+
#
|
70
|
+
|
41
71
|
Naming:
|
42
72
|
Enabled: false
|
43
73
|
|
74
|
+
# Style stuff
|
75
|
+
#
|
76
|
+
Style/AccessorGrouping:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
Style/ArrayCoercion:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Style/BisectedAttrAccessor:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
Style/CaseLikeIf:
|
86
|
+
Enabled: true
|
87
|
+
|
44
88
|
Style/Documentation:
|
45
89
|
Enabled: false
|
46
90
|
|
91
|
+
Style/ExponentialNotation:
|
92
|
+
Enabled: true
|
93
|
+
|
94
|
+
Style/HashAsLastArrayItem:
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
Style/HashEachMethods:
|
98
|
+
Enabled: true
|
99
|
+
|
100
|
+
Style/HashLikeCase:
|
101
|
+
Enabled: true
|
102
|
+
|
103
|
+
Style/HashTransformKeys:
|
104
|
+
Enabled: true
|
105
|
+
|
106
|
+
Style/HashTransformValues:
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
Style/RedundantAssignment:
|
110
|
+
Enabled: true
|
111
|
+
|
112
|
+
Style/RedundantFetchBlock:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Style/RedundantFileExtensionInRequire:
|
116
|
+
Enabled: true
|
117
|
+
|
118
|
+
Style/RedundantRegexpCharacterClass:
|
119
|
+
Enabled: true
|
120
|
+
|
121
|
+
Style/RedundantRegexpEscape:
|
122
|
+
Enabled: true
|
123
|
+
|
47
124
|
Style/RegexpLiteral:
|
48
125
|
Enabled: false
|
126
|
+
|
127
|
+
Style/SlicingWithRange:
|
128
|
+
Enabled: true
|
data/.travis.yml
CHANGED
@@ -7,9 +7,9 @@ after_success:
|
|
7
7
|
- bundle exec danger
|
8
8
|
|
9
9
|
rvm:
|
10
|
-
- 2.5.
|
11
|
-
- 2.6.
|
12
|
-
- 2.7.
|
10
|
+
- 2.5.8
|
11
|
+
- 2.6.6
|
12
|
+
- 2.7.1
|
13
13
|
- ruby-head
|
14
14
|
- jruby-head
|
15
15
|
|
@@ -17,9 +17,9 @@ matrix:
|
|
17
17
|
fast_finish: true
|
18
18
|
|
19
19
|
include:
|
20
|
-
- rvm: 2.4.
|
20
|
+
- rvm: 2.4.10
|
21
21
|
|
22
22
|
allow_failures:
|
23
|
-
- rvm: 2.4.
|
23
|
+
- rvm: 2.4.10
|
24
24
|
- rvm: ruby-head
|
25
25
|
- rvm: jruby-head
|
data/CHANGELOG.md
CHANGED
@@ -8,7 +8,14 @@
|
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
-
### 0.
|
11
|
+
### 0.8.1 (2020-07-15)
|
12
|
+
|
13
|
+
#### Fixes
|
14
|
+
|
15
|
+
* [#336](https://github.com/ruby-grape/grape-entity/pull/336): Pass options to delegators when they accept it - [@dnesteryuk](https://github.com/dnesteryuk).
|
16
|
+
* [#333](https://github.com/ruby-grape/grape-entity/pull/333): Fix typo in CHANGELOG.md - [@eitoball](https://github.com/eitoball).
|
17
|
+
|
18
|
+
### 0.8.0 (2020-02-18)
|
12
19
|
|
13
20
|
#### Features
|
14
21
|
|
data/Gemfile
CHANGED
data/bench/serializing.rb
CHANGED
@@ -7,6 +7,7 @@ require 'benchmark'
|
|
7
7
|
module Models
|
8
8
|
class School
|
9
9
|
attr_reader :classrooms
|
10
|
+
|
10
11
|
def initialize
|
11
12
|
@classrooms = []
|
12
13
|
end
|
@@ -15,6 +16,7 @@ module Models
|
|
15
16
|
class ClassRoom
|
16
17
|
attr_reader :students
|
17
18
|
attr_accessor :teacher
|
19
|
+
|
18
20
|
def initialize(opts = {})
|
19
21
|
@teacher = opts[:teacher]
|
20
22
|
@students = []
|
@@ -23,6 +25,7 @@ module Models
|
|
23
25
|
|
24
26
|
class Person
|
25
27
|
attr_accessor :name
|
28
|
+
|
26
29
|
def initialize(opts = {})
|
27
30
|
@name = opts[:name]
|
28
31
|
end
|
@@ -30,6 +33,7 @@ module Models
|
|
30
33
|
|
31
34
|
class Teacher < Models::Person
|
32
35
|
attr_accessor :tenure
|
36
|
+
|
33
37
|
def initialize(opts = {})
|
34
38
|
super(opts)
|
35
39
|
@tenure = opts[:tenure]
|
@@ -38,6 +42,7 @@ module Models
|
|
38
42
|
|
39
43
|
class Student < Models::Person
|
40
44
|
attr_reader :grade
|
45
|
+
|
41
46
|
def initialize(opts = {})
|
42
47
|
super(opts)
|
43
48
|
@grade = opts[:grade]
|
data/lib/grape_entity/entity.rb
CHANGED
@@ -105,7 +105,7 @@ module Grape
|
|
105
105
|
@root_exposure ||= Exposure.new(nil, nesting: true)
|
106
106
|
end
|
107
107
|
|
108
|
-
attr_writer :root_exposure
|
108
|
+
attr_writer :root_exposure, :formatters
|
109
109
|
|
110
110
|
# Returns all formatters that are registered for this and it's ancestors
|
111
111
|
# @return [Hash] of formatters
|
@@ -113,8 +113,6 @@ module Grape
|
|
113
113
|
@formatters ||= {}
|
114
114
|
end
|
115
115
|
|
116
|
-
attr_writer :formatters
|
117
|
-
|
118
116
|
def hash_access
|
119
117
|
@hash_access ||= :to_sym
|
120
118
|
end
|
@@ -130,6 +128,10 @@ module Grape
|
|
130
128
|
:to_sym
|
131
129
|
end
|
132
130
|
end
|
131
|
+
|
132
|
+
def delegation_opts
|
133
|
+
@delegation_opts ||= { hash_access: hash_access }
|
134
|
+
end
|
133
135
|
end
|
134
136
|
|
135
137
|
@formatters = {}
|
@@ -479,6 +481,9 @@ module Grape
|
|
479
481
|
@object = object
|
480
482
|
@options = options.is_a?(Options) ? options : Options.new(options)
|
481
483
|
@delegator = Delegator.new(object)
|
484
|
+
|
485
|
+
# Why not `arity > 1`? It might be negative https://ruby-doc.org/core-2.6.6/Method.html#method-i-arity
|
486
|
+
@delegator_accepts_opts = @delegator.method(:delegate).arity != 1
|
482
487
|
end
|
483
488
|
|
484
489
|
def root_exposures
|
@@ -531,8 +536,10 @@ module Grape
|
|
531
536
|
def delegate_attribute(attribute)
|
532
537
|
if is_defined_in_entity?(attribute)
|
533
538
|
send(attribute)
|
539
|
+
elsif @delegator_accepts_opts
|
540
|
+
delegator.delegate(attribute, self.class.delegation_opts)
|
534
541
|
else
|
535
|
-
delegator.delegate(attribute
|
542
|
+
delegator.delegate(attribute)
|
536
543
|
end
|
537
544
|
end
|
538
545
|
|
data/lib/grape_entity/options.rb
CHANGED
@@ -106,11 +106,12 @@ module Grape
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def build_symbolized_hash(attribute, hash)
|
109
|
-
|
109
|
+
case attribute
|
110
|
+
when Hash
|
110
111
|
attribute.each do |attr, nested_attrs|
|
111
112
|
hash[attr.to_sym] = build_symbolized_hash(nested_attrs, {})
|
112
113
|
end
|
113
|
-
|
114
|
+
when Array
|
114
115
|
return attribute.each { |x| build_symbolized_hash(x, {}) }
|
115
116
|
else
|
116
117
|
hash[attribute.to_sym] = true
|
data/lib/grape_entity/version.rb
CHANGED
@@ -977,7 +977,7 @@ describe Grape::Entity do
|
|
977
977
|
subject.expose(:user, using: user_entity)
|
978
978
|
|
979
979
|
representation = subject.represent(OpenStruct.new(user: {}),
|
980
|
-
only: [:id, :name, :phone, user: %i[id name email]],
|
980
|
+
only: [:id, :name, :phone, { user: %i[id name email] }],
|
981
981
|
except: [:phone, { user: [:id] }], serializable: true)
|
982
982
|
expect(representation).to eq(id: nil, name: nil, user: { name: nil, email: nil })
|
983
983
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-entity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -214,7 +214,7 @@ homepage: https://github.com/ruby-grape/grape-entity
|
|
214
214
|
licenses:
|
215
215
|
- MIT
|
216
216
|
metadata: {}
|
217
|
-
post_install_message:
|
217
|
+
post_install_message:
|
218
218
|
rdoc_options: []
|
219
219
|
require_paths:
|
220
220
|
- lib
|
@@ -229,8 +229,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
229
|
- !ruby/object:Gem::Version
|
230
230
|
version: '0'
|
231
231
|
requirements: []
|
232
|
-
rubygems_version: 3.1.
|
233
|
-
signing_key:
|
232
|
+
rubygems_version: 3.1.4
|
233
|
+
signing_key:
|
234
234
|
specification_version: 4
|
235
235
|
summary: A simple facade for managing the relationship between your model and API.
|
236
236
|
test_files:
|