Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use smarter type detection for AssignableTypes #2938

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/concerns/assignable_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ module ClassMethods
def load_types_in(module_name, my_name = module_name.singularize)
const_set(:MODULE_NAME, module_name)
const_set(:BASE_CLASS_NAME, my_name)
const_set(:TYPES, Dir[Rails.root.join("app", "models", module_name.underscore, "*.rb")].map { |path| module_name + "::" + File.basename(path, ".rb").camelize })
types = module_name.constantize.constants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this may not work in development and test environments where files are lazy-loaded. Can you confirm this works even in development mode? (e.g. bundle exec rails r 'puts Agent::TYPES')

.select {|t| t.to_s.include?(my_name)}
.map {|t| "#{module_name}::#{t}"}
const_set(:TYPES, types)
end

def types
Expand All @@ -44,4 +47,4 @@ def build_for_type(type, user, attributes = {})
end
end
end
end
end