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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfc652a285ac93d608e77f046327fb435dbc8ae1
4
- data.tar.gz: e0021666f669b564875f3f6b309b37759cefb2b4
3
+ metadata.gz: 0c9853207a501d22e1ccc2c0fe9b705ffd690879
4
+ data.tar.gz: 316aeb4748407057991eebed4221e343fc6399be
5
5
  SHA512:
6
- metadata.gz: 040533fd6335b44f57b60fb8de8d553ab2dc4bf93f52153cc37b2bd5e5daf445684f55facf15ac08aede88b6ac8b230f9bc8dcd74f0b330319ec6c3f8b38f6df
7
- data.tar.gz: cfe62dadd9eba3e66b829492c415d24357faf8dbf91a189c5ae12e976a938fdbd2cfbd78db9ed60f42ab88d3399b3adce9cf2d1793f8e27b661c04534a60e723
6
+ metadata.gz: 27f19bddc8c27b4e73548c68b92b504519f96f70b2cecdfe3b79f6df6767ac2081a61649fa83e05dd8bfae26b74340a9af5955a1e79e6c5233fb66294f9dcb6b
7
+ data.tar.gz: c65c2681b8774fe82375603d0fb8f1b246544da9186aaf8f44ddf4e9fb212666e4862785391180b0ca67882e2aab778eb42f3cd06f66bb5176902d9a767ca87e
@@ -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 [options] environment'
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
- ENV['RACK_ENV'] = environment
29
+ options[:environment] = environment
18
30
  end
19
31
 
20
- Rack::Console.start
32
+ Rack::Console.new(options).start
@@ -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 self.start
8
- Rack::Builder.parse_file('config.ru')
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'
@@ -2,7 +2,7 @@ module Rack
2
2
  class Console
3
3
  class Version
4
4
  MAJOR = 1
5
- MINOR = 1
5
+ MINOR = 2
6
6
  PATCH = 0
7
7
 
8
8
  def self.to_s
@@ -2,12 +2,48 @@ require 'rack/console'
2
2
  require 'irb'
3
3
 
4
4
  describe Rack::Console do
5
- before { Dir.chdir 'spec/support' }
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
- Rack::Console.start
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
@@ -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.1.0
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-01 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack