Skip to content

Commit a03c6c5

Browse files
committed
fix: ruby 3.0 compat
1 parent 175d596 commit a03c6c5

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
- 2.5
2929
- 2.6
3030
- 2.7
31+
- 3.0
3132
steps:
3233
- uses: actions/checkout@v2
3334
- uses: ruby/setup-ruby@v1

lib/rapid/defineable.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def name(new_name = nil)
4040

4141
# Passes all other values through to the DSL for the definition if
4242
# the DSL supoprts it.
43-
def method_missing(name, *args, &block)
43+
def method_missing(name, *args, **kwargs, &block)
4444
if definition.dsl.respond_to?(name)
45-
definition.dsl.send(name, *args, &block)
45+
definition.dsl.send(name, *args, **kwargs, &block)
4646
else
4747
super
4848
end

lib/rapid/dsls/endpoint.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def potential_error(klass, &block)
2828
@definition.potential_errors << klass
2929
end
3030

31-
def argument(*args, &block)
32-
@definition.argument_set.argument(*args, &block)
31+
def argument(*args, **kwargs, &block)
32+
@definition.argument_set.argument(*args, **kwargs, &block)
3333
end
3434

3535
def action(&block)

spec/specs/rapid/argument_set_spec.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
argument :name, type: :string
9696
argument :age, type: :integer
9797
end
98-
as_instance = as.new(name: 'Adam', age: 1234)
98+
as_instance = as.new({ name: 'Adam', age: 1234 })
9999
expect(as_instance[:name]).to eq 'Adam'
100100
expect(as_instance['name']).to eq 'Adam'
101101
expect(as_instance[:age]).to eq 1234
@@ -108,7 +108,7 @@
108108
argument :age, type: :integer, required: true
109109
end
110110
expect do
111-
as.new(name: 'Adam')
111+
as.new({ name: 'Adam' })
112112
end.to raise_error Rapid::MissingArgumentError
113113
end
114114

@@ -125,7 +125,7 @@
125125
argument :name, type: :string
126126
end
127127
expect do
128-
as.new(name: 1234)
128+
as.new({ name: 1234 })
129129
end.to raise_error Rapid::InvalidArgumentError do |e|
130130
expect(e.issue).to eq :invalid_scalar
131131
end
@@ -136,7 +136,7 @@
136136
argument :name, type: :date
137137
end
138138
expect do
139-
as.new(name: '2029-22-34')
139+
as.new({ name: '2029-22-34' })
140140
end.to raise_error Rapid::InvalidArgumentError do |e|
141141
expect(e.issue).to eq :parse_error
142142
end
@@ -151,7 +151,7 @@
151151
end
152152
end
153153
expect do
154-
as.new(name: 'Not Dave')
154+
as.new({ name: 'Not Dave' })
155155
end.to raise_error Rapid::InvalidArgumentError do |e|
156156
expect(e.argument.name).to eq :name
157157
expect(e.issue).to eq :validation_errors
@@ -163,7 +163,7 @@
163163
as = Rapid::ArgumentSet.create('ExampleSet') do
164164
argument :names, type: [:string]
165165
end
166-
as_instance = as.new(names: %w[Adam Charlie])
166+
as_instance = as.new({ names: %w[Adam Charlie] })
167167
expect(as_instance[:names]).to be_a Array
168168
expect(as_instance[:names]).to include 'Adam'
169169
expect(as_instance[:names]).to include 'Charlie'
@@ -174,7 +174,7 @@
174174
argument :names, type: [:string]
175175
end
176176
expect do
177-
as.new(names: ['Adam', 1323])
177+
as.new({ names: ['Adam', 1323] })
178178
end.to raise_error Rapid::InvalidArgumentError do |e|
179179
expect(e.argument.name).to eq :names
180180
expect(e.issue).to eq :invalid_scalar
@@ -190,7 +190,7 @@
190190
argument :title, type: :string
191191
argument :user, type: as1
192192
end
193-
instance = as2.new(title: 'My title', user: { name: 'Michael' })
193+
instance = as2.new({ title: 'My title', user: { name: 'Michael' } })
194194
expect(instance[:title]).to eq 'My title'
195195
expect(instance[:user]).to be_a Rapid::ArgumentSet
196196
expect(instance[:user][:name]).to eq 'Michael'
@@ -204,7 +204,7 @@
204204
argument :title, type: :string
205205
argument :user, type: as1
206206
end
207-
instance = as2.new(title: 'My title')
207+
instance = as2.new({ title: 'My title' })
208208
expect(instance[:user]).to be nil
209209
end
210210

@@ -215,7 +215,7 @@
215215
argument :premium, :boolean
216216
argument :in_debt, :boolean
217217
end
218-
instance = as.new(active: true, premium: false)
218+
instance = as.new({ active: true, premium: false })
219219
expect(instance[:admin]).to eq false
220220
expect(instance[:active]).to eq true
221221
expect(instance[:premium]).to eq false
@@ -235,7 +235,7 @@
235235
argument :book, type: as2
236236
end
237237
expect do
238-
as3.new(age: 12, book: { title: 'Book', user: { name: 1234 } })
238+
as3.new({ age: 12, book: { title: 'Book', user: { name: 1234 } } })
239239
end.to raise_error Rapid::InvalidArgumentError do |e|
240240
expect(e.index).to be nil
241241
expect(e.argument.name).to eq :name

spec/specs/rapid/definitions/field_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@
135135
field = Rapid::Definitions::Field.new(:id)
136136
field.type = :integer
137137
expect do
138-
field.value(id: '444')
138+
field.value({ id: '444' })
139139
end.to raise_error(Rapid::InvalidScalarValueError)
140140
end
141141

142142
it 'should return an array if defined as an array' do
143143
field = Rapid::Definitions::Field.new(:names)
144144
field.type = :string
145145
field.array = true
146-
value = field.value(names: %w[Adam Michael])
146+
value = field.value({ names: %w[Adam Michael] })
147147
expect(value).to be_a Array
148148
expect(value[0]).to eq 'Adam'
149149
expect(value[1]).to eq 'Michael'
@@ -158,10 +158,10 @@
158158
field = Rapid::Definitions::Field.new(:users)
159159
field.type = type
160160
field.array = true
161-
value = field.value(users: [
161+
value = field.value({ users: [
162162
{ name: 'Adam', age: 20 },
163163
{ name: 'Michael', age: 25 }
164-
])
164+
] })
165165
expect(value).to be_a Array
166166
expect(value[0]).to be_a Hash
167167

spec/specs/rapid/field_set_spec.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
field.null = true
1616
field_set.add field
1717

18-
hash = field_set.generate_hash(name: nil)
18+
hash = field_set.generate_hash({ name: nil })
1919
expect(hash['name']).to eq nil
2020
end
2121

@@ -29,11 +29,11 @@
2929
field.condition = proc { |value| value[:name] == 'Sarah' }
3030
field_set.add field
3131

32-
hash = field_set.generate_hash(name: 'Michael', age: 123)
32+
hash = field_set.generate_hash({ name: 'Michael', age: 123 })
3333
expect(hash['name']).to eq 'Michael'
3434
expect(hash.keys).to_not include 'age'
3535

36-
hash = field_set.generate_hash(name: 'Sarah', age: 123)
36+
hash = field_set.generate_hash({ name: 'Sarah', age: 123 })
3737
expect(hash['age']).to eq 123
3838
end
3939

@@ -51,7 +51,7 @@
5151
field.type = :integer
5252
field_set.add field
5353

54-
hash = field_set.generate_hash(number: 99, thing: { name: 'John' })
54+
hash = field_set.generate_hash({ number: 99, thing: { name: 'John' } })
5555
expect(hash['number']).to eq 99
5656
expect(hash.keys).to_not include 'thing'
5757
end
@@ -65,7 +65,7 @@
6565
field.type = type
6666
field_set.add field
6767

68-
hash = field_set.generate_hash(user: { name: 'John' })
68+
hash = field_set.generate_hash({ user: { name: 'John' } })
6969
expect(hash['user']['name']).to eq 'John'
7070
end
7171

@@ -74,7 +74,7 @@
7474
field.type = :string
7575
field_set.add field
7676

77-
hash = field_set.generate_hash(name: :John)
77+
hash = field_set.generate_hash({ name: :John })
7878
expect(hash['name']).to eq 'John'
7979
end
8080

@@ -84,7 +84,7 @@
8484
field.array = true
8585
field_set.add field
8686

87-
hash = field_set.generate_hash(names: %w[Matthew Mark Michael])
87+
hash = field_set.generate_hash({ names: %w[Matthew Mark Michael] })
8888
expect(hash['names']).to be_a Array
8989
expect(hash['names'].size).to eq 3
9090
expect(hash['names']).to include 'Matthew'
@@ -102,7 +102,7 @@
102102
field.array = true
103103
field_set.add field
104104

105-
hash = field_set.generate_hash(users: [{ name: 'Matthew' }, { name: 'Mark' }, { name: 'Michael' }])
105+
hash = field_set.generate_hash({ users: [{ name: 'Matthew' }, { name: 'Mark' }, { name: 'Michael' }] })
106106
expect(hash['users']).to be_a Array
107107
expect(hash['users'].size).to eq 3
108108
expect(hash['users'][0]['name']).to include 'Matthew'
@@ -120,12 +120,12 @@
120120
field.type = polymorph
121121
field_set.add field
122122

123-
hash = field_set.generate_hash(string_or_int: 'Adam')
123+
hash = field_set.generate_hash({ string_or_int: 'Adam' })
124124
expect(hash['string_or_int']).to be_a Hash
125125
expect(hash['string_or_int']['type']).to eq 'string'
126126
expect(hash['string_or_int']['value']).to eq 'Adam'
127127

128-
hash = field_set.generate_hash(string_or_int: 1234)
128+
hash = field_set.generate_hash({ string_or_int: 1234 })
129129
expect(hash['string_or_int']).to be_a Hash
130130
expect(hash['string_or_int']['type']).to eq 'integer'
131131
expect(hash['string_or_int']['value']).to eq 1234
@@ -142,7 +142,7 @@
142142
field.array = true
143143
field_set.add field
144144

145-
hash = field_set.generate_hash(string_or_int: ['Adam', 1, 'Gavin', 2])
145+
hash = field_set.generate_hash({ string_or_int: ['Adam', 1, 'Gavin', 2] })
146146
expect(hash['string_or_int']).to be_a Array
147147
expect(hash['string_or_int'][0]['type']).to eq 'string'
148148
expect(hash['string_or_int'][0]['value']).to eq 'Adam'
@@ -164,7 +164,7 @@
164164
field_set.add field
165165

166166
expect do
167-
field_set.generate_hash(value: 1234)
167+
field_set.generate_hash({ value: 1234 })
168168
end.to raise_error Rapid::InvalidPolymorphValueError do |e|
169169
expect(e.polymorph.definition.id).to eq 'MyPolymorph'
170170
end

0 commit comments

Comments
 (0)