under_rack 0.0.1
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/Gemfile +4 -0
- data/README.rdoc +34 -0
- data/Rakefile +1 -0
- data/lib/under_rack.rb +2 -0
- data/lib/under_rack/framework.rb +70 -0
- data/lib/under_rack/version.rb +3 -0
- data/spec/app_spec.rb +57 -0
- data/spec/spec_helper.rb +7 -0
- data/under_rack.gemspec +23 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
== UnderRack
|
2
|
+
|
3
|
+
A simple Ruby Framework for you understand Rack(Ruby Webserver Interface)
|
4
|
+
|
5
|
+
== Example
|
6
|
+
|
7
|
+
* gem install under_rack
|
8
|
+
* create a new file called app.ru with:
|
9
|
+
|
10
|
+
require "rubygems"
|
11
|
+
require "under_rack"
|
12
|
+
|
13
|
+
get "/hello" do
|
14
|
+
@name = "Mary"
|
15
|
+
erb :hello
|
16
|
+
end
|
17
|
+
|
18
|
+
post "/create" do
|
19
|
+
"Created"
|
20
|
+
end
|
21
|
+
|
22
|
+
app_root = get "/" do
|
23
|
+
"Home"
|
24
|
+
end
|
25
|
+
|
26
|
+
run app_root
|
27
|
+
|
28
|
+
* Create a new file called hello.erb with:
|
29
|
+
|
30
|
+
<p>Hello <%= @name %></p>
|
31
|
+
|
32
|
+
* Run the application with: rackup app.ru
|
33
|
+
|
34
|
+
* Go to http://localhost:9292/hello
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/under_rack.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
def general_request_method(request_method, path, &block)
|
2
|
+
|
3
|
+
def erb(view_name)
|
4
|
+
view = File.read("#{view_name.to_s}.erb")
|
5
|
+
body = ERB.new(view)
|
6
|
+
body.result(binding)
|
7
|
+
end
|
8
|
+
|
9
|
+
middleware = Class.new
|
10
|
+
middleware.send(:define_method, 'initialize') do |app|
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
middleware.send(:define_method, 'call') do |env|
|
15
|
+
request = Rack::Request.new(env)
|
16
|
+
response = Rack::Response.new
|
17
|
+
|
18
|
+
if request.request_method == self.class.request_method && request.path_info == self.class.path
|
19
|
+
response.write(action)
|
20
|
+
response.finish
|
21
|
+
else
|
22
|
+
if @app.respond_to? :call
|
23
|
+
@app.call(env)
|
24
|
+
else
|
25
|
+
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
middleware.instance_eval do
|
31
|
+
def path=(path)
|
32
|
+
@path = path
|
33
|
+
end
|
34
|
+
|
35
|
+
def path
|
36
|
+
@path
|
37
|
+
end
|
38
|
+
|
39
|
+
def request_method=(rm)
|
40
|
+
@rm = rm
|
41
|
+
end
|
42
|
+
|
43
|
+
def request_method
|
44
|
+
@rm
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
middleware.send(:define_method, 'action', &block)
|
49
|
+
middleware.path = path
|
50
|
+
middleware.request_method = request_method
|
51
|
+
|
52
|
+
use middleware
|
53
|
+
middleware
|
54
|
+
end
|
55
|
+
|
56
|
+
def get(path, &block)
|
57
|
+
general_request_method("GET", path, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def post(path, &block)
|
61
|
+
general_request_method("POST", path, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
def put(path, &block)
|
65
|
+
general_request_method("PUT", path, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete(path, &block)
|
69
|
+
general_request_method("DELETE", path, &block)
|
70
|
+
end
|
data/spec/app_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe "UnderRack" do
|
4
|
+
let(:app) do
|
5
|
+
Rack::Builder.new do
|
6
|
+
get "/hello" do
|
7
|
+
"GET hello"
|
8
|
+
end
|
9
|
+
|
10
|
+
post "/hello" do
|
11
|
+
"POST hello"
|
12
|
+
end
|
13
|
+
|
14
|
+
put "/hello" do
|
15
|
+
"PUT hello"
|
16
|
+
end
|
17
|
+
|
18
|
+
delete "/hello" do
|
19
|
+
"DELETE hello"
|
20
|
+
end
|
21
|
+
|
22
|
+
root_app = get "/" do
|
23
|
+
"GET root"
|
24
|
+
end
|
25
|
+
|
26
|
+
run root_app
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
@mock = Rack::MockRequest.new(app)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "GET /hello" do
|
35
|
+
it "returns a response body with 'GET hello'" do
|
36
|
+
@mock.get("/hello").body.should eql "GET hello"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "POST /hello" do
|
41
|
+
it "returns a response body with 'POST hello'" do
|
42
|
+
@mock.post("/hello").body.should eql "POST hello"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "PUT /hello" do
|
47
|
+
it "returns a response body with 'PUT hello'" do
|
48
|
+
@mock.put("/hello").body.should eql "PUT hello"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "DELETE /hello" do
|
53
|
+
it "returns a response body with 'DELETE hello'" do
|
54
|
+
@mock.delete("/hello").body.should eql "DELETE hello"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/under_rack.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "under_rack/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "under_rack"
|
7
|
+
s.version = UnderRack::VERSION
|
8
|
+
s.authors = ["Rinaldi Fonseca"]
|
9
|
+
s.email = ["rinaldifonseca@gmail.com"]
|
10
|
+
s.homepage = "http://www.github.com/rinaldifonseca/under_rack"
|
11
|
+
s.summary = %q{UnderRack is a Ruby Framework for you understand Rack}
|
12
|
+
s.description = %q{UnderRack is a Ruby Framework for you understand Rack}
|
13
|
+
|
14
|
+
s.rubyforge_project = "under_rack"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_runtime_dependency "rack", "1.4.1"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: under_rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rinaldi Fonseca
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70139265814880 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70139265814880
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack
|
27
|
+
requirement: &70139265814380 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.4.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70139265814380
|
36
|
+
description: UnderRack is a Ruby Framework for you understand Rack
|
37
|
+
email:
|
38
|
+
- rinaldifonseca@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- lib/under_rack.rb
|
48
|
+
- lib/under_rack/framework.rb
|
49
|
+
- lib/under_rack/version.rb
|
50
|
+
- spec/app_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- under_rack.gemspec
|
53
|
+
homepage: http://www.github.com/rinaldifonseca/under_rack
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project: under_rack
|
73
|
+
rubygems_version: 1.8.15
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: UnderRack is a Ruby Framework for you understand Rack
|
77
|
+
test_files:
|
78
|
+
- spec/app_spec.rb
|
79
|
+
- spec/spec_helper.rb
|