grape-entity 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/grape-entity.gemspec +1 -1
- data/lib/grape_entity/condition/base.rb +2 -2
- data/lib/grape_entity/entity.rb +2 -2
- data/lib/grape_entity/exposure/base.rb +2 -2
- data/lib/grape_entity/exposure.rb +2 -2
- data/lib/grape_entity/version.rb +1 -1
- data/spec/grape_entity/entity_spec.rb +10 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0f0e5dbd15616782e392614348386ade34ec6c0a2ab27c75603fc654adf068e
|
4
|
+
data.tar.gz: d412d26ef311e83c489aacbc84d6e8f7caabcae3c0d43dc22120d135d184aa00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd34cb1b90bb0353ea4097cab79027cb77cdb9c44dd2ad3fa73595d01e29395e94233165ad6d049380e0200aef3bec792ea5f22ecb3bb94ecf4e72e9a22fcc45
|
7
|
+
data.tar.gz: afa32b651692da1cc7dc604181360166f3799ae66b17901d93c5ba90b17f98b5d038ec2c4cd08f62a83e5d548c9cce18f5664518c2170f4dc31307d48339146e
|
data/.github/workflows/ci.yml
CHANGED
@@ -15,10 +15,10 @@ jobs:
|
|
15
15
|
rubocop:
|
16
16
|
runs-on: ubuntu-latest
|
17
17
|
steps:
|
18
|
-
- uses: actions/checkout@
|
18
|
+
- uses: actions/checkout@v4
|
19
19
|
- uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
|
-
ruby-version: '3.
|
21
|
+
ruby-version: '3.0'
|
22
22
|
bundler-cache: true
|
23
23
|
- name: Run rubocop
|
24
24
|
run: bundle exec rubocop --parallel --format progress
|
@@ -28,10 +28,10 @@ jobs:
|
|
28
28
|
needs: ['rubocop']
|
29
29
|
strategy:
|
30
30
|
matrix:
|
31
|
-
ruby-version: ['3.0', '3.1', '3.2', 'head']
|
31
|
+
ruby-version: ['3.0', '3.1', '3.2', '3.3', 'head']
|
32
32
|
steps:
|
33
33
|
- name: Check out branch
|
34
|
-
uses: actions/checkout@
|
34
|
+
uses: actions/checkout@v4
|
35
35
|
- name: Set up Ruby
|
36
36
|
uses: ruby/setup-ruby@v1
|
37
37
|
with:
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,13 @@
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
11
|
|
12
|
+
### ### 1.0.1 (2024-04-10)
|
13
|
+
|
14
|
+
#### Fixes
|
15
|
+
|
16
|
+
* [#381](https://github.com/ruby-grape/grape-entity/pull/381): Fix `expose_nil: false` when using a block - [@magni-](https://github.com/magni-).
|
17
|
+
|
18
|
+
|
12
19
|
### ### 1.0.0 (2023-02-16)
|
13
20
|
|
14
21
|
#### Fixes
|
data/grape-entity.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.description = 'Extracted from Grape, A Ruby framework for rapid API development with great conventions.'
|
15
15
|
s.license = 'MIT'
|
16
16
|
|
17
|
-
s.required_ruby_version = '>=
|
17
|
+
s.required_ruby_version = '>= 3.0'
|
18
18
|
|
19
19
|
s.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
20
20
|
# FIXME: remove dependecy
|
@@ -4,8 +4,8 @@ module Grape
|
|
4
4
|
class Entity
|
5
5
|
module Condition
|
6
6
|
class Base
|
7
|
-
def self.new(inverse,
|
8
|
-
super(inverse).tap { |e| e.setup(
|
7
|
+
def self.new(inverse, ...)
|
8
|
+
super(inverse).tap { |e| e.setup(...) }
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(inverse = false)
|
data/lib/grape_entity/entity.rb
CHANGED
@@ -598,10 +598,10 @@ module Grape
|
|
598
598
|
if existing_val.is_a?(Hash) && new_val.is_a?(Hash)
|
599
599
|
existing_val.merge(new_val)
|
600
600
|
elsif new_val.is_a?(Hash)
|
601
|
-
(opts["#{key}_extras"
|
601
|
+
(opts[:"#{key}_extras"] ||= []) << existing_val
|
602
602
|
new_val
|
603
603
|
else
|
604
|
-
(opts["#{key}_extras"
|
604
|
+
(opts[:"#{key}_extras"] ||= []) << new_val
|
605
605
|
existing_val
|
606
606
|
end
|
607
607
|
else
|
@@ -9,8 +9,8 @@ module Grape
|
|
9
9
|
class Base
|
10
10
|
attr_reader :attribute, :is_safe, :documentation, :override, :conditions, :for_merge
|
11
11
|
|
12
|
-
def self.new(attribute, options, conditions,
|
13
|
-
super(attribute, options, conditions).tap { |e| e.setup(
|
12
|
+
def self.new(attribute, options, conditions, ...)
|
13
|
+
super(attribute, options, conditions).tap { |e| e.setup(...) }
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(attribute, options, conditions)
|
@@ -54,7 +54,7 @@ module Grape
|
|
54
54
|
|
55
55
|
def expose_nil_condition(attribute, options)
|
56
56
|
Condition.new_unless(
|
57
|
-
proc do |object,
|
57
|
+
proc do |object, entity_options|
|
58
58
|
if options[:proc].nil?
|
59
59
|
delegator = Delegator.new(object)
|
60
60
|
if is_a?(Grape::Entity) && delegator.accepts_options?
|
@@ -63,7 +63,7 @@ module Grape
|
|
63
63
|
delegator.delegate(attribute).nil?
|
64
64
|
end
|
65
65
|
else
|
66
|
-
exec_with_object(
|
66
|
+
exec_with_object(entity_options, &options[:proc]).nil?
|
67
67
|
end
|
68
68
|
end
|
69
69
|
)
|
data/lib/grape_entity/version.rb
CHANGED
@@ -30,9 +30,11 @@ describe Grape::Entity do
|
|
30
30
|
|
31
31
|
it 'makes sure that :format_with as a proc cannot be used with a block' do
|
32
32
|
# rubocop:disable Style/BlockDelimiters
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
expect {
|
34
|
+
subject.expose :name, format_with: proc {} do
|
35
|
+
p 'hi'
|
36
|
+
end
|
37
|
+
}.to raise_error ArgumentError
|
36
38
|
# rubocop:enable Style/BlockDelimiters
|
37
39
|
end
|
38
40
|
|
@@ -131,8 +133,8 @@ describe Grape::Entity do
|
|
131
133
|
|
132
134
|
context 'when expose_nil option is false and block passed' do
|
133
135
|
it 'does not expose if block returns nil' do
|
134
|
-
subject.expose(:a, expose_nil: false) do |_obj,
|
135
|
-
|
136
|
+
subject.expose(:a, expose_nil: false) do |_obj, options|
|
137
|
+
options[:option_a]
|
136
138
|
end
|
137
139
|
subject.expose(:b)
|
138
140
|
subject.expose(:c)
|
@@ -140,12 +142,12 @@ describe Grape::Entity do
|
|
140
142
|
end
|
141
143
|
|
142
144
|
it 'exposes is block returns a value' do
|
143
|
-
subject.expose(:a, expose_nil: false) do |_obj,
|
144
|
-
|
145
|
+
subject.expose(:a, expose_nil: false) do |_obj, options|
|
146
|
+
options[:option_a]
|
145
147
|
end
|
146
148
|
subject.expose(:b)
|
147
149
|
subject.expose(:c)
|
148
|
-
expect(subject.represent(model).serializable_hash).to eq(a: 100, b: nil, c: 'value')
|
150
|
+
expect(subject.represent(model, option_a: 100).serializable_hash).to eq(a: 100, b: nil, c: 'value')
|
149
151
|
end
|
150
152
|
end
|
151
153
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-entity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeFnord
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -113,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
113
|
requirements:
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '3.0'
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
119
|
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
123
|
+
rubygems_version: 3.5.5
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: A simple facade for managing the relationship between your model and API.
|