Skip to content

Commit

Permalink
Address offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 4, 2025
1 parent 65247f5 commit 50f5d63
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
18 changes: 9 additions & 9 deletions lib/dry/struct/class_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def inherited(klass)
# ruby.celebrities[0].pseudonym #=> 'Matz'
# ruby.celebrities[1].name #=> 'Aaron Patterson'
# ruby.celebrities[1].pseudonym #=> 'tenderlove'
def attribute(name, type = Undefined, &block)
attributes(name => build_type(name, type, &block))
def attribute(name, type = Undefined, &)
attributes(name => build_type(name, type, &))
end

# Add atributes from another struct
Expand Down Expand Up @@ -121,13 +121,13 @@ def attribute(name, type = Undefined, &block)
#
# @param struct [Dry::Struct]
def attributes_from(struct)
extracted_schema = struct.schema.keys.map { |key|
extracted_schema = struct.schema.keys.to_h do |key|
if key.required?
[key.name, key.type]
else
[:"#{key.name}?", key.type]
end
}.to_h
end
attributes(extracted_schema)
end

Expand All @@ -148,7 +148,7 @@ def attributes_from(struct)
def attribute?(*args, &block)
if args.size == 1 && block.nil?
Core::Deprecations.warn(
"Dry::Struct.attribute? is deprecated for checking attribute presence, "\
"Dry::Struct.attribute? is deprecated for checking attribute presence, " \
"use has_attribute? instead",
tag: :"dry-struct"
)
Expand Down Expand Up @@ -246,7 +246,7 @@ def check_schema_duplication(new_keys)

# @param [Hash{Symbol => Object},Dry::Struct] attributes
# @raise [Struct::Error] if the given attributes don't conform {#schema}
def new(attributes = default_attributes, safe = false, &block) # rubocop:disable Style/OptionalBooleanParameter
def new(attributes = default_attributes, safe = false, &) # rubocop:disable Style/OptionalBooleanParameter
if attributes.is_a?(Struct)
if equal?(attributes.class)
attributes
Expand All @@ -256,7 +256,7 @@ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable
# User.new(super_user)
#
# We may deprecate this behavior in future forcing people to be explicit
new(attributes.to_h, safe, &block)
new(attributes.to_h, safe, &)
end
elsif safe
load(schema.call_safe(attributes) { |output = attributes| return yield output })
Expand All @@ -268,11 +268,11 @@ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable
end

# @api private
def call_safe(input, &block)
def call_safe(input, &)
if input.is_a?(self)
input
else
new(input, true, &block)
new(input, true, &)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/dry/struct/sum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def try(input)
# @param [Dry::Types::Type] type
# @return [Dry::Types::Sum]
def |(type)
if type.is_a?(Class) && type <= Struct || type.is_a?(Sum)
if (type.is_a?(::Class) && type <= Struct) || type.is_a?(Sum)
Sum.new(self, type)
else
super
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/constructor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

describe "#prepend" do
let(:type) do
super().prepend { |x| x.map { |k, v| [k.to_sym, v] }.to_h }
super().prepend { |x| x.to_h { |k, v| [k.to_sym, v] } }
end

specify do
Expand Down
3 changes: 1 addition & 2 deletions spec/integration/pattern_matching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def match(user)
"Alice or Carol"
in User(first_name:, last_name: "Doe")
"DOE, #{first_name.upcase}"
in User(first_name:, last_name: "Doe")
"DOE, #{first_name.upcase}"
in User(first_name:, address: Address(street: "Downing street"))
"PM is #{first_name}"
end
Expand All @@ -76,6 +74,7 @@ def match(user)
example "multiple structs" do
case john
in User(first_name: "John" | "Jack")
"John or Jack"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module DryStructSpec
rescue LoadError
end

Dir[Pathname(__dir__).join("shared/*.rb")].sort.each(&method(:require))
Dir[Pathname(__dir__).join("shared/*.rb")].each(&method(:require))
require "dry/types/spec/types"

RSpec.configure do |config|
Expand Down

0 comments on commit 50f5d63

Please sign in to comment.