Skip to content

Commit

Permalink
use hash mapping name to class instead of storing just names
Browse files Browse the repository at this point in the history
This will alternatively resolve the problem with duplicate classes in
development on reload without the need to explicitly reset the registry
  • Loading branch information
toy committed Jul 1, 2024
1 parent f752884 commit c60686c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib_static/open_project/acts/registry_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ module OpenProject
module Acts
module RegistryMethods
def instance(model_name)
class_name = model_name.singularize.camelize

class_name.constantize if class_names.include?(class_name)
models[model_name.singularize.camelize]
end

def add(*models)
Expand All @@ -44,14 +42,14 @@ def add(*models)
raise ArgumentError.new("Model #{model} does not include #{acts_as_method_name}")
end

class_names << model.name
self.models[model.name] = model
end
end

private

def class_names
@class_names ||= Set.new
def models
@models ||= Hash.new
end
end
end
Expand Down

0 comments on commit c60686c

Please sign in to comment.