rack-console 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rack-console +1 -0
- data/lib/rack/console/methods.rb +15 -0
- data/lib/rack/console/session.rb +14 -0
- data/lib/rack/console/version.rb +1 -1
- data/lib/rack/console.rb +23 -10
- data/spec/rack/console_spec.rb +23 -24
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be0561b73e2bb80e0872e203829a7055483f2369
|
4
|
+
data.tar.gz: 95712c578db0c15afd3df09bf13baed2b156b95f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b288b43f1dc8c5893e4a275a92e609c700802e2423e215940de8ecc427809e0dcea71e8e6c76b98bc206f16d14411f2d3960b71cd3eb85af0b45a438f551c99
|
7
|
+
data.tar.gz: e0cb6f3379972332014f1cba0bc4aa1c4fef4e9c930b5ee507385b1c0e73362e391866ebefc09f64063b011736698faa3274e550ff9035816c1726d5cf793e62
|
data/bin/rack-console
CHANGED
data/lib/rack/console/version.rb
CHANGED
data/lib/rack/console.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
require 'rack'
|
2
|
+
require 'rack/console/methods'
|
3
|
+
require 'rack/console/session'
|
2
4
|
require 'rack/console/version'
|
3
|
-
require 'optparse'
|
4
5
|
|
5
6
|
module Rack
|
6
7
|
class Console
|
8
|
+
def self.start(options = {})
|
9
|
+
self.new(options).start
|
10
|
+
end
|
11
|
+
|
7
12
|
def initialize(options = {})
|
8
13
|
@options = { config: 'config.ru' }.merge(options)
|
9
|
-
end
|
10
14
|
|
11
|
-
def start
|
12
15
|
ENV['RACK_ENV'] = @options[:environment] || 'development'
|
16
|
+
ENV['RACK_CONSOLE_PREAMBLE'] ||= "Loading #{ENV['RACK_ENV']} environment (Rack::Console #{Rack::Console::VERSION})"
|
13
17
|
|
14
18
|
if includes = @options[:include]
|
15
19
|
$LOAD_PATH.unshift(*includes)
|
@@ -18,16 +22,19 @@ module Rack
|
|
18
22
|
if library = @options[:require]
|
19
23
|
require library
|
20
24
|
end
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def reload!
|
26
|
-
puts 'Reloading...'
|
27
|
-
exec $0
|
28
|
-
end
|
27
|
+
def start
|
28
|
+
if ENV['RACK_CONSOLE_PREAMBLE'] && !ENV['RACK_CONSOLE_PREAMBLE'].empty?
|
29
|
+
puts ENV['RACK_CONSOLE_PREAMBLE']
|
29
30
|
end
|
30
31
|
|
32
|
+
app = Rack::Builder.parse_file(@options[:config]).first
|
33
|
+
|
34
|
+
# Add convenience methods to the top-level binding (main)
|
35
|
+
main.extend(Rack::Console::Methods)
|
36
|
+
main.instance_variable_set(:@app, Rack::Console::Session.new(app))
|
37
|
+
|
31
38
|
begin
|
32
39
|
require 'pry'
|
33
40
|
Pry.start
|
@@ -36,5 +43,11 @@ module Rack
|
|
36
43
|
IRB.start
|
37
44
|
end
|
38
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def main
|
50
|
+
TOPLEVEL_BINDING.eval('self')
|
51
|
+
end
|
39
52
|
end
|
40
53
|
end
|
data/spec/rack/console_spec.rb
CHANGED
@@ -3,47 +3,46 @@ require 'irb'
|
|
3
3
|
|
4
4
|
describe Rack::Console do
|
5
5
|
before do
|
6
|
-
@
|
6
|
+
@old_pwd = Dir.pwd
|
7
7
|
Dir.chdir File.expand_path('../../support', __FILE__)
|
8
8
|
|
9
9
|
expect(IRB).to receive(:start)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
it 'defaults to a config.ru file in the current working directory' do
|
13
|
+
expect(Rack::Builder).to receive(:parse_file).
|
14
|
+
with('config.ru').
|
15
|
+
and_call_original
|
15
16
|
|
16
|
-
|
17
|
-
end
|
17
|
+
Rack::Console.new.start
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
it 'accepts the --config option to override the location of config.ru' do
|
21
|
+
Dir.chdir @old_pwd
|
22
|
+
expect(Rack::Builder).to receive(:parse_file).
|
23
|
+
with('spec/support/config.ru').
|
24
|
+
and_call_original
|
22
25
|
|
23
|
-
|
24
|
-
expect(Rack::Builder).to receive(:parse_file).with('spec/support/config.ru')
|
25
|
-
|
26
|
-
Rack::Console.new(config: 'spec/support/config.ru').start
|
27
|
-
end
|
26
|
+
Rack::Console.new(config: 'spec/support/config.ru').start
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
expect { JSON }.not_to raise_error
|
34
|
-
end
|
29
|
+
it 'accepts the --require option to require a file or library' do
|
30
|
+
Rack::Console.new(require: 'json').start
|
31
|
+
expect { JSON }.not_to raise_error
|
35
32
|
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
expect($LOAD_PATH).to include('spec')
|
42
|
-
end
|
34
|
+
it 'accepts the --require option to add paths to $LOAD_PATH' do
|
35
|
+
Rack::Console.new(include: ['lib', 'spec']).start
|
36
|
+
expect($LOAD_PATH).to include('lib')
|
37
|
+
expect($LOAD_PATH).to include('spec')
|
43
38
|
end
|
44
39
|
|
45
40
|
it 'accepts an argument to set the environment' do
|
46
41
|
Rack::Console.new(environment: 'production').start
|
47
42
|
expect(ENV['RACK_ENV']).to eq('production')
|
48
43
|
end
|
44
|
+
|
45
|
+
after do
|
46
|
+
Dir.chdir @old_pwd
|
47
|
+
end
|
49
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-test
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,6 +68,8 @@ files:
|
|
54
68
|
- bin/rack-console
|
55
69
|
- lib/rack-console.rb
|
56
70
|
- lib/rack/console.rb
|
71
|
+
- lib/rack/console/methods.rb
|
72
|
+
- lib/rack/console/session.rb
|
57
73
|
- lib/rack/console/version.rb
|
58
74
|
- spec/rack/console_spec.rb
|
59
75
|
- spec/spec_helper.rb
|