Skip to content

Commit

Permalink
Add rails specific environment boostrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Dec 2, 2020
1 parent cfa6b69 commit 62f3263
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/mutant/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module Bootstrap
#
# rubocop:disable Metrics/MethodLength
def self.apply(world, config)
# TOOD: Have this behind a conditional.
config = Rails.call(world, config)

env = Env
Expand Down
38 changes: 29 additions & 9 deletions lib/mutant/bootstrap/rails.rb
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
2 changes: 0 additions & 2 deletions lib/mutant/license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module License
#
# @api private
def self.apply(world)
return Either::Right.new(nil)

load_mutant_license(world)
.fmap { license_path(world) }
.bind { |path| Subscription.load(world, world.json.load(path)) }
Expand Down

0 comments on commit 62f3263

Please sign in to comment.