spinels-racksh 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.txt +34 -0
- data/README.markdown +146 -0
- data/bin/racksh +25 -0
- data/lib/racksh/init.rb +53 -0
- data/lib/racksh/irb.rb +2 -0
- data/lib/racksh/session.rb +18 -0
- data/lib/racksh/version.rb +5 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b0128a9c2c6ea277f29e4c165aba04dca9cb3d63b8fbadd9247e48c66d41d676
|
4
|
+
data.tar.gz: a7df62aeb44cb8989d3639ce3a9fe03b71a533cce56fc9675e328f755dc0972a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1edfcb6ea64b3c6d2b2f0af11d6c44950d554c10763b566697c05d8c9f6de095ea01d1e82bb43d3836d14cb452d24bd0dead20cdb65d6061e18e2f5fb32c9d3
|
7
|
+
data.tar.gz: '049c7337e34ef1ce193d93b19c96e8183725c396224dac9e1908cf7789a8a3e6f91df39833953a207e5d9c5be6ddfad21184600d2cbd064a80024a7fb295225c'
|
data/CHANGELOG.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
=== 0.9.8 / 2010-09-03
|
2
|
+
|
3
|
+
* added option to load racksh into existing irb session
|
4
|
+
|
5
|
+
=== 0.9.7 / ?
|
6
|
+
=== 0.9.6 / ?
|
7
|
+
|
8
|
+
=== 0.9.5 / 2010-01-31
|
9
|
+
|
10
|
+
* added application reloading with "reload!"
|
11
|
+
|
12
|
+
=== 0.9.4 / 2009-11-19
|
13
|
+
|
14
|
+
* added loading irb/completion
|
15
|
+
* added support for session setup, loaded from .rackshrc in user's home directory and app's directory
|
16
|
+
* prevented STDOUT & STDERR to be reopened
|
17
|
+
* added showing simple prompt (>>) like Rails console
|
18
|
+
* added printing startup info in colors
|
19
|
+
|
20
|
+
=== 0.9.3 / 2009-11-17
|
21
|
+
|
22
|
+
* exposed Rack::Test::Methods via $rack variable
|
23
|
+
|
24
|
+
=== 0.9.2 / 2009-11-15
|
25
|
+
|
26
|
+
* irb require uses absolute path (for users without rubygems required in their .irbrc)
|
27
|
+
|
28
|
+
=== 0.9.1 / 2009-11-15
|
29
|
+
|
30
|
+
* added showing name of loaded rack env
|
31
|
+
|
32
|
+
=== 0.9 / 2009-11-15
|
33
|
+
|
34
|
+
* initial release
|
data/README.markdown
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# racksh
|
2
|
+
|
3
|
+
## About
|
4
|
+
|
5
|
+
**racksh** (Rack::Shell) is a console for Rack based ruby web applications.
|
6
|
+
|
7
|
+
It's like _script/console_ in Rails or _merb -i_ in Merb, but for any app built on Rack. You can use it to load application
|
8
|
+
environment for Rails, Merb, Sinatra, Camping, Ramaze or your own framework provided there is _config.ru_ file in app's root
|
9
|
+
directory.
|
10
|
+
|
11
|
+
It's purpose is to allow developer to introspect his application and/or make some initial setup. You can for example run
|
12
|
+
_DataMapper.auto_migrate!_ or make a request to _/users/666_ and check response details. It's mainly aimed at apps that don't
|
13
|
+
have console-like component (ie. app built with Sinatra) but all frameworks can benefit from interactive Rack stack and request
|
14
|
+
introspection.
|
15
|
+
|
16
|
+
## How it works?
|
17
|
+
|
18
|
+
It loads whole application environment like Rack web server, but instead of running the app it starts _irb_ session.
|
19
|
+
Additionally it exposes _$rack_ variable which allows you to make simulated HTTP requests to your app.
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
gem install spinels-racksh
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Starting racksh
|
28
|
+
|
29
|
+
To start racksh session run following inside rack application directory (containing config.ru file):
|
30
|
+
|
31
|
+
% racksh
|
32
|
+
Rack::Shell v0.9.9 started in development environment.
|
33
|
+
>>
|
34
|
+
|
35
|
+
Specifying location of config.ru:
|
36
|
+
|
37
|
+
% CONFIG_RU=~/projects/foobar/config.ru racksh
|
38
|
+
|
39
|
+
Executing ruby code inside application environment and printing results:
|
40
|
+
|
41
|
+
% racksh Order.all
|
42
|
+
% racksh "Order.first :created_at => Date.today"
|
43
|
+
|
44
|
+
Specifying Rack environment (default is development):
|
45
|
+
|
46
|
+
% RACK_ENV=production racksh
|
47
|
+
Rack::Shell v0.9.9 started in production environment.
|
48
|
+
>>
|
49
|
+
|
50
|
+
### Making simulated HTTP requests to your app
|
51
|
+
|
52
|
+
% racksh
|
53
|
+
Rack::Shell v0.9.9 started in development environment.
|
54
|
+
>> $rack.get "/"
|
55
|
+
=> #<Rack::MockResponse:0xb68fa7bc @body="<html>...", @headers={"Content-Type"=>"text/html", "Content-Length"=>"1812"}, @status=200, ...
|
56
|
+
|
57
|
+
_$rack_ variable contains following methods (thanks to [rack-test](http://github.com/rack/rack-test) gem):
|
58
|
+
|
59
|
+
# make GET request
|
60
|
+
$rack.get uri, params, env
|
61
|
+
|
62
|
+
# make POST request
|
63
|
+
$rack.post uri, params, env
|
64
|
+
|
65
|
+
# make PUT request
|
66
|
+
$rack.put uri, params, env
|
67
|
+
|
68
|
+
# make DELETE request
|
69
|
+
$rack.delete uri, params, env
|
70
|
+
|
71
|
+
# make HEAD request
|
72
|
+
$rack.head uri, params, env
|
73
|
+
|
74
|
+
# make custom request
|
75
|
+
$rack.request uri, params, env
|
76
|
+
|
77
|
+
# set HTTP header
|
78
|
+
$rack.header name, value
|
79
|
+
|
80
|
+
# set credentials for Basic Authorization
|
81
|
+
$rack.basic_authorize username, password
|
82
|
+
|
83
|
+
# set credentials for Digest Authorization
|
84
|
+
$rack.digest_authorize username, password
|
85
|
+
|
86
|
+
# follow redirect from previous request
|
87
|
+
$rack.follow_redirect!
|
88
|
+
|
89
|
+
# last request object
|
90
|
+
$rack.last_request
|
91
|
+
|
92
|
+
# last response object
|
93
|
+
$rack.last_response
|
94
|
+
|
95
|
+
# access your Rack app
|
96
|
+
$rack.app
|
97
|
+
|
98
|
+
# name of environment
|
99
|
+
$rack.env
|
100
|
+
|
101
|
+
Check [test.rb from brynary's rack-test](http://github.com/brynary/rack-test/blob/master/lib/rack/test.rb) for implementation of
|
102
|
+
above methods.
|
103
|
+
|
104
|
+
Examples:
|
105
|
+
|
106
|
+
$rack.get "/", {}, { 'REMOTE_ADDR' => '123.45.67.89' }
|
107
|
+
$rack.header "User-Agent", "Firefox"
|
108
|
+
$rack.post "/users", :user => { :name => "Jola", :email => "jola@misi.ak" }
|
109
|
+
|
110
|
+
### Configuration files
|
111
|
+
|
112
|
+
Rack::Shell supports configuration file _.rackshrc_ which is loaded from two places during startup: user's home dir and
|
113
|
+
application directory (in this order). You can put any ruby code in it, but it's purpose is to setup your session, ie. setting
|
114
|
+
headers which will be used for all $rack.get/post/... requests.
|
115
|
+
|
116
|
+
For example to set user agent to Firefox and re-migrate db if loaded environment is _test_ put following in _.rackshrc_:
|
117
|
+
|
118
|
+
$rack.header "User-Agent", "Firefox"
|
119
|
+
DataMapper.auto_migrate! if $rack.env == "test"
|
120
|
+
|
121
|
+
You can also make requests:
|
122
|
+
|
123
|
+
$rack.put "/signin", :login => "jola", :password => "misiacz"
|
124
|
+
|
125
|
+
This will ensure you are always logged in when you start _racksh_.
|
126
|
+
|
127
|
+
### Reloading
|
128
|
+
|
129
|
+
If you've made some changes to your app and you want to reload it type:
|
130
|
+
|
131
|
+
reload!
|
132
|
+
|
133
|
+
It will reload (actually restart) whole Rack application in new process.
|
134
|
+
|
135
|
+
### Loading racksh into existing irb session
|
136
|
+
|
137
|
+
If you already opened irb and you want racksh functionality just run following:
|
138
|
+
|
139
|
+
require 'racksh/irb'
|
140
|
+
|
141
|
+
It will initialize racksh and load rack app. From now on you can use _$rack_.
|
142
|
+
|
143
|
+
## Authors
|
144
|
+
|
145
|
+
* Marcin Kulik - [ku1ik.com](http://ku1ik.com/)
|
146
|
+
|
data/bin/racksh
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "racksh", "init.rb"))
|
4
|
+
|
5
|
+
# prevent STDOUT & STDERR to be reopened (apps do this to be able to log under Passenger)
|
6
|
+
def STDOUT.reopen(*args); end
|
7
|
+
def STDERR.reopen(*args); end
|
8
|
+
|
9
|
+
if ARGV.empty?
|
10
|
+
begin
|
11
|
+
require "pry"
|
12
|
+
Interpreter = Pry
|
13
|
+
rescue LoadError
|
14
|
+
require "irb"
|
15
|
+
require "irb/completion"
|
16
|
+
Interpreter = IRB
|
17
|
+
end
|
18
|
+
|
19
|
+
Rack::Shell.init
|
20
|
+
ARGV.concat(['--prompt', 'simple']) unless ARGV.include?('--prompt')
|
21
|
+
Interpreter.start
|
22
|
+
else
|
23
|
+
Rack::Shell.init
|
24
|
+
p eval(ARGV.join(" "))
|
25
|
+
end
|
data/lib/racksh/init.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
ENV['RACK_ENV'] ||= 'development'
|
4
|
+
ENV['CONFIG_RU'] ||= 'config.ru'
|
5
|
+
|
6
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
7
|
+
%w(session version init).each { |f| require File.join(dir, f) }
|
8
|
+
|
9
|
+
def reload!
|
10
|
+
puts "Rack::Shell reloading..."
|
11
|
+
ENV['RACKSH_SKIP_INTRO'] = "1"
|
12
|
+
exec $0
|
13
|
+
end
|
14
|
+
|
15
|
+
module Rack
|
16
|
+
module Shell
|
17
|
+
File = ::File
|
18
|
+
|
19
|
+
def self.init
|
20
|
+
config_ru = ENV['CONFIG_RU']
|
21
|
+
|
22
|
+
# build Rack app
|
23
|
+
rack_app = Array(Rack::Builder.parse_file(config_ru)).first
|
24
|
+
$rack = Rack::Shell::Session.new(rack_app)
|
25
|
+
|
26
|
+
# run ~/.rackshrc
|
27
|
+
rcfile = File.expand_path("~/.rackshrc")
|
28
|
+
eval(File.read(rcfile)) if File.exist?(rcfile)
|
29
|
+
|
30
|
+
# run local .rackshrc (from app dir)
|
31
|
+
rcfile = File.expand_path(File.join(File.dirname(config_ru), ".rackshrc"))
|
32
|
+
eval(File.read(rcfile)) if File.exist?(rcfile)
|
33
|
+
|
34
|
+
# print startup info
|
35
|
+
unless ENV['RACKSH_SKIP_INTRO']
|
36
|
+
if STDOUT.tty? && ENV['TERM'] != 'dumb' # we have color terminal, let's pimp our info!
|
37
|
+
env_color = ($rack.env == 'production' ? "\e[31m\e[1m" : "\e[36m\e[1m")
|
38
|
+
puts "\e[32m\e[1mRack\e[0m\e[33m\e[1m::\e[0m\e[32m\e[1mShell\e[0m v#{VERSION} started in #{env_color}#{$rack.env}\e[0m environment."
|
39
|
+
else
|
40
|
+
puts "Rack::Shell v#{VERSION} started in #{$rack.env} environment."
|
41
|
+
end
|
42
|
+
@reloaded = true
|
43
|
+
end
|
44
|
+
rescue Errno::ENOENT => e
|
45
|
+
if e.message =~ /config\.ru$/
|
46
|
+
puts "Rack::Shell couldn't find #{config_ru}"
|
47
|
+
exit(1)
|
48
|
+
else
|
49
|
+
raise e
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/racksh/irb.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spinels-racksh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcin Kulik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
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.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.5'
|
41
|
+
description:
|
42
|
+
email: marcin.kulik@gmail.com
|
43
|
+
executables:
|
44
|
+
- racksh
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.txt
|
49
|
+
- README.markdown
|
50
|
+
- bin/racksh
|
51
|
+
- lib/racksh/init.rb
|
52
|
+
- lib/racksh/irb.rb
|
53
|
+
- lib/racksh/session.rb
|
54
|
+
- lib/racksh/version.rb
|
55
|
+
homepage: http://github.com/spinels/racksh
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.4.7
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Console for any Rack based ruby web app
|
78
|
+
test_files: []
|