Skip to content

Commit c406729

Browse files
committed
Move most logic out of the initializer into start
1 parent 2dbb201 commit c406729

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/rack/console.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@ def self.start(options = {})
1010
end
1111

1212
def initialize(options = {})
13-
@options = default_options.merge(options)
13+
options = default_options.merge(options)
1414

15-
ENV["RACK_ENV"] = @options[:environment]
16-
set_preamble
17-
18-
$LOAD_PATH.unshift(*@options[:include]) if @options[:include]
19-
20-
require @options[:require] if @options[:require]
15+
@config = options[:config]
16+
@environment = options[:environment]
17+
@include = options[:include]
18+
@require = options[:require]
2119
end
2220

2321
def start
24-
puts ENV["RACK_CONSOLE_INTRO"] unless ENV["IGNORE_RACK_CONSOLE_INTRO"]
22+
ENV["RACK_ENV"] = @environment
23+
$LOAD_PATH.unshift(*@include) if @include
24+
require @require if @require
2525

26-
app = Rack::Builder.parse_file(@options[:config])
26+
set_preamble
27+
28+
puts ENV["RACK_CONSOLE_INTRO"] unless ENV["IGNORE_RACK_CONSOLE_INTRO"]
2729

2830
# Add convenience methods to the top-level binding (main)
29-
main.extend(Rack::Console::Methods)
31+
app = Rack::Builder.parse_file(@config)
3032
main.instance_variable_set(:@app, Rack::Console::Session.new(app))
33+
main.extend(Rack::Console::Methods)
3134

3235
if Gem::Specification.find_all_by_name("pry").any?
3336
require "pry"
@@ -56,7 +59,7 @@ def set_preamble
5659
def default_options
5760
{
5861
config: "config.ru",
59-
environment: ENV["RACK_ENV"] || "development"
62+
environment: ENV.fetch("RACK_ENV", "development")
6063
}
6164
end
6265
end

0 commit comments

Comments
 (0)