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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f98548d9171133e0bf95ba1e4ce84b148a124e7e3b6927054bdd748986e833fb
4
- data.tar.gz: 641d9453158181536d24f5f9c907e8e5eee45bbf76ad746db94bd77815329749
3
+ metadata.gz: e0f0e5dbd15616782e392614348386ade34ec6c0a2ab27c75603fc654adf068e
4
+ data.tar.gz: d412d26ef311e83c489aacbc84d6e8f7caabcae3c0d43dc22120d135d184aa00
5
5
  SHA512:
6
- metadata.gz: 7df4614a5dddfc479d691b5d6e4c1c7644bb7cfe11ec8ac5256d962d63551530ccaed1eb8c56c70218eba0ec370a37f15e83aae148753cc29036148bdea43514
7
- data.tar.gz: 985b7ad4f9a2d9f70d5fe5c207fc5ab1cf78529c0cf62bed66b22274038d36e4fb6ffe5c0af7367b5c3c6e13093799130c875e29c9d33ea462f3e9cb721d4ff4
6
+ metadata.gz: fd34cb1b90bb0353ea4097cab79027cb77cdb9c44dd2ad3fa73595d01e29395e94233165ad6d049380e0200aef3bec792ea5f22ecb3bb94ecf4e72e9a22fcc45
7
+ data.tar.gz: afa32b651692da1cc7dc604181360166f3799ae66b17901d93c5ba90b17f98b5d038ec2c4cd08f62a83e5d548c9cce18f5664518c2170f4dc31307d48339146e
@@ -15,10 +15,10 @@ jobs:
15
15
  rubocop:
16
16
  runs-on: ubuntu-latest
17
17
  steps:
18
- - uses: actions/checkout@v3
18
+ - uses: actions/checkout@v4
19
19
  - uses: ruby/setup-ruby@v1
20
20
  with:
21
- ruby-version: '3.2'
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@v3
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
@@ -5,7 +5,7 @@ AllCops:
5
5
  - vendor/**/*
6
6
  - example/**/*
7
7
  NewCops: enable
8
- TargetRubyVersion: 3.2
8
+ TargetRubyVersion: 3.0
9
9
  SuggestExtensions: false
10
10
 
11
11
  # Layout stuff
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 = '>= 2.7'
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, *args, &block)
8
- super(inverse).tap { |e| e.setup(*args, &block) }
7
+ def self.new(inverse, ...)
8
+ super(inverse).tap { |e| e.setup(...) }
9
9
  end
10
10
 
11
11
  def initialize(inverse = false)
@@ -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".to_sym] ||= []) << existing_val
601
+ (opts[:"#{key}_extras"] ||= []) << existing_val
602
602
  new_val
603
603
  else
604
- (opts["#{key}_extras".to_sym] ||= []) << new_val
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, *args, &block)
13
- super(attribute, options, conditions).tap { |e| e.setup(*args, &block) }
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, _options|
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(options, &options[:proc]).nil?
66
+ exec_with_object(entity_options, &options[:proc]).nil?
67
67
  end
68
68
  end
69
69
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeEntity
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -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
- # rubocop:disable Lint/Debugger
34
- expect { subject.expose :name, format_with: proc {} do p 'hi' end }.to raise_error ArgumentError
35
- # rubocop:enable Lint/Debugger
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, _options|
135
- nil
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, _options|
144
- 100
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.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: 2023-02-16 00:00:00.000000000 Z
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: '2.7'
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.4.6
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.