Skip to content

Commit

Permalink
Small cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianna-chang-shopify committed Aug 28, 2023
1 parent 81fbe0d commit 7acd2a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 2 additions & 3 deletions lib/global_id/global_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ def model_class
@model_class ||= begin
model = model_name.constantize

unless model <= GlobalID
model
else
if model <= GlobalID
raise ArgumentError, "GlobalID and SignedGlobalID cannot be used as model_class."
end
model
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/global_id/locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ def normalize_app(app)

class BaseLocator
def locate(gid)
return unless model_id_is_valid(gid)
return unless model_id_is_valid?(gid)
gid.model_class.find gid.model_id
end

def locate_many(gids, options = {})
ids_by_model = Hash.new { |hash, key| hash[key] = [] }

gids.each do |gid|
next unless model_id_is_valid(gid)
next unless model_id_is_valid?(gid)
ids_by_model[gid.model_class] << gid.model_id
end

Expand Down Expand Up @@ -165,7 +165,7 @@ def find_records(model_class, ids, options)
end

private
def model_id_is_valid(gid)
def model_id_is_valid?(gid)
primary_key = Array(gid.model_class.primary_key)
primary_key_size = primary_key.size

Expand Down
13 changes: 8 additions & 5 deletions lib/global_id/uri/gid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ def set_model_components(path, validate = false)
@model_name = model_name

if model_id
model_id_parts = model_id.split(COMPOSITE_MODEL_ID_DELIMITER, COMPOSITE_MODEL_ID_MAX_SIZE)
model_id_parts.reject!(&:blank?)
model_id_parts.each { |id| validate_model_id(id) }

model_id_parts.map! { |id| CGI.unescape(id) }
model_id_parts = model_id
.split(COMPOSITE_MODEL_ID_DELIMITER, COMPOSITE_MODEL_ID_MAX_SIZE)
.reject(&:blank?)

model_id_parts.map! do |id|
validate_model_id(id)
CGI.unescape(id)
end

@model_id = model_id_parts.length == 1 ? model_id_parts.first : model_id_parts
end
Expand Down

0 comments on commit 7acd2a4

Please sign in to comment.