Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wbzyl-rack-math

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wbzyl-rack-math

  • 0.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Rack Math Menagerie

This gem contains four simple Rack applications:

  • Rack::Pi
  • Rack::Euler
  • Rack::Sqrt2
  • Rack::Phi

These applications can be used to play with:

  • construct iteratively Rack applications,
  • experiment with new and existing Rack Middleware,
  • embed one Rack application into another Rack application.

Build an install the gem with:

rake install

Examples

The directory examples contains several ready to run applications. For example, run the pi.ru file with:

rackup pi.ru -p 3000

And see the result at:

http://localhost:3000

To get more digits input:

http://localhost:3000/?prec=256

Have a fun!

Playing with Rack::Builder#map

Rack::Builder#map mounts a stack of rack application/middlewares the specified path or URI and all the children paths under it.

# app1.rb
require 'rack-math'
App1 = Rack::Builder.new do
  use Rack::ShowExceptions
  use Rack::Lint
  use Rack::CommonLogger
  
  map '/euler' do
    run Rack::Euler.new
  end
  
  map '/pi' do
    run Rack::Pi.new
  end
  
  map '/phi' do
    run Rack::Phi.new
  end
  
  map '/sqrt2' do
    run Rack::Sqrt2.new
  end
end

In app1.rb we mount Rack::Euler under '/euler', Rack::Pi under '/pi' etc. Run app1.rb with:

rackup app1.rb -p 3000

and watch the results at:

http://localhost:3000/euler    
http://localhost:3000/pi?prec=1024
etc.

In the app2.rb we mount App1 under '/math' and rack/lobster.rb under '/lobster':

# app2.rb
require 'rack/lobster' # distributed with the rack gem
require 'app1'

App2 = Rack::Builder.new do
  map '/math' do
    run App1
  end
  
  map '/lobster' do
    run Rack::Lobster.new
  end
end

Run app2.rb with:

rackup app2.rb -p 3000

and watch the results at:

http://localhost:3000/math/euler
http://localhost:3000/math/pi?prec=1024
http://localhost:3000/lobster

Alternatively, use this rackup file:

# app2.ru
require 'app2'
run App2

and run it with:

rackup app2.ru -s thin -p 3000

or

thin --rackup app2.ru -p 3000

Note, the use of the thin server above.

FAQs

Package last updated on 10 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc