-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rails specific environment boostrapping
- Loading branch information
Showing
3 changed files
with
34 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,49 @@ | ||
module Mutant | ||
module Bootstrap | ||
module Rails | ||
def self.call(world, config) | ||
class Rails | ||
include Procto.call, Concord.new(:world, :config) | ||
|
||
def call | ||
world.stdout.puts('Loading mutant config from rails environment') | ||
|
||
# TODO move to world. | ||
# TODO add env to world. | ||
# | ||
# Make actual env configurable | ||
ENV['RAILS_ENV'] = 'test' | ||
|
||
world.kernel.require('./config/environment.rb') | ||
|
||
::Rails.application.eager_load! | ||
|
||
# TODO: preload engines, these *love* to pack things | ||
# in the main project | ||
# | ||
# TODO: allow custom preload hooks. | ||
|
||
add_rails_matchers | ||
end | ||
|
||
private | ||
|
||
def add_rails_matchers | ||
# This logic sucks, instead rails should be come a match expression | ||
# possibly allow match expressions like: `ActionController.subclasses` | ||
return config if config.matcher.match_expressions.any? | ||
|
||
config.with( | ||
matcher: config.matcher.with(match_expressions: rails_expressions) | ||
) | ||
end | ||
|
||
def rails_expressions | ||
expressions = [ | ||
ApplicationController, | ||
*ApplicationController.subclasses, | ||
ApplicationRecord, | ||
*ApplicationRecord.subclasses | ||
].map { |klass| config.expression_parser.apply(klass.name).from_right } | ||
|
||
config.with( | ||
matcher: config.matcher.with( | ||
match_expressions: config.matcher.match_expressions | expressions | ||
) | ||
) | ||
end | ||
|
||
end # Rails | ||
end # Bootstrap | ||
end # Mutant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters