• Stars
    star
    424
  • Rank 102,329 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 15 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Console for Rack based ruby web apps

racksh

About

racksh (Rack::Shell) is a console for Rack based ruby web applications.

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 environment for Rails, Merb, Sinatra, Camping, Ramaze or your own framework provided there is config.ru file in app's root directory.

It's purpose is to allow developer to introspect his application and/or make some initial setup. You can for example run DataMapper.auto_migrate! or make a request to /users/666 and check response details. It's mainly aimed at apps that don't have console-like component (ie. app built with Sinatra) but all frameworks can benefit from interactive Rack stack and request introspection.

How it works?

It loads whole application environment like Rack web server, but instead of running the app it starts irb session. Additionally it exposes $rack variable which allows you to make simulated HTTP requests to your app.

Installation

gem install racksh

Usage

Starting racksh

To start racksh session run following inside rack application directory (containing config.ru file):

% racksh
Rack::Shell v0.9.9 started in development environment.
>>

Specifying location of config.ru:

% CONFIG_RU=~/projects/foobar/config.ru racksh

Executing ruby code inside application environment and printing results:

% racksh Order.all
% racksh "Order.first :created_at => Date.today"

Specifying Rack environment (default is development):

% RACK_ENV=production racksh
Rack::Shell v0.9.9 started in production environment.
>>

Making simulated HTTP requests to your app

% racksh
Rack::Shell v0.9.9 started in development environment.
>> $rack.get "/"
=> #<Rack::MockResponse:0xb68fa7bc @body="<html>...", @headers={"Content-Type"=>"text/html", "Content-Length"=>"1812"}, @status=200, ...

$rack variable contains following methods (thanks to rack-test gem):

# make GET request
$rack.get uri, params, env

# make POST request
$rack.post uri, params, env

# make PUT request
$rack.put uri, params, env

# make DELETE request
$rack.delete uri, params, env

# make HEAD request
$rack.head uri, params, env

# make custom request
$rack.request uri, params, env

# set HTTP header
$rack.header name, value

# set credentials for Basic Authorization
$rack.basic_authorize username, password

# set credentials for Digest Authorization
$rack.digest_authorize username, password

# follow redirect from previous request
$rack.follow_redirect!

# last request object
$rack.last_request

# last response object
$rack.last_response

# access your Rack app
$rack.app

# name of environment
$rack.env

Check test.rb from brynary's rack-test for implementation of above methods.

Examples:

$rack.get "/", {}, { 'REMOTE_ADDR' => '123.45.67.89' }
$rack.header "User-Agent", "Firefox"
$rack.post "/users", :user => { :name => "Jola", :email => "[email protected]" }

Configuration files

Rack::Shell supports configuration file .rackshrc which is loaded from two places during startup: user's home dir and application directory (in this order). You can put any ruby code in it, but it's purpose is to setup your session, ie. setting headers which will be used for all $rack.get/post/... requests.

For example to set user agent to Firefox and re-migrate db if loaded environment is test put following in .rackshrc:

$rack.header "User-Agent", "Firefox"
DataMapper.auto_migrate! if $rack.env == "test"

You can also make requests:

$rack.put "/signin", :login => "jola", :password => "misiacz"

This will ensure you are always logged in when you start racksh.

Reloading

If you've made some changes to your app and you want to reload it type:

reload!

It will reload (actually restart) whole Rack application in new process.

Loading racksh into existing irb session

If you already opened irb and you want racksh functionality just run following:

require 'racksh/irb'

It will initialize racksh and load rack app. From now on you can use $rack.

Bugs & feature requests

Please report bugs and/or feature requests on the github issue tracker for the project located here.

Authors

More Repositories

1

vim-monokai

Monokai color scheme for Vim converted from Textmate theme
Vim Script
1,434
star
2

bitpocket

"DIY Dropbox" or "2-way directory (r)sync with proper deletion"
Shell
1,029
star
3

stderred

stderr in red
C
990
star
4

git-dude

Git commit notifier
Shell
948
star
5

rainbow

Ruby gem for colorizing printed text on ANSI terminals
Ruby
810
star
6

vim-pasta

Pasting in Vim with indentation adjusted to destination context
Vim Script
321
star
7

coloration

Textmate to Vim, JEdit and Kate/KWrite color scheme converter
Ruby
260
star
8

css2less

Css to LessCss converter
Ruby
62
star
9

off-plugin

Plugin for Netbeans and JEdit for quick finding and opening files by typing just few characters
Java
44
star
10

vim-sunburst

Sunburst color scheme for Vim converted with coloration.ku1ik.com from Textmate theme with the same name.
Vim Script
28
star
11

dotfiles

My virtual home
Vim Script
27
star
12

rack-revision-info

Rack middleware showing current git (or svn) revision number of deployed application
Ruby
20
star
13

rack-lesscss

Rack middleware for serving LessCSS files compiled to CSS
Ruby
14
star
14

tm2jed

Texmate-To-JEdit colour theme converter - NOTE: DEVELOPMENT MOVED TO sickill/coloration repo
Ruby
9
star
15

kanbanery-ruby-client

Ruby client library and CLI for Kanbanery.com
Ruby
8
star
16

ps

Unix "ps" on the web.
Ruby
7
star
17

traytor

Show (animated) tray icon from command line
Python
7
star
18

example-rack-framework

Example ruby web framework built with Rack
Ruby
6
star
19

skype-kde-notifications

Displaying Skype incoming messages with KDE4 visual notifications
Python
6
star
20

homepage

Personal homepage / blog
CSS
5
star
21

coloration-web

Web frontend for Coloration
CSS
5
star
22

krug-merb-presentation

Ruby
4
star
23

rubytime-plasmoid

Rubytime plasmoid with support for adding activities and notifications
C
4
star
24

vim-git-inline-diff

Git inline diff for Vim using Vim's signs feature
Vim Script
4
star
25

vimbanery

Vim-like keybindings for Kanbanery
JavaScript
4
star
26

merb-resque-mailer

Merb plugin for putting mail delivery jobs onto Resque queue
Ruby
4
star
27

canvator

HTML5 Canvas element demo
C++
4
star
28

gratifier

Desktop notifications with Gravatars!
Shell
3
star
29

archlinux-nginx-passenger

Nginx webserver with Passenger module for Archlinux
Shell
3
star
30

blogator

My old homepage/blog created with Sinatra + Datamapper
JavaScript
3
star
31

krug-chef-presentation

JavaScript
3
star
32

sickounter

Simple Sinatra powered downloads counter
Ruby
3
star
33

euruko2010-building-frameworks-with-rack

My Euruko 2010 conference presentation about building ruby web frameworks using Rack and available middleware
JavaScript
3
star
34

yeb

Ruby
3
star
35

kodr

Programmer's editor for KDE4 written in Ruby
Shell
3
star
36

expo

Beautiful html photo album generator
Ruby
2
star
37

minion

Dead simple ruby background jobs without workers
Ruby
2
star
38

clj-bwt

Clojure implementation of Burrows-Wheeler transform (block-sorting compression)
Clojure
2
star
39

ts-hermit

JavaScript
2
star
40

openfilefast-headless

Tool to find a file in a project (dir) using fuzzy matching (this is backend only, to be used with gui frontend)
Ruby
2
star
41

ecto-preload-bug

Example project for demonstrating Ecto preload bug
Elixir
2
star
42

tsm

Ruby
2
star
43

tmux

C
2
star
44

mail_friday

Ruby
2
star
45

urack

rack + usher + warden + tilt + rack-flash + ...
Ruby
2
star
46

flash

Keep the secrets out of emails and chat history!
Elixir
2
star
47

luna

Fresh Rails app for "Setting up fresh Ubuntu server for Rails" LLP workshop
Ruby
2
star
48

omnomnom

sinatra+heroku test app
Ruby
2
star
49

finish-him

Word autocomplete (expansion) plugin for JEdit editor written in Scala
Scala
2
star
50

gts-move-on

Clojure
1
star
51

phoenix-1.3-to-dev

Elixir
1
star
52

bitflip-gen

Rust
1
star
53

bb-lb-400

1
star
54

tarpit

Tarpit for ssh/smtp/http
Rust
1
star
55

nemesis

1
star
56

chrome-browserid

JavaScript
1
star
57

gh-356

JavaScript
1
star
58

collatz-conjecture-rs

Collatz conjecture solver
Rust
1
star
59

brunch-issue

CSS
1
star