Skip to content

Instantly share code, notes, and snippets.

@voltechs
Last active December 4, 2020 15:23
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 voltechs/49711a2f44fbb9d0df45962dfa3ce9dd to your computer and use it in GitHub Desktop.
Save voltechs/49711a2f44fbb9d0df45962dfa3ce9dd to your computer and use it in GitHub Desktop.
Combustion Engine

For those of you who might be using your engine as a git submodule in a bigger project, here is what I've settled on (riffed a bit from pat/combustion#13 (comment)). I will admit that a bit of the final result is due to trail/error. For instance, I don't really know what the task :environment block does, but I know when I run rake db:migrate, it executes that block, and thus requires additional requires.

If someone else has a clearer understanding of how everything is fitting together, please let me know and I'll update

We do not need to modify db paths in the Rakefile because we've set those up as initializers in the engine.rb so that the main app pulls migrations and schema.rb from the core project. (Bonus points for loading FactoryBot factories to be reused in the main app!)

module Core
class Engine < ::Rails::Engine
initializer :append_paths do |app|
app.config.paths['db'] = config.paths['db'].expanded
app.config.paths['db/migrate'] = config.paths['db/migrate'].expanded
# So we can use core factories in the main app
if defined?(FactoryBot)
FactoryBot.definition_file_paths.unshift(Core.root.join('spec', 'factories'))
end
end
end
end
# === boot ===
begin
require "bundler/setup"
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
# === application ===
require "rails"
require "combustion"
require "active_record/railtie"
Bundler.require :default, Rails.env
Combustion.path = '/'
Combustion::Application.configure_for_combustion
# === Rakefile ===
task :environment do
require 'dotenv/rails'
require "action_mailer/railtie"
end
require "rspec/core/rake_task"
Combustion::Application.load_tasks
task(:default).clear
task(:spec).clear
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
task default: [:spec]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment