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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c9853207a501d22e1ccc2c0fe9b705ffd690879
4
- data.tar.gz: 316aeb4748407057991eebed4221e343fc6399be
3
+ metadata.gz: be0561b73e2bb80e0872e203829a7055483f2369
4
+ data.tar.gz: 95712c578db0c15afd3df09bf13baed2b156b95f
5
5
  SHA512:
6
- metadata.gz: 27f19bddc8c27b4e73548c68b92b504519f96f70b2cecdfe3b79f6df6767ac2081a61649fa83e05dd8bfae26b74340a9af5955a1e79e6c5233fb66294f9dcb6b
7
- data.tar.gz: c65c2681b8774fe82375603d0fb8f1b246544da9186aaf8f44ddf4e9fb212666e4862785391180b0ca67882e2aab778eb42f3cd06f66bb5176902d9a767ca87e
6
+ metadata.gz: 3b288b43f1dc8c5893e4a275a92e609c700802e2423e215940de8ecc427809e0dcea71e8e6c76b98bc206f16d14411f2d3960b71cd3eb85af0b45a438f551c99
7
+ data.tar.gz: e0cb6f3379972332014f1cba0bc4aa1c4fef4e9c930b5ee507385b1c0e73362e391866ebefc09f64063b011736698faa3274e550ff9035816c1726d5cf793e62
data/bin/rack-console CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rack/console'
4
+ require 'optparse'
4
5
 
5
6
  options = {}
6
7
 
@@ -0,0 +1,15 @@
1
+ module Rack
2
+ class Console
3
+ module Methods
4
+ def reload!
5
+ ENV['RACK_CONSOLE_PREAMBLE'] = ''
6
+ puts 'Reloading...'
7
+ exec $0
8
+ end
9
+
10
+ def app
11
+ @app
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'rack/test'
2
+
3
+ module Rack
4
+ class Console
5
+ class Session
6
+ include Rack::Test::Methods
7
+ attr_reader :app
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,7 +2,7 @@ module Rack
2
2
  class Console
3
3
  class Version
4
4
  MAJOR = 1
5
- MINOR = 2
5
+ MINOR = 3
6
6
  PATCH = 0
7
7
 
8
8
  def self.to_s
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
- Rack::Builder.parse_file(@options[:config])
23
-
24
- Object.class_eval do
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
@@ -3,47 +3,46 @@ require 'irb'
3
3
 
4
4
  describe Rack::Console do
5
5
  before do
6
- @old_cwd = Dir.pwd
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
- 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')
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
- Rack::Console.new.start
17
- end
17
+ Rack::Console.new.start
18
18
  end
19
19
 
20
- context 'overriding the location of config.ru' do
21
- before { Dir.chdir @old_cwd }
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
- 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
26
+ Rack::Console.new(config: 'spec/support/config.ru').start
28
27
  end
29
28
 
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
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
- 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
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.2.0
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-02 00:00:00.000000000 Z
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