Skip to content

Commit ca4136d

Browse files
committed
[rubocop] fix remaining offences
1 parent 65889c1 commit ca4136d

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

bin/console

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ require "bundler/setup"
55
require "dry/logic"
66
require "dry/logic/predicates"
77

8+
# rubocop:disable Style/MixinUsage
89
include Dry::Logic
10+
# rubocop:enable Style/MixinUsage
911

1012
require "irb"
1113
IRB.start

examples/basic.rb

+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
require "dry/logic"
44
require "dry/logic/predicates"
55

6+
# rubocop:disable Style/MixinUsage
67
include Dry::Logic
8+
# rubocop:enable Style/MixinUsage
79

810
user_present = Rule::Predicate.build(Predicates[:key?]).curry(:user)
911

lib/dry/logic/predicates.rb

+23-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ module Logic
99
module Predicates
1010
# rubocop:disable Metrics/ModuleLength
1111
module Methods
12+
def self.uuid_format(version)
13+
::Regexp.new(<<~FORMAT.chomp, ::Regexp::IGNORECASE)
14+
\\A[0-9A-F]{8}-[0-9A-F]{4}-#{version}[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\\z
15+
FORMAT
16+
end
17+
18+
UUIDv1 = uuid_format(1)
19+
20+
UUIDv2 = uuid_format(2)
21+
22+
UUIDv3 = uuid_format(3)
23+
24+
UUIDv4 = uuid_format(4)
25+
26+
UUIDv5 = uuid_format(5)
27+
1228
def [](name)
1329
method(name)
1430
end
@@ -204,32 +220,29 @@ def format?(regex, input)
204220
end
205221

206222
def case?(pattern, input)
223+
# rubocop:disable Style/CaseEquality
207224
pattern === input
225+
# rubocop:enable Style/CaseEquality
208226
end
209227

210228
def uuid_v1?(input)
211-
uuid_v1_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
212-
format?(uuid_v1_format, input)
229+
format?(UUIDv1, input)
213230
end
214231

215232
def uuid_v2?(input)
216-
uuid_v2_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
217-
format?(uuid_v2_format, input)
233+
format?(UUIDv2, input)
218234
end
219235

220236
def uuid_v3?(input)
221-
uuid_v3_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
222-
format?(uuid_v3_format, input)
237+
format?(UUIDv3, input)
223238
end
224239

225240
def uuid_v4?(input)
226-
uuid_v4_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
227-
format?(uuid_v4_format, input)
241+
format?(UUIDv4, input)
228242
end
229243

230244
def uuid_v5?(input)
231-
uuid_v5_format = /\A[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z/i
232-
format?(uuid_v5_format, input)
245+
format?(UUIDv5, input)
233246
end
234247

235248
def uri?(schemes, input)

0 commit comments

Comments
 (0)