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

Conversation

stevenleeg
Copy link

Hi there,

This PR stems from an issue I've asked about in Gitter but didn't end up with a response, so I figured I'd submit the fix myself.

When developing agents locally and importing them via the ADDITIONAL_GEMS=some_agent(path:../some_agent) pathway, I noticed that any agents within the gems wouldn't end up in the agents list of the agent creation page. Doing some digging, I found that the reason was that the dropdown was being populated, via various layers of the stack, by this line in assignable_types.rb:

const_set(:TYPES, Dir[Rails.root.join("app", "models", module_name.underscore, "*.rb")].map { |path| module_name + "::" + File.basename(path, ".rb").camelize })

Searching through the app/models/agents directory naturally omits agents provided by gems, as they're stored not only outside of that directory, but even outside of the Huginn project root. This PR fixes this by populating the TYPES constant with the actual list of constants contained by the namespace at runtime.

The one thing I'm a little stumped on is how this list ends up getting populated properly (ie including agens in gems) when in production, as this is an issue I've only been able to replicate on my development instance. Perhaps there's something I'm missing here, but otherwise this seems like a pretty straightforward fix.

@@ -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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants