Skip to content

Commit

Permalink
Fix some rubocop offences
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jul 21, 2021
1 parent 166ccdd commit 4d7db5b
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 24 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ eval_gemfile "Gemfile.devtools"

gemspec

gem "dry-logic", github: "dry-rb/dry-logic", branch: "master" if ENV["DRY_LOGIC_FROM_MASTER"].eql?("true")
if ENV["DRY_LOGIC_FROM_MASTER"].eql?("true")
gem "dry-logic", github: "dry-rb/dry-logic",
branch: "master"
end

group :test do
gem "dry-struct"
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Dry
module Types
extend Dry::Core::Extensions
extend Dry::Core::ClassAttributes
extend Dry::Core::Deprecations[:'dry-types']
extend Dry::Core::Deprecations[:"dry-types"]
include Dry::Core::Constants

TYPE_SPEC_REGEX = /(.+)<(.+)>/.freeze
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/types/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def default(input = Undefined, options = EMPTY_HASH, &block)
" value every time. Call `.freeze` when setting the default"\
" or pass `shared: true` to discard this warning."\
"\n#{where}",
tag: :'dry-types'
tag: :"dry-types"
)
end

Expand Down Expand Up @@ -105,7 +105,7 @@ def enum(*values)
if values.length == 1 && values[0].is_a?(::Hash)
values[0]
else
::Hash[values.zip(values)]
values.zip(values).to_h
end

Enum.new(constrained(included_in: mapping.keys), mapping: mapping)
Expand Down Expand Up @@ -167,7 +167,7 @@ def fallback(value = Undefined, shared: false, &_fallback)
" value every time. Call `.freeze` when setting the fallback"\
" or pass `shared: true` to discard this warning."\
"\n#{where}",
tag: :'dry-types'
tag: :"dry-types"
)
end

Expand Down
7 changes: 4 additions & 3 deletions lib/dry/types/coercions/params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ module Coercions
module Params
TRUE_VALUES = %w[1 on On ON t true True TRUE T y yes Yes YES Y].freeze
FALSE_VALUES = %w[0 off Off OFF f false False FALSE F n no No NO N].freeze
BOOLEAN_MAP = ::Hash[
TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])
].merge(true => true, false => false).freeze
BOOLEAN_MAP = EMPTY_HASH.merge(
[true, *TRUE_VALUES].to_h { |v| [v, true] },
[false, *FALSE_VALUES].to_h { |v| [v, false] }
).freeze

extend Coercions

Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Dry
module Types
# @api private
class Compiler
extend ::Dry::Core::Deprecations[:'dry-types']
extend ::Dry::Core::Deprecations[:"dry-types"]

attr_reader :registry

Expand Down
3 changes: 2 additions & 1 deletion lib/dry/types/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ module Types

# Register {KERNEL_COERCIBLE} types
KERNEL_COERCIBLE.each do |name, primitive|
register("coercible.#{name}", self["nominal.#{name}"].constructor(Kernel.method(primitive.name)))
register("coercible.#{name}",
self["nominal.#{name}"].constructor(Kernel.method(primitive.name)))
end

# Register {METHOD_COERCIBLE} types
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/lax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def decorate?(response)
end
end

extend ::Dry::Core::Deprecations[:'dry-types']
extend ::Dry::Core::Deprecations[:"dry-types"]
Safe = Lax
deprecate_constant(:Safe)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(registry, *args, **kwargs)
singleton_class.send(:define_method, :included) do |base|
super(base)
base.instance_exec(const_get(:Nominal, false)) do |nominal|
extend Dry::Core::Deprecations[:'dry-types']
extend Dry::Core::Deprecations[:"dry-types"]
const_set(:Definition, nominal)
deprecate_constant(:Definition, message: "Nominal")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/nominal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def to_proc
end
end

extend Dry::Core::Deprecations[:'dry-types']
extend Dry::Core::Deprecations[:"dry-types"]
Definition = Nominal
deprecate_constant(:Definition, message: "Nominal")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def visit_callable(callable)
end
end

def visit_options(options, meta = EMPTY_HASH)
def visit_options(options, meta = EMPTY_HASH) # rubocop:disable Metrics/PerceivedComplexity
if options.empty? && meta.empty?
yield ""
else
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def apply(hash, options = EMPTY_HASH)
# @return [Object] if coercion fails and a block is given
#
# @api public
def try(input)
def try(input) # rubocop:disable Metrics/AbcSize
if primitive?(input)
success = true
output = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/schema/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Schema < Hash
#
# @see Dry::Types::Schema
class Key
extend ::Dry::Core::Deprecations[:'dry-types']
extend ::Dry::Core::Deprecations[:"dry-types"]
include Type
include Dry::Equalizer(:name, :type, :options, inspect: false, immutable: true)
include Decorator
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/types/sum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ def success(input)

# @api private
def failure(input, _error = nil)
if !left.valid?(input)
left.failure(input, left.try(input).error)
else
if left.valid?(input)
right.failure(input, right.try(input).error)
else
left.failure(input, left.try(input).error)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/dry/types/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Types
#
# @api public
module Type
extend ::Dry::Core::Deprecations[:'dry-types']
extend ::Dry::Core::Deprecations[:"dry-types"]

deprecate(:safe, :lax)

Expand Down
2 changes: 1 addition & 1 deletion spec/dry/types/predicate_inferrer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def type(*args)
end

it "should be removed once 2.0 is released" do
if Dry::Types::VERSION.start_with?('2.')
if Dry::Types::VERSION.start_with?("2.")
raise "Remove infer_predicate_by_class_name"
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/dry/types/sum_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@

expect { type.([%i[foo]]) }.to raise_error(Dry::Types::ConstraintError, /\[:foo\]/)

expect { type.([[1], [2]]) }.to raise_error(Dry::Types::ConstraintError, /[1]/)
expect { type.([[1], [2]]) }.to raise_error(Dry::Types::ConstraintError, /[2]/)
expect { type.([[1], [2]]) }.to raise_error(Dry::Types::ConstraintError, /2, \[1\]/)
end
end

Expand Down Expand Up @@ -155,7 +154,7 @@

it "returns boolean" do
expect(type.===("hello")).to eql(true)
expect(type.===(nil)).to eql(false)
expect(type.===(nil)).to eql(false) # rubocop:disable Style/NilComparison
end

context "in case statement" do
Expand Down

0 comments on commit 4d7db5b

Please sign in to comment.