Skip to content

Instantly share code, notes, and snippets.

@pablomarti
Created February 20, 2019 05:29
Show Gist options
  • Save pablomarti/b8b2a746f7e72d9b319f5f6423bf1373 to your computer and use it in GitHub Desktop.
Save pablomarti/b8b2a746f7e72d9b319f5f6423bf1373 to your computer and use it in GitHub Desktop.
Load supporting files into a Rails model
module Support
extend ActiveSupport::Concern
included do
support_path = "app/support/#{name.underscore}/"
actions_path = File.join('.', "#{support_path}actions/*.rb")
queries_path = File.join('.', "#{support_path}queries/*.rb")
events_path = File.join('.', "#{support_path}events/*.rb")
Dir[actions_path, queries_path, events_path].each do |f|
include f.gsub('.rb', '').split('/')[3..-1].map(&:camelize).join('::').constantize
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment