Skip to content

Commit

Permalink
Refactor each_with_object calls
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 8, 2025
1 parent e70096e commit 05110e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 1 addition & 3 deletions core/lib/rom/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def self.coerce(input, options = {})
if input.instance_of?(self)
input
else
attributes = input.each_with_object({}) { |pair, h|
h[pair.first] = Attribute.coerce(pair)
}
attributes = input.to_h { [_1.first, Attribute.coerce(_1)] }

new(attributes, options)
end
Expand Down
8 changes: 4 additions & 4 deletions core/lib/rom/setup/finalize/finalize_mappers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ def initialize(mapper_classes, mapper_objects)
@registry_hash = [@mapper_classes.map(&:base_relation) + @mapper_objects.keys]
.flatten
.uniq
.each_with_object({}) { |n, h| h[n] = {} }
.to_h { [_1, {}] }
end

# @api private
def run!
cache = Cache.new

mappers = registry_hash.each_with_object({}) do |(relation_name, relation_mappers), h|
mappers = registry_hash.to_h do |relation_name, relation_mappers|
relation_mappers.update(build_mappers(relation_name))

if mapper_objects.key?(relation_name)
relation_mappers.update(mapper_objects[relation_name])
end

h[relation_name] = MapperRegistry.new(relation_mappers, cache: cache)
[relation_name, MapperRegistry.new(relation_mappers, cache: cache)]
end

Registry.new(mappers, cache: cache)
Expand All @@ -57,7 +57,7 @@ def check_duplicate_registered_mappers
def build_mappers(relation_name)
mapper_classes
.select { |klass| klass.base_relation == relation_name }
.each_with_object({}) { |klass, h| h[klass.register_as || klass.relation] = klass.build }
.to_h { |k| [k.register_as || k.relation, k.build] }
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions core/lib/rom/support/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def dup = self.class.new(dup_settings(settings))
private

def dup_settings(settings)
settings.each_with_object({}) do |(key, value), new_settings|
settings.to_h do |key, value|
if value.is_a?(self.class)
new_settings[key] = value.dup
[key, value.dup]
else
new_settings[key] = value
[key, value]
end
end
end
Expand Down

0 comments on commit 05110e9

Please sign in to comment.