rack-console 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/rack-console +16 -4
- data/lib/rack/console.rb +24 -3
- data/lib/rack/console/version.rb +1 -1
- data/spec/rack/console_spec.rb +40 -4
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c9853207a501d22e1ccc2c0fe9b705ffd690879
|
4
|
+
data.tar.gz: 316aeb4748407057991eebed4221e343fc6399be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27f19bddc8c27b4e73548c68b92b504519f96f70b2cecdfe3b79f6df6767ac2081a61649fa83e05dd8bfae26b74340a9af5955a1e79e6c5233fb66294f9dcb6b
|
7
|
+
data.tar.gz: c65c2681b8774fe82375603d0fb8f1b246544da9186aaf8f44ddf4e9fb212666e4862785391180b0ca67882e2aab778eb42f3cd06f66bb5176902d9a767ca87e
|
data/bin/rack-console
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rack/console'
|
4
|
-
require 'optparse'
|
5
4
|
|
6
5
|
options = {}
|
6
|
+
|
7
7
|
OptionParser.new do |opts|
|
8
|
-
opts.banner = 'USAGE: rack-console [
|
8
|
+
opts.banner = 'USAGE: rack-console [OPTIONS] [ENVIRONMENT]'
|
9
|
+
|
10
|
+
opts.on('-c', '--config [RACKUP_FILE]', 'Specify a rackup config file') do |config|
|
11
|
+
options[:config] = config
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on('-r', '--require [LIBRARY]', 'Require a file or library before the Rack console loads') do |library|
|
15
|
+
options[:require] = library
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-I', '--include [PATHS]', 'Add paths (colon-separated) to the $LOAD_PATH') do |paths|
|
19
|
+
options[:include] = paths.split(':')
|
20
|
+
end
|
9
21
|
|
10
22
|
opts.on('-v', '--version', 'Print version and exit') do |v|
|
11
23
|
puts Rack::Console::VERSION
|
@@ -14,7 +26,7 @@ OptionParser.new do |opts|
|
|
14
26
|
end.parse!
|
15
27
|
|
16
28
|
if environment = ARGV.shift
|
17
|
-
|
29
|
+
options[:environment] = environment
|
18
30
|
end
|
19
31
|
|
20
|
-
Rack::Console.start
|
32
|
+
Rack::Console.new(options).start
|
data/lib/rack/console.rb
CHANGED
@@ -1,11 +1,32 @@
|
|
1
1
|
require 'rack'
|
2
|
-
|
3
2
|
require 'rack/console/version'
|
3
|
+
require 'optparse'
|
4
4
|
|
5
5
|
module Rack
|
6
6
|
class Console
|
7
|
-
def
|
8
|
-
|
7
|
+
def initialize(options = {})
|
8
|
+
@options = { config: 'config.ru' }.merge(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
ENV['RACK_ENV'] = @options[:environment] || 'development'
|
13
|
+
|
14
|
+
if includes = @options[:include]
|
15
|
+
$LOAD_PATH.unshift(*includes)
|
16
|
+
end
|
17
|
+
|
18
|
+
if library = @options[:require]
|
19
|
+
require library
|
20
|
+
end
|
21
|
+
|
22
|
+
Rack::Builder.parse_file(@options[:config])
|
23
|
+
|
24
|
+
Object.class_eval do
|
25
|
+
def reload!
|
26
|
+
puts 'Reloading...'
|
27
|
+
exec $0
|
28
|
+
end
|
29
|
+
end
|
9
30
|
|
10
31
|
begin
|
11
32
|
require 'pry'
|
data/lib/rack/console/version.rb
CHANGED
data/spec/rack/console_spec.rb
CHANGED
@@ -2,12 +2,48 @@ require 'rack/console'
|
|
2
2
|
require 'irb'
|
3
3
|
|
4
4
|
describe Rack::Console do
|
5
|
-
before
|
5
|
+
before do
|
6
|
+
@old_cwd = Dir.pwd
|
7
|
+
Dir.chdir File.expand_path('../../support', __FILE__)
|
6
8
|
|
7
|
-
it 'parses config.ru in the current working directory' do
|
8
|
-
expect(Rack::Builder).to receive(:parse_file).with('config.ru')
|
9
9
|
expect(IRB).to receive(:start)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'parsing config.ru' do
|
13
|
+
it 'defaults to a config.ru file in the current working directory' do
|
14
|
+
expect(Rack::Builder).to receive(:parse_file).with('config.ru')
|
15
|
+
|
16
|
+
Rack::Console.new.start
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'overriding the location of config.ru' do
|
21
|
+
before { Dir.chdir @old_cwd }
|
22
|
+
|
23
|
+
it 'accepts the --config option to override the location of config.ru' do
|
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
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'requiring libraries' do
|
31
|
+
it 'accepts the --require option' do
|
32
|
+
Rack::Console.new(require: 'json').start
|
33
|
+
expect { JSON }.not_to raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'adding paths to $LOAD_PATH' do
|
38
|
+
it 'accepts the --require option' do
|
39
|
+
Rack::Console.new(include: ['lib', 'spec']).start
|
40
|
+
expect($LOAD_PATH).to include('lib')
|
41
|
+
expect($LOAD_PATH).to include('spec')
|
42
|
+
end
|
43
|
+
end
|
10
44
|
|
11
|
-
|
45
|
+
it 'accepts an argument to set the environment' do
|
46
|
+
Rack::Console.new(environment: 'production').start
|
47
|
+
expect(ENV['RACK_ENV']).to eq('production')
|
12
48
|
end
|
13
49
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,7 @@ RSpec.configure do |config|
|
|
10
10
|
# Print the 10 slowest examples and example groups at the
|
11
11
|
# end of the spec run, to help surface which specs are running
|
12
12
|
# particularly slow.
|
13
|
-
config.profile_examples = 10
|
13
|
+
# config.profile_examples = 10
|
14
14
|
|
15
15
|
# Run specs in random order to surface order dependencies. If you find an
|
16
16
|
# order dependency and want to debug it, you can fix the order by providing
|
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.2.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-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|