grape-entity 0.10.2 → 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: 4a89222a95fe66dc86d907762352275aa328a0423a461e2f5a7c8fc806a92f09
4
- data.tar.gz: a06ad75430e568a7e4cd2e9b6b329011e8382003c5882f690199403be58928c7
3
+ metadata.gz: e0f0e5dbd15616782e392614348386ade34ec6c0a2ab27c75603fc654adf068e
4
+ data.tar.gz: d412d26ef311e83c489aacbc84d6e8f7caabcae3c0d43dc22120d135d184aa00
5
5
  SHA512:
6
- metadata.gz: 1bc3419fea51eb0c7c7c78f8f4e510c9d73bfe210cee2aa1f2aaaee92725d02334ab235818a37300c733c0970c9ee40cf56a022b421937ec6662d3e67da3e85f
7
- data.tar.gz: 4f31cb8e01fbba21883bbf432fa557d0ca7f85d3c1d42a0aac0e4143c4add3af37e7f24b4fc315ff55502a640bffa0d185e8c3081d8a8b5492d45dc1b0102233
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.1'
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: ['2.7', '3.0', '3.1', 'head', jruby, truffleruby]
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.1
8
+ TargetRubyVersion: 3.0
9
9
  SuggestExtensions: false
10
10
 
11
11
  # Layout stuff
@@ -38,7 +38,7 @@ Lint/ConstantDefinitionInBlock:
38
38
  #
39
39
  Metrics/AbcSize:
40
40
  Max: 25
41
- IgnoredMethods:
41
+ AllowedMethods:
42
42
  # from lib/grape_entity/exposure/nesting_exposure.rb
43
43
  - 'normalized_exposures'
44
44
 
@@ -59,7 +59,7 @@ Metrics/MethodLength:
59
59
 
60
60
  Metrics/PerceivedComplexity:
61
61
  Max: 11
62
- IgnoredMethods:
62
+ AllowedMethods:
63
63
  # from lib/grape_entity/entity.rb
64
64
  - 'expose'
65
65
  - 'merge_options'
data/CHANGELOG.md CHANGED
@@ -9,6 +9,22 @@
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
+
19
+ ### ### 1.0.0 (2023-02-16)
20
+
21
+ #### Fixes
22
+
23
+ **Breaking change:**
24
+ * [#352](https://github.com/ruby-grape/grape-entity/pull/369): Remove `FetchableObject` behavior. - [@danielvdao](https://github.com/danielvdao).
25
+ * [#371](https://github.com/ruby-grape/grape-entity/pull/371): Allow default exposed value to be `false` or any empty data - [@norydev](https://github.com/norydev).
26
+
27
+
12
28
  ### 0.10.2 (2022-07-29)
13
29
 
14
30
  #### Fixes
data/Gemfile CHANGED
@@ -5,7 +5,15 @@ source 'http://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- gem 'rubocop', '~> 1.0', require: false
8
+ gem 'bundler'
9
+ gem 'maruku'
10
+ gem 'pry' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
11
+ gem 'pry-byebug' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
12
+ gem 'rack-test'
13
+ gem 'rake'
14
+ gem 'rspec', '~> 3.9'
15
+ gem 'rubocop', '~> 1.0'
16
+ gem 'yard'
9
17
  end
10
18
 
11
19
  group :test do
data/UPGRADING.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Upgrading Grape Entity
2
2
 
3
3
 
4
+ ### Upgrading to >= 0.10.2
5
+ Official support for `FetchableObject` was removed.
6
+
7
+ See [#352](https://github.com/ruby-grape/grape-entity/pull/369) for more information.
8
+
4
9
  ### Upgrading to >= 0.8.2
5
10
 
6
11
  Official support for ruby < 2.5 removed, ruby 2.5 only in testing mode, but no support.
data/grape-entity.gemspec CHANGED
@@ -7,28 +7,19 @@ Gem::Specification.new do |s|
7
7
  s.name = 'grape-entity'
8
8
  s.version = GrapeEntity::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
- s.authors = ['Michael Bleigh']
11
- s.email = ['michael@intridea.com']
10
+ s.authors = ['LeFnord', 'Michael Bleigh']
11
+ s.email = ['pscholz.le@gmail.com', 'michael@intridea.com']
12
12
  s.homepage = 'https://github.com/ruby-grape/grape-entity'
13
13
  s.summary = 'A simple facade for managing the relationship between your model and API.'
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.5'
17
+ s.required_ruby_version = '>= 3.0'
18
18
 
19
19
  s.add_runtime_dependency 'activesupport', '>= 3.0.0'
20
20
  # FIXME: remove dependecy
21
21
  s.add_runtime_dependency 'multi_json', '>= 1.3.2'
22
22
 
23
- s.add_development_dependency 'bundler'
24
- s.add_development_dependency 'maruku'
25
- s.add_development_dependency 'pry' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
26
- s.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM.eql?('java') || RUBY_ENGINE.eql?('rbx')
27
- s.add_development_dependency 'rack-test'
28
- s.add_development_dependency 'rake'
29
- s.add_development_dependency 'rspec', '~> 3.9'
30
- s.add_development_dependency 'yard'
31
-
32
23
  s.files = `git ls-files`.split("\n")
33
24
  s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
34
25
  s.require_paths = ['lib']
@@ -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)
@@ -3,7 +3,6 @@
3
3
  require 'grape_entity/delegator/base'
4
4
  require 'grape_entity/delegator/hash_object'
5
5
  require 'grape_entity/delegator/openstruct_object'
6
- require 'grape_entity/delegator/fetchable_object'
7
6
  require 'grape_entity/delegator/plain_object'
8
7
 
9
8
  module Grape
@@ -15,8 +14,6 @@ module Grape
15
14
  HashObject
16
15
  elsif defined?(OpenStruct) && object.is_a?(OpenStruct)
17
16
  OpenStructObject
18
- elsif object.respond_to?(:fetch, true)
19
- FetchableObject
20
17
  else
21
18
  PlainObject
22
19
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'multi_json'
4
- require 'set'
5
4
 
6
5
  module Grape
7
6
  # An Entity is a lightweight structure that allows you to easily
@@ -599,10 +598,10 @@ module Grape
599
598
  if existing_val.is_a?(Hash) && new_val.is_a?(Hash)
600
599
  existing_val.merge(new_val)
601
600
  elsif new_val.is_a?(Hash)
602
- (opts["#{key}_extras".to_sym] ||= []) << existing_val
601
+ (opts[:"#{key}_extras"] ||= []) << existing_val
603
602
  new_val
604
603
  else
605
- (opts["#{key}_extras".to_sym] ||= []) << new_val
604
+ (opts[:"#{key}_extras"] ||= []) << new_val
606
605
  existing_val
607
606
  end
608
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)
@@ -89,7 +89,7 @@ module Grape
89
89
  return unless valid?(entity)
90
90
 
91
91
  output = value(entity, options)
92
- output.blank? && @default_value.present? ? @default_value : output
92
+ output.blank? && !@default_value.nil? ? @default_value : output
93
93
  end
94
94
 
95
95
  def should_return_key?(options)
@@ -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 = '0.10.2'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -30,7 +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
- expect { subject.expose :name, format_with: proc {} do p 'hi' end }.to raise_error ArgumentError
33
+ expect {
34
+ subject.expose :name, format_with: proc {} do
35
+ p 'hi'
36
+ end
37
+ }.to raise_error ArgumentError
34
38
  # rubocop:enable Style/BlockDelimiters
35
39
  end
36
40
 
@@ -129,8 +133,8 @@ describe Grape::Entity do
129
133
 
130
134
  context 'when expose_nil option is false and block passed' do
131
135
  it 'does not expose if block returns nil' do
132
- subject.expose(:a, expose_nil: false) do |_obj, _options|
133
- nil
136
+ subject.expose(:a, expose_nil: false) do |_obj, options|
137
+ options[:option_a]
134
138
  end
135
139
  subject.expose(:b)
136
140
  subject.expose(:c)
@@ -138,12 +142,12 @@ describe Grape::Entity do
138
142
  end
139
143
 
140
144
  it 'exposes is block returns a value' do
141
- subject.expose(:a, expose_nil: false) do |_obj, _options|
142
- 100
145
+ subject.expose(:a, expose_nil: false) do |_obj, options|
146
+ options[:option_a]
143
147
  end
144
148
  subject.expose(:b)
145
149
  subject.expose(:c)
146
- 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')
147
151
  end
148
152
  end
149
153
  end
@@ -245,9 +249,9 @@ describe Grape::Entity do
245
249
  context 'when default option is set' do
246
250
  it 'exposes default values for attributes' do
247
251
  subject.expose(:a, default: 'a')
248
- subject.expose(:b, default: 'b')
252
+ subject.expose(:b, default: false)
249
253
  subject.expose(:c, default: 'c')
250
- expect(subject.represent(model).serializable_hash).to eq(a: 'a', b: 'b', c: 'value')
254
+ expect(subject.represent(model).serializable_hash).to eq(a: 'a', b: false, c: 'value')
251
255
  end
252
256
  end
253
257
 
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-entity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
+ - LeFnord
7
8
  - Michael Bleigh
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2022-07-29 00:00:00.000000000 Z
12
+ date: 2024-04-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activesupport
@@ -38,121 +39,10 @@ dependencies:
38
39
  - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: 1.3.2
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: maruku
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: pry
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: pry-byebug
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rack-test
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: rake
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rspec
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '3.9'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '3.9'
139
- - !ruby/object:Gem::Dependency
140
- name: yard
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
42
  description: Extracted from Grape, A Ruby framework for rapid API development with
154
43
  great conventions.
155
44
  email:
45
+ - pscholz.le@gmail.com
156
46
  - michael@intridea.com
157
47
  executables: []
158
48
  extensions: []
@@ -187,7 +77,6 @@ files:
187
77
  - lib/grape_entity/condition/symbol_condition.rb
188
78
  - lib/grape_entity/delegator.rb
189
79
  - lib/grape_entity/delegator/base.rb
190
- - lib/grape_entity/delegator/fetchable_object.rb
191
80
  - lib/grape_entity/delegator/hash_object.rb
192
81
  - lib/grape_entity/delegator/openstruct_object.rb
193
82
  - lib/grape_entity/delegator/plain_object.rb
@@ -224,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
224
113
  requirements:
225
114
  - - ">="
226
115
  - !ruby/object:Gem::Version
227
- version: '2.5'
116
+ version: '3.0'
228
117
  required_rubygems_version: !ruby/object:Gem::Requirement
229
118
  requirements:
230
119
  - - ">="
231
120
  - !ruby/object:Gem::Version
232
121
  version: '0'
233
122
  requirements: []
234
- rubygems_version: 3.3.7
123
+ rubygems_version: 3.5.5
235
124
  signing_key:
236
125
  specification_version: 4
237
126
  summary: A simple facade for managing the relationship between your model and API.
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- class Entity
5
- module Delegator
6
- class FetchableObject < Base
7
- def delegate(attribute)
8
- object.fetch attribute
9
- end
10
- end
11
- end
12
- end
13
- end