wbzyl-rack-math 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/README.markdown +120 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/examples/app1.rb +23 -0
- data/examples/app2.rb +12 -0
- data/examples/app2.ru +2 -0
- data/examples/euler.ru +2 -0
- data/examples/phi.ru +2 -0
- data/examples/pi.ru +2 -0
- data/examples/sqrt2.ru +2 -0
- data/lib/rack-math.rb +4 -0
- data/lib/rack-math/euler.rb +19 -0
- data/lib/rack-math/phi.rb +19 -0
- data/lib/rack-math/pi.rb +19 -0
- data/lib/rack-math/slowdown.rb +13 -0
- data/lib/rack-math/sqrt2.rb +19 -0
- data/lib/rack-math/where.rb +13 -0
- data/rack-math.gemspec +68 -0
- metadata +91 -0
data/.gitignore
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# Rack Math Menagerie
|
2
|
+
|
3
|
+
This gem contains four simple Rack applications:
|
4
|
+
|
5
|
+
* Rack::Pi
|
6
|
+
* Rack::Euler
|
7
|
+
* Rack::Sqrt2
|
8
|
+
* Rack::Phi
|
9
|
+
|
10
|
+
These applications can be used to play with:
|
11
|
+
|
12
|
+
* construct iteratively Rack applications,
|
13
|
+
* experiment with new and existing Rack Middleware,
|
14
|
+
* embed one Rack application into another
|
15
|
+
Rack application.
|
16
|
+
|
17
|
+
Build an install the gem with:
|
18
|
+
|
19
|
+
rake install
|
20
|
+
|
21
|
+
## Examples
|
22
|
+
|
23
|
+
The directory `examples` contains several ready to run applications.
|
24
|
+
For example, run the *pi.ru* file with:
|
25
|
+
|
26
|
+
rackup pi.ru -p 3000
|
27
|
+
|
28
|
+
And see the result at:
|
29
|
+
|
30
|
+
http://localhost:3000
|
31
|
+
|
32
|
+
To get more digits input:
|
33
|
+
|
34
|
+
http://localhost:3000/?prec=256
|
35
|
+
|
36
|
+
Have a fun!
|
37
|
+
|
38
|
+
|
39
|
+
### Playing with Rack::Builder\#map
|
40
|
+
|
41
|
+
`Rack::Builder#map` mounts a stack of rack application/middlewares the
|
42
|
+
specified path or URI and all the children paths under it.
|
43
|
+
|
44
|
+
# app1.rb
|
45
|
+
require 'rack-math'
|
46
|
+
App1 = Rack::Builder.new do
|
47
|
+
use Rack::ShowExceptions
|
48
|
+
use Rack::Lint
|
49
|
+
use Rack::CommonLogger
|
50
|
+
|
51
|
+
map '/euler' do
|
52
|
+
run Rack::Euler.new
|
53
|
+
end
|
54
|
+
|
55
|
+
map '/pi' do
|
56
|
+
run Rack::Pi.new
|
57
|
+
end
|
58
|
+
|
59
|
+
map '/phi' do
|
60
|
+
run Rack::Phi.new
|
61
|
+
end
|
62
|
+
|
63
|
+
map '/sqrt2' do
|
64
|
+
run Rack::Sqrt2.new
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
In *app1.rb* we mount `Rack::Euler` under '/euler',
|
69
|
+
`Rack::Pi` under '/pi' etc. Run *app1.rb* with:
|
70
|
+
|
71
|
+
rackup app1.rb -p 3000
|
72
|
+
|
73
|
+
and watch the results at:
|
74
|
+
|
75
|
+
http://localhost:3000/euler
|
76
|
+
http://localhost:3000/pi?prec=1024
|
77
|
+
etc.
|
78
|
+
|
79
|
+
In the *app2.rb* we mount `App1` under '/math'
|
80
|
+
and *rack/lobster.rb* under '/lobster':
|
81
|
+
|
82
|
+
# app2.rb
|
83
|
+
require 'rack/lobster' # distributed with the rack gem
|
84
|
+
require 'app1'
|
85
|
+
|
86
|
+
App2 = Rack::Builder.new do
|
87
|
+
map '/math' do
|
88
|
+
run App1
|
89
|
+
end
|
90
|
+
|
91
|
+
map '/lobster' do
|
92
|
+
run Rack::Lobster.new
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
Run *app2.rb* with:
|
97
|
+
|
98
|
+
rackup app2.rb -p 3000
|
99
|
+
|
100
|
+
and watch the results at:
|
101
|
+
|
102
|
+
http://localhost:3000/math/euler
|
103
|
+
http://localhost:3000/math/pi?prec=1024
|
104
|
+
http://localhost:3000/lobster
|
105
|
+
|
106
|
+
Alternatively, use this rackup file:
|
107
|
+
|
108
|
+
# app2.ru
|
109
|
+
require 'app2'
|
110
|
+
run App2
|
111
|
+
|
112
|
+
and run it with:
|
113
|
+
|
114
|
+
rackup app2.ru -s thin -p 3000
|
115
|
+
|
116
|
+
or
|
117
|
+
|
118
|
+
thin --rackup app2.ru -p 3000
|
119
|
+
|
120
|
+
Note, the use of the *thin* server above.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '/lib')
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require "rake/clean"
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
|
11
|
+
gem.name = "rack-math"
|
12
|
+
gem.summary = "Several modular Rack apps to play with and iteratively construct new Rack apps."
|
13
|
+
gem.email = "matwb@univ.gda.pl"
|
14
|
+
gem.homepage = "http://github.com/wbzyl/rack-math"
|
15
|
+
gem.authors = ["Wlodek Bzyl"]
|
16
|
+
gem.description = <<-EOF
|
17
|
+
This gem contains four modular Rack applications:
|
18
|
+
Pi, Euler, Sqrt2, Phi (golden ratio).
|
19
|
+
|
20
|
+
These applications can be used to play with:
|
21
|
+
* experiment with new and existing Rack Middleware
|
22
|
+
* combine modular Sinatra app with Rack::Builder
|
23
|
+
* embed one Rack application into another Rack application
|
24
|
+
EOF
|
25
|
+
|
26
|
+
gem.add_runtime_dependency 'rack', '>=1.0.0'
|
27
|
+
|
28
|
+
gem.add_development_dependency 'rack-test', '>=0.3.0'
|
29
|
+
|
30
|
+
# gem is a Gem::Specification
|
31
|
+
# refer to http://www.rubygems.org/read/chapter/20 for additional settings
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
puts "Jeweler not available."
|
35
|
+
puts "Install it with:"
|
36
|
+
puts " sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
37
|
+
end
|
38
|
+
|
39
|
+
Rake::TestTask.new(:test) do |t|
|
40
|
+
t.libs << 'lib' << 'test'
|
41
|
+
t.pattern = 'test/**/*_test.rb'
|
42
|
+
t.verbose = false
|
43
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
data/examples/app1.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rack-math'
|
2
|
+
|
3
|
+
App1 = Rack::Builder.new do
|
4
|
+
#use Rack::ShowExceptions
|
5
|
+
use Rack::CommonLogger
|
6
|
+
#use Rack::Lint
|
7
|
+
|
8
|
+
map '/euler' do
|
9
|
+
run Rack::Euler.new
|
10
|
+
end
|
11
|
+
|
12
|
+
map '/pi' do
|
13
|
+
run Rack::Pi.new
|
14
|
+
end
|
15
|
+
|
16
|
+
map '/phi' do
|
17
|
+
run Rack::Phi.new
|
18
|
+
end
|
19
|
+
|
20
|
+
map '/sqrt2' do
|
21
|
+
run Rack::Sqrt2.new
|
22
|
+
end
|
23
|
+
end
|
data/examples/app2.rb
ADDED
data/examples/app2.ru
ADDED
data/examples/euler.ru
ADDED
data/examples/phi.ru
ADDED
data/examples/pi.ru
ADDED
data/examples/sqrt2.ru
ADDED
data/lib/rack-math.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'rack/response'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'bigdecimal/math'
|
5
|
+
include BigMath
|
6
|
+
module Rack
|
7
|
+
class Euler
|
8
|
+
def call(env)
|
9
|
+
req = Request.new(env)
|
10
|
+
prec = req.GET["prec"].to_i
|
11
|
+
res = Response.new
|
12
|
+
res.write "<title>E</title>"
|
13
|
+
res.write "<p>"
|
14
|
+
res.write E(prec + 1).to_s("10F")
|
15
|
+
res.write "</p>"
|
16
|
+
res.finish
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'rack/response'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'bigdecimal/math'
|
5
|
+
include BigMath
|
6
|
+
module Rack
|
7
|
+
class Phi
|
8
|
+
def call(env)
|
9
|
+
req = Request.new(env)
|
10
|
+
prec = req.GET["prec"].to_i
|
11
|
+
res = Response.new
|
12
|
+
res.write "<title>PI</title>"
|
13
|
+
res.write "<p>"
|
14
|
+
res.write(((BigDecimal('5').sqrt(prec + 1) + 1) / 2).to_s("10F"))
|
15
|
+
res.write "</p>"
|
16
|
+
res.finish
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rack-math/pi.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'rack/response'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'bigdecimal/math'
|
5
|
+
include BigMath
|
6
|
+
module Rack
|
7
|
+
class Pi
|
8
|
+
def call(env)
|
9
|
+
req = Request.new(env)
|
10
|
+
prec = req.GET["prec"].to_i
|
11
|
+
res = Response.new
|
12
|
+
res.write "<title>PI</title>"
|
13
|
+
res.write "<p>"
|
14
|
+
res.write PI(prec + 1).to_s("10F")
|
15
|
+
res.write "</p>"
|
16
|
+
res.finish
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
require 'rack/response'
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'bigdecimal/math'
|
5
|
+
include BigMath
|
6
|
+
module Rack
|
7
|
+
class Sqrt2
|
8
|
+
def call(env)
|
9
|
+
req = Request.new(env)
|
10
|
+
prec = req.GET["prec"].to_i
|
11
|
+
res = Response.new
|
12
|
+
res.write "<title>Sqrt2</title>"
|
13
|
+
res.write "<p>"
|
14
|
+
res.write BigDecimal('2').sqrt(prec + 1).to_s("10F")
|
15
|
+
res.write "</p>"
|
16
|
+
res.finish
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/rack-math.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{rack-math}
|
5
|
+
s.version = "0.0.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Wlodek Bzyl"]
|
9
|
+
s.date = %q{2009-05-25}
|
10
|
+
s.description = %q{This gem contains four modular Rack applications:
|
11
|
+
Pi, Euler, Sqrt2, Phi (golden ratio).
|
12
|
+
|
13
|
+
These applications can be used to play with:
|
14
|
+
* experiment with new and existing Rack Middleware
|
15
|
+
* combine modular Sinatra app with Rack::Builder
|
16
|
+
* embed one Rack application into another Rack application
|
17
|
+
}
|
18
|
+
s.email = %q{matwb@univ.gda.pl}
|
19
|
+
s.extra_rdoc_files = [
|
20
|
+
"README.markdown"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".gitignore",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"examples/app1.rb",
|
28
|
+
"examples/app2.rb",
|
29
|
+
"examples/app2.ru",
|
30
|
+
"examples/euler.ru",
|
31
|
+
"examples/phi.ru",
|
32
|
+
"examples/pi.ru",
|
33
|
+
"examples/sqrt2.ru",
|
34
|
+
"lib/rack-math.rb",
|
35
|
+
"lib/rack-math/euler.rb",
|
36
|
+
"lib/rack-math/phi.rb",
|
37
|
+
"lib/rack-math/pi.rb",
|
38
|
+
"lib/rack-math/slowdown.rb",
|
39
|
+
"lib/rack-math/sqrt2.rb",
|
40
|
+
"lib/rack-math/where.rb",
|
41
|
+
"rack-math.gemspec"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/wbzyl/rack-math}
|
44
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.3.3}
|
47
|
+
s.summary = %q{Several modular Rack apps to play with and iteratively construct new Rack apps.}
|
48
|
+
s.test_files = [
|
49
|
+
"examples/app2.rb",
|
50
|
+
"examples/app1.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
|
59
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.3.0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
62
|
+
s.add_dependency(%q<rack-test>, [">= 0.3.0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
66
|
+
s.add_dependency(%q<rack-test>, [">= 0.3.0"])
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wbzyl-rack-math
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wlodek Bzyl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
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.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack-test
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
version:
|
35
|
+
description: "This gem contains four modular Rack applications: Pi, Euler, Sqrt2, Phi (golden ratio). These applications can be used to play with: * experiment with new and existing Rack Middleware * combine modular Sinatra app with Rack::Builder * embed one Rack application into another Rack application"
|
36
|
+
email: matwb@univ.gda.pl
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.markdown
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- README.markdown
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- examples/app1.rb
|
49
|
+
- examples/app2.rb
|
50
|
+
- examples/app2.ru
|
51
|
+
- examples/euler.ru
|
52
|
+
- examples/phi.ru
|
53
|
+
- examples/pi.ru
|
54
|
+
- examples/sqrt2.ru
|
55
|
+
- lib/rack-math.rb
|
56
|
+
- lib/rack-math/euler.rb
|
57
|
+
- lib/rack-math/phi.rb
|
58
|
+
- lib/rack-math/pi.rb
|
59
|
+
- lib/rack-math/slowdown.rb
|
60
|
+
- lib/rack-math/sqrt2.rb
|
61
|
+
- lib/rack-math/where.rb
|
62
|
+
- rack-math.gemspec
|
63
|
+
has_rdoc: false
|
64
|
+
homepage: http://github.com/wbzyl/rack-math
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --charset=UTF-8
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.2.0
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Several modular Rack apps to play with and iteratively construct new Rack apps.
|
89
|
+
test_files:
|
90
|
+
- examples/app2.rb
|
91
|
+
- examples/app1.rb
|