Skip to content

Commit

Permalink
[rubocop] fix remaining offences
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Dec 24, 2021
1 parent 65889c1 commit ca4136d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 2 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ require "bundler/setup"
require "dry/logic"
require "dry/logic/predicates"

# rubocop:disable Style/MixinUsage
include Dry::Logic
# rubocop:enable Style/MixinUsage

require "irb"
IRB.start
2 changes: 2 additions & 0 deletions examples/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
require "dry/logic"
require "dry/logic/predicates"

# rubocop:disable Style/MixinUsage
include Dry::Logic
# rubocop:enable Style/MixinUsage

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

Expand Down
33 changes: 23 additions & 10 deletions lib/dry/logic/predicates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ module Logic
module Predicates
# rubocop:disable Metrics/ModuleLength
module Methods
def self.uuid_format(version)
::Regexp.new(<<~FORMAT.chomp, ::Regexp::IGNORECASE)
\\A[0-9A-F]{8}-[0-9A-F]{4}-#{version}[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\\z
FORMAT
end

UUIDv1 = uuid_format(1)

UUIDv2 = uuid_format(2)

UUIDv3 = uuid_format(3)

UUIDv4 = uuid_format(4)

UUIDv5 = uuid_format(5)

def [](name)
method(name)
end
Expand Down Expand Up @@ -204,32 +220,29 @@ def format?(regex, input)
end

def case?(pattern, input)
# rubocop:disable Style/CaseEquality
pattern === input
# rubocop:enable Style/CaseEquality
end

def uuid_v1?(input)
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
format?(uuid_v1_format, input)
format?(UUIDv1, input)
end

def uuid_v2?(input)
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
format?(uuid_v2_format, input)
format?(UUIDv2, input)
end

def uuid_v3?(input)
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
format?(uuid_v3_format, input)
format?(UUIDv3, input)
end

def uuid_v4?(input)
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
format?(uuid_v4_format, input)
format?(UUIDv4, input)
end

def uuid_v5?(input)
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
format?(uuid_v5_format, input)
format?(UUIDv5, input)
end

def uri?(schemes, input)
Expand Down

0 comments on commit ca4136d

Please sign in to comment.