racksh 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +36 -9
- data/bin/racksh +3 -1
- data/lib/racksh/init.rb +41 -0
- data/lib/racksh/session.rb +18 -0
- data/lib/racksh/version.rb +5 -0
- data/lib/racksh.rb +4 -29
- metadata +5 -3
- data/VERSION +0 -1
data/README.markdown
CHANGED
@@ -9,8 +9,9 @@ environment for Rails, Merb, Sinatra, Camping, Ramaze or your own framework prov
|
|
9
9
|
directory.
|
10
10
|
|
11
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
|
13
|
-
have console-like component (ie. app built with Sinatra) but all frameworks can benefit from interactive Rack stack
|
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.
|
14
15
|
|
15
16
|
## How it works?
|
16
17
|
|
@@ -28,8 +29,8 @@ Additionally it exposes _$rack_ variable which allows you to make simulated HTTP
|
|
28
29
|
To start racksh session run following inside rack application directory (containing config.ru file):
|
29
30
|
|
30
31
|
% racksh
|
31
|
-
Rack::Shell v0.9.
|
32
|
-
|
32
|
+
Rack::Shell v0.9.4 started in development environment.
|
33
|
+
>>
|
33
34
|
|
34
35
|
Specifying location of config.ru:
|
35
36
|
|
@@ -43,14 +44,14 @@ Executing ruby code inside application environment and printing results:
|
|
43
44
|
Specifying Rack environment (default is development):
|
44
45
|
|
45
46
|
% RACK_ENV=production racksh
|
46
|
-
Rack::Shell v0.9.
|
47
|
-
|
47
|
+
Rack::Shell v0.9.4 started in production environment.
|
48
|
+
>>
|
48
49
|
|
49
|
-
### Making simulated HTTP requests to your app
|
50
|
+
### Making simulated HTTP requests to your app
|
50
51
|
|
51
52
|
% racksh
|
52
|
-
Rack::Shell v0.9.
|
53
|
-
|
53
|
+
Rack::Shell v0.9.4 started in development environment.
|
54
|
+
>> $rack.get "/"
|
54
55
|
=> #<Rack::MockResponse:0xb68fa7bc @body="<html>...", @headers={"Content-Type"=>"text/html", "Content-Length"=>"1812"}, @status=200, ...
|
55
56
|
|
56
57
|
_$rack_ variable contains following methods (thanks to [rack-test](http://github.com/brynary/rack-test) gem):
|
@@ -85,9 +86,18 @@ _$rack_ variable contains following methods (thanks to [rack-test](http://github
|
|
85
86
|
# follow redirect from previous request
|
86
87
|
$rack.follow_redirect!
|
87
88
|
|
89
|
+
# last request object
|
90
|
+
$rack.last_request
|
91
|
+
|
92
|
+
# last response object
|
93
|
+
$rack.last_response
|
94
|
+
|
88
95
|
# access your Rack app
|
89
96
|
$rack.app
|
90
97
|
|
98
|
+
# name of environment
|
99
|
+
$rack.env
|
100
|
+
|
91
101
|
Check [test.rb from brynary's rack-test](http://github.com/brynary/rack-test/blob/master/lib/rack/test.rb) for implementation of
|
92
102
|
above methods.
|
93
103
|
|
@@ -97,6 +107,23 @@ Examples:
|
|
97
107
|
$rack.header "User-Agent", "Firefox"
|
98
108
|
$rack.post "/users", :user => { :name => "Jola", :email => "jola@misi.ak" }
|
99
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
|
+
|
100
127
|
## Bugs & feature requests
|
101
128
|
|
102
129
|
Please report bugs and/or feature requests on the github issue tracker for the project located [here](http://github.com/sickill/racksh/issues).
|
data/bin/racksh
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
ENV['RACK_ENV'] ||= 'development'
|
4
|
+
|
3
5
|
if ARGV.empty?
|
4
6
|
racksh_path = File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "racksh.rb")
|
5
|
-
exec "irb -r #{racksh_path}"
|
7
|
+
exec "irb -r irb/completion -r #{racksh_path} --simple-prompt"
|
6
8
|
else
|
7
9
|
require 'racksh'
|
8
10
|
p eval(ARGV.join(" "))
|
data/lib/racksh/init.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module Shell
|
5
|
+
File = ::File
|
6
|
+
|
7
|
+
def self.start!
|
8
|
+
# prevent STDOUT & STDERR to be reopened (apps do this to be able to log under Passenger)
|
9
|
+
def STDOUT.reopen(*args); end
|
10
|
+
def STDERR.reopen(*args); end
|
11
|
+
|
12
|
+
# build Rack app
|
13
|
+
config_ru = ENV['CONFIG_RU'] || 'config.ru'
|
14
|
+
rack_app = Object.class_eval("Rack::Builder.new { #{File.read(config_ru)} }")
|
15
|
+
$rack = Rack::Shell::Session.new(rack_app)
|
16
|
+
|
17
|
+
# run ~/.rackshrc
|
18
|
+
rcfile = File.expand_path("~/.rackshrc")
|
19
|
+
eval(File.read(rcfile)) if File.exists?(rcfile)
|
20
|
+
|
21
|
+
# run local .rackshrc (from app dir)
|
22
|
+
rcfile = File.expand_path(File.join(File.dirname(config_ru), ".rackshrc"))
|
23
|
+
eval(File.read(rcfile)) if File.exists?(rcfile)
|
24
|
+
|
25
|
+
# print startup info
|
26
|
+
if STDOUT.tty? && ENV['TERM'] != 'dumb' # we have color terminal, let's pimp our info!
|
27
|
+
env_color = ($rack.env == 'production' ? "\e[31m\e[1m" : "\e[36m\e[1m")
|
28
|
+
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."
|
29
|
+
else
|
30
|
+
puts "Rack::Shell v#{VERSION} started in #{$rack.env} environment."
|
31
|
+
end
|
32
|
+
rescue Errno::ENOENT => e
|
33
|
+
if e.message =~ /config\.ru$/
|
34
|
+
puts "Rack::Shell couldn't find #{config_ru}"
|
35
|
+
exit(1)
|
36
|
+
else
|
37
|
+
raise e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/racksh.rb
CHANGED
@@ -1,30 +1,5 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
dir = File.join(File.expand_path(File.dirname(__FILE__)), 'racksh')
|
3
|
+
%w(session version init).each { |f| require File.join(dir, f) }
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
module Rack
|
8
|
-
class Shell
|
9
|
-
include Rack::Test::Methods
|
10
|
-
attr_reader :app
|
11
|
-
def initialize(app)
|
12
|
-
@app = app
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
begin
|
18
|
-
config_ru = ENV['CONFIG_RU'] || 'config.ru'
|
19
|
-
rack_application = eval("Rack::Builder.new { #{File.read(config_ru)} }")
|
20
|
-
$rack = Rack::Shell.new(rack_application)
|
21
|
-
version = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
|
22
|
-
puts "Rack::Shell v#{version} started in #{ENV['RACK_ENV']} environment."
|
23
|
-
rescue Errno::ENOENT => e
|
24
|
-
if e.message =~ /config\.ru$/
|
25
|
-
puts "Rack::Shell couldn't find #{config_ru}"
|
26
|
-
exit(1)
|
27
|
-
else
|
28
|
-
raise e
|
29
|
-
end
|
30
|
-
end
|
5
|
+
Rack::Shell.start!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: racksh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Kulik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-19 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +43,9 @@ extra_rdoc_files: []
|
|
43
43
|
files:
|
44
44
|
- bin/racksh
|
45
45
|
- lib/racksh.rb
|
46
|
-
-
|
46
|
+
- lib/racksh/init.rb
|
47
|
+
- lib/racksh/session.rb
|
48
|
+
- lib/racksh/version.rb
|
47
49
|
- README.markdown
|
48
50
|
has_rdoc: true
|
49
51
|
homepage: http://github.com/sickill/racksh
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.9.3
|