Skip to content

Commit 62f3263

Browse files
committed
Add rails specific environment boostrapping
1 parent cfa6b69 commit 62f3263

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

lib/mutant/bootstrap.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module Bootstrap
3131
#
3232
# rubocop:disable Metrics/MethodLength
3333
def self.apply(world, config)
34+
# TOOD: Have this behind a conditional.
3435
config = Rails.call(world, config)
3536

3637
env = Env

lib/mutant/bootstrap/rails.rb

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
11
module Mutant
22
module Bootstrap
3-
module Rails
4-
def self.call(world, config)
3+
class Rails
4+
include Procto.call, Concord.new(:world, :config)
5+
6+
def call
57
world.stdout.puts('Loading mutant config from rails environment')
68

7-
# TODO move to world.
9+
# TODO add env to world.
10+
#
11+
# Make actual env configurable
812
ENV['RAILS_ENV'] = 'test'
913

1014
world.kernel.require('./config/environment.rb')
1115

1216
::Rails.application.eager_load!
1317

18+
# TODO: preload engines, these *love* to pack things
19+
# in the main project
20+
#
21+
# TODO: allow custom preload hooks.
22+
23+
add_rails_matchers
24+
end
25+
26+
private
27+
28+
def add_rails_matchers
29+
# This logic sucks, instead rails should be come a match expression
30+
# possibly allow match expressions like: `ActionController.subclasses`
31+
return config if config.matcher.match_expressions.any?
32+
33+
config.with(
34+
matcher: config.matcher.with(match_expressions: rails_expressions)
35+
)
36+
end
37+
38+
def rails_expressions
1439
expressions = [
1540
ApplicationController,
1641
*ApplicationController.subclasses,
1742
ApplicationRecord,
1843
*ApplicationRecord.subclasses
1944
].map { |klass| config.expression_parser.apply(klass.name).from_right }
20-
21-
config.with(
22-
matcher: config.matcher.with(
23-
match_expressions: config.matcher.match_expressions | expressions
24-
)
25-
)
2645
end
46+
2747
end # Rails
2848
end # Bootstrap
2949
end # Mutant

lib/mutant/license.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ module License
1313
#
1414
# @api private
1515
def self.apply(world)
16-
return Either::Right.new(nil)
17-
1816
load_mutant_license(world)
1917
.fmap { license_path(world) }
2018
.bind { |path| Subscription.load(world, world.json.load(path)) }

0 commit comments

Comments
 (0)