Skip to content

Instantly share code, notes, and snippets.

@coop

coop/railtie.rb Secret

Created April 13, 2016 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coop/e4e13b850fcf0440f711d7c5f78d2521 to your computer and use it in GitHub Desktop.
Save coop/e4e13b850fcf0440f711d7c5f78d2521 to your computer and use it in GitHub Desktop.
require "set"
module Cobra
def self.paths
@paths ||= Set.new
end
def self.register(path)
paths << path
end
class Railtie < ::Rails::Railtie
config.cobra = ActiveSupport::OrderedOptions.new
config.cobra.pattern = ["*", "*.rb"]
config.cobra.directories = %w(
app/process_managers
app/read_models
)
config.to_prepare { Railtie.setup! }
def setup!
return if Rails.configuration.eager_load
Cobra.config.reset
paths = Cobra.paths.flat_map do |path|
config.cobra.directories.flat_map do |directory|
Dir[path.join(directory, *config.cobra.pattern)]
end
end
paths.each { |path| require_dependency(path) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment