rack-console 1.4.1 → 2.0.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
  SHA256:
3
- metadata.gz: 252f28c967c58786b0985c7a8d322289f9175d7ff52f3db48e48e684406c3f5a
4
- data.tar.gz: 47379d7814016dc3c3ad37625d4c6766370ba46330549dc24d753aec52764fe0
3
+ metadata.gz: cc0a409ebaf0b1151c0e88fe3b1f0263bb24fde3a0ca90f02d2974f99d9fabf3
4
+ data.tar.gz: 8378656873d94a7111a08575ecd1b29b03511b65fdc2999dbddf12da7d7ffcf6
5
5
  SHA512:
6
- metadata.gz: 9a53264d670e31ca3665675af08aa935134084addaaef007727e6b190e91572bc31e552dbf171b43eac1f46ac61856ee4eacd0fb35301fb7bd2afa2d89e495a5
7
- data.tar.gz: 46e2742cdaf1a566f8eafb70c1486e16b8accf457f88eb0881ff8ad2e800a3955798199dd1972cc705dd62ca27ca8f976c4745843ce7e37f9e797747c27fb485
6
+ metadata.gz: 2fe1d7a661d63aed888caaf0cc8493a21e713b8991d86932e37bae13698ccf3c488ccddf215ed4a9404acd61d9182d82557bdda6145789dcfbbd36b16e3aec03
7
+ data.tar.gz: e46d313a7ec4f022a169f90427079cea724de4f1341e7dbf703cc0941c00e00dc64814e769a57b2959a27d25e1102f37ca5f177ab6e3b37ff904b20cc59469e8
data/bin/rack-console CHANGED
@@ -1,33 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rack/console'
4
- require 'optparse'
3
+ require "rack/console"
4
+ require "optparse"
5
5
 
6
6
  options = {}
7
7
 
8
8
  OptionParser.new do |opts|
9
- opts.banner = 'USAGE: rack-console [OPTIONS] [ENVIRONMENT]'
9
+ opts.banner = "USAGE: rack-console [options]"
10
10
 
11
- opts.on('-c', '--config [RACKUP_FILE]', 'Specify a rackup config file') do |config|
11
+ opts.on("-c", "--config [RACKUP_FILE]", "Specify a rackup config file (default: ./config.ru)") do |config|
12
12
  options[:config] = config
13
13
  end
14
14
 
15
- opts.on('-r', '--require [LIBRARY]', 'Require a file or library before the Rack console loads') do |library|
15
+ opts.on("-e", "--environment [ENVIRONMENT]", "Specify the Rack environment (default: development)") do |environment|
16
+ options[:environment] = environment
17
+ end
18
+
19
+ opts.on("-I", "--include [PATHS]", "Add paths (colon-separated) to the $LOAD_PATH") do |paths|
20
+ options[:include] = paths.split(":")
21
+ end
22
+
23
+ opts.on("-r", "--require [LIBRARY]", "Require a file or library before the Rack console loads") do |library|
16
24
  options[:require] = library
17
25
  end
18
26
 
19
- opts.on('-I', '--include [PATHS]', 'Add paths (colon-separated) to the $LOAD_PATH') do |paths|
20
- options[:include] = paths.split(':')
27
+ opts.on("-P", "--[no-]pry", "Use Pry if available or explicitly disable it") do |pry|
28
+ options[:pry] = pry
21
29
  end
22
30
 
23
- opts.on('-v', '--version', 'Print version and exit') do |v|
31
+ opts.on("-v", "--version", "Print version and exit") do |v|
24
32
  puts Rack::Console::VERSION
25
33
  exit 0
26
34
  end
27
35
  end.parse!
28
36
 
29
- if environment = ARGV.shift
30
- options[:environment] = environment
31
- end
32
-
33
37
  Rack::Console.new(options).start
@@ -2,8 +2,8 @@ module Rack
2
2
  class Console
3
3
  module Methods
4
4
  def reload!
5
- ENV['IGNORE_RACK_CONSOLE_INTRO'] = 'true'
6
- puts 'Reloading...'
5
+ ENV["IGNORE_RACK_CONSOLE_INTRO"] = "true"
6
+ puts "Reloading..."
7
7
  Kernel.exec $0, *ARGV
8
8
  end
9
9
 
@@ -1,9 +1,10 @@
1
- require 'rack/test'
1
+ require "rack/test"
2
2
 
3
3
  module Rack
4
4
  class Console
5
5
  class Session
6
6
  include Rack::Test::Methods
7
+
7
8
  attr_reader :app
8
9
 
9
10
  def initialize(app)
@@ -1,12 +1,12 @@
1
1
  module Rack
2
2
  class Console
3
3
  class Version
4
- MAJOR = 1
5
- MINOR = 4
6
- PATCH = 1
4
+ MAJOR = 2
5
+ MINOR = 0
6
+ PATCH = 0
7
7
 
8
8
  def self.to_s
9
- [MAJOR, MINOR, PATCH].join('.')
9
+ [MAJOR, MINOR, PATCH].join(".")
10
10
  end
11
11
  end
12
12
 
data/lib/rack/console.rb CHANGED
@@ -1,39 +1,43 @@
1
- require 'rack'
2
- require 'rack/console/methods'
3
- require 'rack/console/session'
4
- require 'rack/console/version'
1
+ require "rack"
2
+ require "rack/console/methods"
3
+ require "rack/console/session"
4
+ require "rack/console/version"
5
5
 
6
6
  module Rack
7
7
  class Console
8
8
  def self.start(options = {})
9
- self.new(options).start
9
+ new(options).start
10
10
  end
11
11
 
12
12
  def initialize(options = {})
13
- @options = default_options.merge(options)
13
+ options = default_options.merge(options)
14
14
 
15
- ENV['RACK_ENV'] = @options[:environment]
16
- set_preamble
17
-
18
- $LOAD_PATH.unshift(*@options[:include]) if @options[:include]
19
-
20
- require @options[:require] if @options[:require]
15
+ @config = options[:config]
16
+ @environment = options[:environment]
17
+ @include = options[:include]
18
+ @require = options[:require]
19
+ @use_pry = !!options[:pry]
21
20
  end
22
21
 
23
22
  def start
24
- puts ENV['RACK_CONSOLE_INTRO'] unless ENV['IGNORE_RACK_CONSOLE_INTRO']
23
+ ENV["RACK_ENV"] = @environment
24
+ $LOAD_PATH.unshift(*@include) if @include
25
+ require @require if @require
25
26
 
26
- app = Rack::Builder.parse_file(@options[:config])
27
+ set_preamble
28
+
29
+ puts ENV["RACK_CONSOLE_INTRO"] unless ENV["IGNORE_RACK_CONSOLE_INTRO"]
27
30
 
28
31
  # Add convenience methods to the top-level binding (main)
29
- main.extend(Rack::Console::Methods)
32
+ app = Rack::Builder.parse_file(@config)
30
33
  main.instance_variable_set(:@app, Rack::Console::Session.new(app))
34
+ main.extend(Rack::Console::Methods)
31
35
 
32
- if Gem::Specification.find_all_by_name('pry').any?
33
- require 'pry'
36
+ if Gem::Specification.find_all_by_name("pry").any? && @use_pry
37
+ require "pry"
34
38
  Pry.start
35
39
  else
36
- require 'irb'
40
+ require "irb"
37
41
  IRB.start
38
42
  end
39
43
  end
@@ -41,22 +45,22 @@ module Rack
41
45
  private
42
46
 
43
47
  def main
44
- TOPLEVEL_BINDING.eval('self')
48
+ TOPLEVEL_BINDING.eval("self")
45
49
  end
46
50
 
47
51
  def set_preamble
48
- return if ENV['RACK_CONSOLE_INTRO']
52
+ return if ENV["RACK_CONSOLE_INTRO"]
49
53
 
50
- loading = "Loading #{ENV['RACK_ENV']} environment"
54
+ loading = "Loading #{ENV["RACK_ENV"]} environment"
51
55
  version = "(Rack::Console #{Rack::Console::VERSION})"
52
56
 
53
- ENV['RACK_CONSOLE_INTRO'] = "#{loading} #{version}"
57
+ ENV["RACK_CONSOLE_INTRO"] = "#{loading} #{version}"
54
58
  end
55
59
 
56
60
  def default_options
57
61
  {
58
- config: 'config.ru',
59
- environment: ENV['RACK_ENV'] || 'development'
62
+ config: "config.ru",
63
+ environment: ENV.fetch("RACK_ENV", "development")
60
64
  }
61
65
  end
62
66
  end
data/lib/rack-console.rb CHANGED
@@ -1 +1 @@
1
- require 'rack/console'
1
+ require "rack/console"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Celis
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rack
@@ -39,19 +38,19 @@ dependencies:
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: rspec
41
+ name: irb
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - "~>"
44
+ - - ">="
46
45
  - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
46
+ version: '0'
47
+ type: :runtime
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - "~>"
51
+ - - ">="
53
52
  - !ruby/object:Gem::Version
54
- version: '3.0'
53
+ version: '0'
55
54
  description: |
56
55
  Find yourself missing a `rails console` analogue in your other Ruby web
57
56
  applications? This lightweight gem provides a Rack::Console that will load
@@ -71,14 +70,10 @@ files:
71
70
  - lib/rack/console/methods.rb
72
71
  - lib/rack/console/session.rb
73
72
  - lib/rack/console/version.rb
74
- - spec/rack/console/methods_spec.rb
75
- - spec/rack/console_spec.rb
76
- - spec/spec_helper.rb
77
73
  homepage: https://github.com/davidcelis/rack-console
78
74
  licenses:
79
75
  - MIT
80
76
  metadata: {}
81
- post_install_message:
82
77
  rdoc_options: []
83
78
  require_paths:
84
79
  - lib
@@ -93,11 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
88
  - !ruby/object:Gem::Version
94
89
  version: '0'
95
90
  requirements: []
96
- rubygems_version: 3.5.3
97
- signing_key:
91
+ rubygems_version: 3.7.2
98
92
  specification_version: 4
99
93
  summary: "`rails console` for your Rack applications"
100
- test_files:
101
- - spec/rack/console/methods_spec.rb
102
- - spec/rack/console_spec.rb
103
- - spec/spec_helper.rb
94
+ test_files: []
@@ -1,22 +0,0 @@
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
@@ -1,68 +0,0 @@
1
- require 'rack/console'
2
- require 'irb'
3
-
4
- describe Rack::Console do
5
- before do
6
- @old_pwd = Dir.pwd
7
- Dir.chdir File.expand_path('../../support', __FILE__)
8
-
9
- expect(IRB).to receive(:start)
10
- end
11
-
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
16
-
17
- Rack::Console.new.start
18
- end
19
-
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
25
-
26
- Rack::Console.new(config: 'spec/support/config.ru').start
27
- end
28
-
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
32
- end
33
-
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')
38
- end
39
-
40
- it 'accepts an argument to set the environment' do
41
- Rack::Console.new(environment: 'production').start
42
- expect(ENV['RACK_ENV']).to eq('production')
43
- end
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
-
62
- after do
63
- Dir.chdir @old_pwd
64
-
65
- ENV['RACK_ENV'] = 'test'
66
- ENV['RACK_CONSOLE_INTRO'] = nil
67
- end
68
- end
data/spec/spec_helper.rb DELETED
@@ -1,52 +0,0 @@
1
- ENV['RACK_ENV'] = 'test'
2
- ENV['IGNORE_RACK_CONSOLE_INTRO'] = 'true'
3
-
4
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
5
- RSpec.configure do |config|
6
- # Allow more verbose output when running an individual spec file.
7
- if config.files_to_run.one?
8
- # Use the documentation formatter for detailed output, unless a formatter
9
- # has already been configured (e.g. via a command-line flag).
10
- config.default_formatter = 'doc'
11
- end
12
-
13
- # Print the 10 slowest examples and example groups at the
14
- # end of the spec run, to help surface which specs are running
15
- # particularly slow.
16
- # config.profile_examples = 10
17
-
18
- # Run specs in random order to surface order dependencies. If you find an
19
- # order dependency and want to debug it, you can fix the order by providing
20
- # the seed, which is printed after each run.
21
- # --seed 1234
22
- config.order = :random
23
-
24
- # Seed global randomization in this process using the `--seed` CLI option.
25
- # Setting this allows you to use `--seed` to deterministically reproduce
26
- # test failures related to randomization by passing the same `--seed` value
27
- # as the one that triggered the failure.
28
- Kernel.srand config.seed
29
-
30
- # rspec-expectations config goes here. You can use an alternate
31
- # assertion/expectation library such as wrong or the stdlib/minitest
32
- # assertions if you prefer.
33
- config.expect_with :rspec do |expectations|
34
- # Enable only the newer, non-monkey-patching expect syntax.
35
- # For more details, see:
36
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
37
- expectations.syntax = :expect
38
- end
39
-
40
- # rspec-mocks config goes here. You can use an alternate test double
41
- # library (such as bogus or mocha) by changing the `mock_with` option here.
42
- config.mock_with :rspec do |mocks|
43
- # Enable only the newer, non-monkey-patching expect syntax.
44
- # For more details, see:
45
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
46
- mocks.syntax = :expect
47
-
48
- # Prevents you from mocking or stubbing a method that does not exist on
49
- # a real object. This is generally recommended.
50
- mocks.verify_partial_doubles = true
51
- end
52
- end