rack-console 1.3.0 → 1.4.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
- SHA1:
3
- metadata.gz: be0561b73e2bb80e0872e203829a7055483f2369
4
- data.tar.gz: 95712c578db0c15afd3df09bf13baed2b156b95f
2
+ SHA256:
3
+ metadata.gz: 58283265efafbac8877ef1cf8962faff21cc5b7e2713c8aaa678fa2b778f47fa
4
+ data.tar.gz: eb40f17f5b8c9be42a863a6feb8b1bd524f857d5a5b6824818f6c8989de13e75
5
5
  SHA512:
6
- metadata.gz: 3b288b43f1dc8c5893e4a275a92e609c700802e2423e215940de8ecc427809e0dcea71e8e6c76b98bc206f16d14411f2d3960b71cd3eb85af0b45a438f551c99
7
- data.tar.gz: e0cb6f3379972332014f1cba0bc4aa1c4fef4e9c930b5ee507385b1c0e73362e391866ebefc09f64063b011736698faa3274e550ff9035816c1726d5cf793e62
6
+ metadata.gz: cce20afdc2f4d1e06c8fbc2402f1837090a6c1cee022226a214f3f8df147c97f889014c2350cc6dc0cdab597194ed120220a762037cbd326b555c75971bc4596
7
+ data.tar.gz: 01240b8bc4b38074877bcb21c724ef2d2b30fa504720c36ee8cba1a60575808bfdb627b61151dfe04dd0bea20462fabdeb26a993d45cde0e6a2db1513ca3bb41
@@ -2,9 +2,9 @@ module Rack
2
2
  class Console
3
3
  module Methods
4
4
  def reload!
5
- ENV['RACK_CONSOLE_PREAMBLE'] = ''
5
+ ENV['IGNORE_RACK_CONSOLE_INTRO'] = 'true'
6
6
  puts 'Reloading...'
7
- exec $0
7
+ Kernel.exec $0, *ARGV
8
8
  end
9
9
 
10
10
  def app
@@ -2,7 +2,7 @@ module Rack
2
2
  class Console
3
3
  class Version
4
4
  MAJOR = 1
5
- MINOR = 3
5
+ MINOR = 4
6
6
  PATCH = 0
7
7
 
8
8
  def self.to_s
data/lib/rack/console.rb CHANGED
@@ -10,26 +10,20 @@ module Rack
10
10
  end
11
11
 
12
12
  def initialize(options = {})
13
- @options = { config: 'config.ru' }.merge(options)
13
+ @options = default_options.merge(options)
14
14
 
15
- ENV['RACK_ENV'] = @options[:environment] || 'development'
16
- ENV['RACK_CONSOLE_PREAMBLE'] ||= "Loading #{ENV['RACK_ENV']} environment (Rack::Console #{Rack::Console::VERSION})"
15
+ ENV['RACK_ENV'] = @options[:environment]
16
+ set_preamble
17
17
 
18
- if includes = @options[:include]
19
- $LOAD_PATH.unshift(*includes)
20
- end
18
+ $LOAD_PATH.unshift(*@options[:include]) if @options[:include]
21
19
 
22
- if library = @options[:require]
23
- require library
24
- end
20
+ require @options[:require] if @options[:require]
25
21
  end
26
22
 
27
23
  def start
28
- if ENV['RACK_CONSOLE_PREAMBLE'] && !ENV['RACK_CONSOLE_PREAMBLE'].empty?
29
- puts ENV['RACK_CONSOLE_PREAMBLE']
30
- end
24
+ puts ENV['RACK_CONSOLE_INTRO'] unless ENV['IGNORE_RACK_CONSOLE_INTRO']
31
25
 
32
- app = Rack::Builder.parse_file(@options[:config]).first
26
+ app = Rack::Builder.parse_file(@options[:config])
33
27
 
34
28
  # Add convenience methods to the top-level binding (main)
35
29
  main.extend(Rack::Console::Methods)
@@ -49,5 +43,21 @@ module Rack
49
43
  def main
50
44
  TOPLEVEL_BINDING.eval('self')
51
45
  end
46
+
47
+ def set_preamble
48
+ return if ENV['RACK_CONSOLE_INTRO']
49
+
50
+ loading = "Loading #{ENV['RACK_ENV']} environment"
51
+ version = "(Rack::Console #{Rack::Console::VERSION})"
52
+
53
+ ENV['RACK_CONSOLE_INTRO'] = "#{loading} #{version}"
54
+ end
55
+
56
+ def default_options
57
+ {
58
+ config: 'config.ru',
59
+ environment: ENV['RACK_ENV'] || 'development'
60
+ }
61
+ end
52
62
  end
53
63
  end
@@ -0,0 +1,22 @@
1
+ require 'rack/console/methods'
2
+
3
+ describe Rack::Console::Methods do
4
+ let(:session) { Object.new }
5
+
6
+ before { session.send :extend, Rack::Console::Methods }
7
+
8
+ describe 'reload!' do
9
+ it 're-executes the running process' do
10
+ expect(Kernel).to receive(:exec).with(/bin\/rspec$/)
11
+
12
+ session.reload!
13
+ end
14
+ end
15
+
16
+ describe 'app' do
17
+ before { session.instance_variable_set(:@app, 'app') }
18
+ subject { session.app }
19
+
20
+ it { is_expected.to eq('app') }
21
+ end
22
+ end
@@ -42,7 +42,27 @@ describe Rack::Console do
42
42
  expect(ENV['RACK_ENV']).to eq('production')
43
43
  end
44
44
 
45
+ describe 'preamble message' do
46
+ it 'defaults to a loading message' do
47
+ preamble = "Loading #{ENV['RACK_ENV']} environment (Rack::Console #{Rack::Console::VERSION})"
48
+
49
+ Rack::Console.new.start
50
+ expect(ENV['RACK_CONSOLE_INTRO']).to eq(preamble)
51
+ end
52
+
53
+ it 'does not override a preamble if one has already been set' do
54
+ ENV['RACK_CONSOLE_INTRO'] = 'Hello, Rack::Console!'
55
+
56
+ expect { Rack::Console.new.start }.not_to change { ENV['RACK_CONSOLE_INTRO'] }
57
+
58
+ ENV['RACK_CONSOLE_INTRO'] = nil
59
+ end
60
+ end
61
+
45
62
  after do
46
63
  Dir.chdir @old_pwd
64
+
65
+ ENV['RACK_ENV'] = 'test'
66
+ ENV['RACK_CONSOLE_INTRO'] = nil
47
67
  end
48
68
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+ ENV['IGNORE_RACK_CONSOLE_INTRO'] = 'true'
3
+
1
4
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
2
5
  RSpec.configure do |config|
3
6
  # Allow more verbose output when running an individual spec file.
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Celis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-06 00:00:00.000000000 Z
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.1'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack-test
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -71,13 +71,14 @@ files:
71
71
  - lib/rack/console/methods.rb
72
72
  - lib/rack/console/session.rb
73
73
  - lib/rack/console/version.rb
74
+ - spec/rack/console/methods_spec.rb
74
75
  - spec/rack/console_spec.rb
75
76
  - spec/spec_helper.rb
76
77
  homepage: https://github.com/davidcelis/rack-console
77
78
  licenses:
78
79
  - MIT
79
80
  metadata: {}
80
- post_install_message:
81
+ post_install_message:
81
82
  rdoc_options: []
82
83
  require_paths:
83
84
  - lib
@@ -92,12 +93,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.3.0
97
- signing_key:
96
+ rubygems_version: 3.3.21
97
+ signing_key:
98
98
  specification_version: 4
99
99
  summary: "`rails console` for your Rack applications"
100
100
  test_files:
101
+ - spec/rack/console/methods_spec.rb
101
102
  - spec/rack/console_spec.rb
102
103
  - spec/spec_helper.rb
103
- has_rdoc: