racksh 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +79 -24
- data/VERSION +1 -1
- data/lib/racksh.rb +17 -7
- metadata +23 -4
data/README.markdown
CHANGED
@@ -1,52 +1,107 @@
|
|
1
|
-
racksh
|
2
|
-
======
|
1
|
+
# racksh
|
3
2
|
|
4
|
-
About
|
5
|
-
-----
|
3
|
+
## About
|
6
4
|
|
7
5
|
**racksh** (Rack::Shell) is a console for Rack based ruby web applications.
|
8
6
|
|
9
|
-
It's like Rails' _script/console_ or Merb's _merb -i_, but for any app built on Rack. You can use it to load application
|
7
|
+
It's like Rails' _script/console_ or Merb's _merb -i_, 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
10
|
|
11
|
-
It's purpose is to allow developer to introspect his application and/or make some initial setup
|
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 introspection.
|
12
14
|
|
13
|
-
How it works?
|
14
|
-
-------------
|
15
|
+
## How it works?
|
15
16
|
|
16
|
-
It loads whole application environment like Rack web server, but
|
17
|
+
It loads whole application environment like Rack web server, but instead of running the app it starts _irb_ session.
|
18
|
+
Additionally it exposes _$rack_ variable which allows you to make simulated HTTP requests to your app.
|
17
19
|
|
18
|
-
Installation
|
19
|
-
------------
|
20
|
+
## Installation
|
20
21
|
|
21
22
|
gem install racksh -s http://gemcutter.org
|
22
23
|
|
23
|
-
Usage
|
24
|
-
-----
|
24
|
+
## Usage
|
25
25
|
|
26
|
-
|
26
|
+
### Starting racksh
|
27
27
|
|
28
|
-
|
28
|
+
To start racksh session run following inside rack application directory (containing config.ru file):
|
29
|
+
|
30
|
+
% racksh
|
31
|
+
Rack::Shell v0.9.3 started in development environment.
|
32
|
+
irb(main):001:0>
|
29
33
|
|
30
34
|
Specifying location of config.ru:
|
31
35
|
|
32
|
-
CONFIG_RU=~/projects/foobar/config.ru racksh
|
36
|
+
% CONFIG_RU=~/projects/foobar/config.ru racksh
|
33
37
|
|
34
38
|
Executing ruby code inside application environment and printing results:
|
35
39
|
|
36
|
-
racksh Order.all
|
37
|
-
racksh "Order.first :created_at => Date.today"
|
40
|
+
% racksh Order.all
|
41
|
+
% racksh "Order.first :created_at => Date.today"
|
38
42
|
|
39
43
|
Specifying Rack environment (default is development):
|
40
44
|
|
41
|
-
RACK_ENV=production racksh
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
% RACK_ENV=production racksh
|
46
|
+
Rack::Shell v0.9.3 started in production environment.
|
47
|
+
irb(main):001:0>
|
48
|
+
|
49
|
+
### Making simulated HTTP requests to your app:
|
50
|
+
|
51
|
+
% racksh
|
52
|
+
Rack::Shell v0.9.3 started in development environment.
|
53
|
+
irb(main):001:0> $rack.get "/"
|
54
|
+
=> #<Rack::MockResponse:0xb68fa7bc @body="<html>...", @headers={"Content-Type"=>"text/html", "Content-Length"=>"1812"}, @status=200, ...
|
55
|
+
|
56
|
+
_$rack_ variable contains following methods (thanks to [rack-test](http://github.com/brynary/rack-test) gem):
|
57
|
+
|
58
|
+
# make GET request
|
59
|
+
$rack.get uri, params, env
|
60
|
+
|
61
|
+
# make POST request
|
62
|
+
$rack.post uri, params, env
|
63
|
+
|
64
|
+
# make PUT request
|
65
|
+
$rack.put uri, params, env
|
66
|
+
|
67
|
+
# make DELETE request
|
68
|
+
$rack.delete uri, params, env
|
69
|
+
|
70
|
+
# make HEAD request
|
71
|
+
$rack.head uri, params, env
|
72
|
+
|
73
|
+
# make custom request
|
74
|
+
$rack.request uri, params, env
|
75
|
+
|
76
|
+
# set HTTP header
|
77
|
+
$rack.header name, value
|
78
|
+
|
79
|
+
# set credentials for Basic Authorization
|
80
|
+
$rack.basic_authorize username, password
|
81
|
+
|
82
|
+
# set credentials for Digest Authorization
|
83
|
+
$rack.digest_authorize username, password
|
84
|
+
|
85
|
+
# follow redirect from previous request
|
86
|
+
$rack.follow_redirect!
|
87
|
+
|
88
|
+
# access your Rack app
|
89
|
+
$rack.app
|
90
|
+
|
91
|
+
Check [test.rb from brynary's rack-test](http://github.com/brynary/rack-test/blob/master/lib/rack/test.rb) for implementation of
|
92
|
+
above methods.
|
93
|
+
|
94
|
+
Examples:
|
95
|
+
|
96
|
+
$rack.get "/", {}, { 'REMOTE_ADDR' => '123.45.67.89' }
|
97
|
+
$rack.header "User-Agent", "Firefox"
|
98
|
+
$rack.post "/users", :user => { :name => "Jola", :email => "jola@misi.ak" }
|
99
|
+
|
100
|
+
## Bugs & feature requests
|
45
101
|
|
46
102
|
Please report bugs and/or feature requests on the github issue tracker for the project located [here](http://github.com/sickill/racksh/issues).
|
47
103
|
|
48
|
-
Authors
|
49
|
-
-------
|
104
|
+
## Authors
|
50
105
|
|
51
106
|
* Marcin Kulik - [sickill.net](http://sickill.net/)
|
52
107
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.3
|
data/lib/racksh.rb
CHANGED
@@ -1,16 +1,26 @@
|
|
1
|
-
|
1
|
+
require "rubygems"
|
2
|
+
require "rack"
|
3
|
+
require "rack/test"
|
2
4
|
|
3
|
-
|
4
|
-
def run(*args, &blk); end
|
5
|
-
def map(*args, &blk); end
|
5
|
+
ENV['RACK_ENV'] ||= 'development'
|
6
6
|
|
7
|
-
|
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
|
8
16
|
|
9
17
|
begin
|
10
|
-
|
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)
|
11
21
|
version = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
|
12
22
|
puts "Rack::Shell v#{version} started in #{ENV['RACK_ENV']} environment."
|
13
|
-
rescue
|
23
|
+
rescue Errno::ENOENT => e
|
14
24
|
if e.message =~ /config\.ru$/
|
15
25
|
puts "Rack::Shell couldn't find #{config_ru}"
|
16
26
|
exit(1)
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Kulik
|
@@ -9,10 +9,29 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-17 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack-test
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0.5"
|
34
|
+
version:
|
16
35
|
description:
|
17
36
|
email: marcin.kulik@gmail.com
|
18
37
|
executables:
|