simple 0.0.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/Gemfile +13 -0
- data/Gemfile.lock +49 -0
- data/README.md +91 -0
- data/Rakefile +5 -0
- data/examples/benchmark.log +60 -0
- data/examples/helloworld.ru +31 -0
- data/lib/simple.rb +81 -0
- data/lib/simple/core_ext.rb +8 -0
- data/lib/simple/version.rb +3 -0
- data/pkg/simple-0.1.gem +0 -0
- data/simple.gemspec +17 -0
- data/spec/example_spec.rb +44 -0
- data/spec/spec_helper.rb +36 -0
- metadata +54 -70
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simple (0.1)
|
5
|
+
http_router
|
6
|
+
rack
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
crack (0.3.1)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
http_router (0.10.2)
|
14
|
+
rack (>= 1.0.0)
|
15
|
+
url_mount (~> 0.2.1)
|
16
|
+
mime-types (1.17.2)
|
17
|
+
parka (0.8.0)
|
18
|
+
crack (~> 0.3.0)
|
19
|
+
psych (~> 1.2.1)
|
20
|
+
rest-client (~> 1.6.7)
|
21
|
+
thor (~> 0.14.6)
|
22
|
+
psych (1.2.2)
|
23
|
+
rack (1.4.1)
|
24
|
+
rack-test (0.6.1)
|
25
|
+
rack (>= 1.0)
|
26
|
+
rake (0.9.2.2)
|
27
|
+
rest-client (1.6.7)
|
28
|
+
mime-types (>= 1.16)
|
29
|
+
rspec (2.8.0)
|
30
|
+
rspec-core (~> 2.8.0)
|
31
|
+
rspec-expectations (~> 2.8.0)
|
32
|
+
rspec-mocks (~> 2.8.0)
|
33
|
+
rspec-core (2.8.0)
|
34
|
+
rspec-expectations (2.8.0)
|
35
|
+
diff-lcs (~> 1.1.2)
|
36
|
+
rspec-mocks (2.8.0)
|
37
|
+
thor (0.14.6)
|
38
|
+
url_mount (0.2.1)
|
39
|
+
rack
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
parka
|
46
|
+
rack-test
|
47
|
+
rake
|
48
|
+
rspec
|
49
|
+
simple!
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Simple [![TravisCI][travis-img]][travis-ci] [![Dependency Status][gemnasium-img]][gemnasium]
|
2
|
+
|
3
|
+
[travis-img]: https://secure.travis-ci.org/bry4n/simple.png?branch=master
|
4
|
+
[travis-ci]: http://travis-ci.org/bry4n/simple
|
5
|
+
[gemnasium-img]: https://gemnasium.com/bry4n/simple.png?travis
|
6
|
+
[gemnasium]: https://gemnasium.com/bry4n/simple
|
7
|
+
|
8
|
+
_Simple web development framework for Ruby._
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
**_Notes: Simple is very new and still under development._** Feel free to create ticket and report about bug or improvement or addition.
|
13
|
+
|
14
|
+
|
15
|
+
put this line in your Gemfile
|
16
|
+
|
17
|
+
gem "simple"
|
18
|
+
|
19
|
+
or install with `gem` command line
|
20
|
+
|
21
|
+
gem install bundler
|
22
|
+
|
23
|
+
## Features
|
24
|
+
|
25
|
+
* Built on top of [Rack](https://github.com/rack/rack) and [http_router](https://github.com/joshbuddy/http_router)
|
26
|
+
* Insanely small ruby web framework - < 100 LC
|
27
|
+
* Blazingly fast [benchmark](https://github.com/bry4n/simple/blob/master/examples/benchmark.log)
|
28
|
+
* Inspired by [Sinatra](https://github.com/sinatra/sinatra)
|
29
|
+
* Works with [Thin](http://code.macournoyer.com/thin/), [Unicorn](http://unicorn.bogomips.org/), [Pow](http://pow.cx/), [Heroku](http://www.heroku.com/)
|
30
|
+
* Easy to write your own Ruby web application.
|
31
|
+
|
32
|
+
## Basic Usage
|
33
|
+
|
34
|
+
The little snippet of the famous hello world web application.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# config.ru
|
38
|
+
|
39
|
+
require 'simple'
|
40
|
+
|
41
|
+
class Example < Simple::Base
|
42
|
+
|
43
|
+
# GET /
|
44
|
+
get "/" do
|
45
|
+
[200, {"Content-Type" => "text/plain"}, ["Hello World"]]
|
46
|
+
end
|
47
|
+
|
48
|
+
# GET /hello
|
49
|
+
get "/:message" do
|
50
|
+
# params[:message]
|
51
|
+
end
|
52
|
+
|
53
|
+
# POST /users
|
54
|
+
post "/users" do
|
55
|
+
# User.create or etc
|
56
|
+
end
|
57
|
+
|
58
|
+
# GET /api/v1/users/online.xml
|
59
|
+
namespace :api do
|
60
|
+
namespace :v1 do
|
61
|
+
get "/users/online" do
|
62
|
+
# json/xml output
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
run Example
|
70
|
+
````
|
71
|
+
|
72
|
+
This would create a Rack application.
|
73
|
+
|
74
|
+
## TODO
|
75
|
+
|
76
|
+
* Before/After Filters
|
77
|
+
* Helpers (Form/Link/etc)
|
78
|
+
* Render Templates
|
79
|
+
* Rails style router (match "/hi" => "controller#action")
|
80
|
+
* And much more.
|
81
|
+
|
82
|
+
## Contribution
|
83
|
+
|
84
|
+
* Fork the project
|
85
|
+
* Make your feature addition or bug fix.
|
86
|
+
* Add test for it
|
87
|
+
* Send me a pull request. Topic branches preferred.
|
88
|
+
|
89
|
+
## Copyright
|
90
|
+
|
91
|
+
Copyright © 2012 Bryan Goines. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
2-1-2012 - Mac OSX 10.7.2 - 2.4 Ghz Intel Core 2 Duo - 8GB Ram (1067Mhz DRR3) - Ruby 1.9.3 p0 with performance patch (https://gist.github.com/1688857)
|
2
|
+
|
3
|
+
$ thin -R examples/helloworld.ru start
|
4
|
+
|
5
|
+
$ ab -kc 30 -t 10 http://0.0.0.0:3000/
|
6
|
+
|
7
|
+
---------------------------------------------------------------------------------
|
8
|
+
This is ApacheBench, Version 2.3 <$Revision: 1178079 $>
|
9
|
+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
|
10
|
+
Licensed to The Apache Software Foundation, http://www.apache.org/
|
11
|
+
|
12
|
+
Benchmarking 0.0.0.0 (be patient)
|
13
|
+
Completed 5000 requests
|
14
|
+
Completed 10000 requests
|
15
|
+
Completed 15000 requests
|
16
|
+
Completed 20000 requests
|
17
|
+
Completed 25000 requests
|
18
|
+
Completed 30000 requests
|
19
|
+
Completed 35000 requests
|
20
|
+
Finished 38698 requests
|
21
|
+
|
22
|
+
|
23
|
+
Server Software: thin
|
24
|
+
Server Hostname: 0.0.0.0
|
25
|
+
Server Port: 3000
|
26
|
+
|
27
|
+
Document Path: /
|
28
|
+
Document Length: 12 bytes
|
29
|
+
|
30
|
+
Concurrency Level: 30
|
31
|
+
Time taken for tests: 10.000 seconds
|
32
|
+
Complete requests: 38698
|
33
|
+
Failed requests: 0
|
34
|
+
Write errors: 0
|
35
|
+
Keep-Alive requests: 38698
|
36
|
+
Total transferred: 5611210 bytes
|
37
|
+
HTML transferred: 464376 bytes
|
38
|
+
Requests per second: 3869.70 [#/sec] (mean)
|
39
|
+
Time per request: 7.753 [ms] (mean)
|
40
|
+
Time per request: 0.258 [ms] (mean, across all concurrent requests)
|
41
|
+
Transfer rate: 547.96 [Kbytes/sec] received
|
42
|
+
|
43
|
+
Connection Times (ms)
|
44
|
+
min mean[+/-sd] median max
|
45
|
+
Connect: 0 0 0.0 0 1
|
46
|
+
Processing: 1 8 3.0 7 35
|
47
|
+
Waiting: 0 8 3.0 7 35
|
48
|
+
Total: 1 8 3.0 7 36
|
49
|
+
|
50
|
+
Percentage of the requests served within a certain time (ms)
|
51
|
+
50% 7
|
52
|
+
66% 8
|
53
|
+
75% 9
|
54
|
+
80% 10
|
55
|
+
90% 12
|
56
|
+
95% 13
|
57
|
+
98% 15
|
58
|
+
99% 16
|
59
|
+
100% 36 (longest request)
|
60
|
+
---------------------------------------------------------------------------------
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
require 'simple'
|
4
|
+
|
5
|
+
class HelloWorld < Simple::Base
|
6
|
+
|
7
|
+
namespace :api do
|
8
|
+
namespace :v1 do
|
9
|
+
get "/main" do
|
10
|
+
"API!!"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
resource :say do
|
16
|
+
get "/:message" do
|
17
|
+
"You said: #{params[:message]}!"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
get "/" do
|
22
|
+
"Hello World!"
|
23
|
+
end
|
24
|
+
|
25
|
+
post "/test" do
|
26
|
+
[200, {"content-type" => "text/plain"}, ["test..."]]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
run HelloWorld
|
data/lib/simple.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'http_router'
|
3
|
+
require 'simple/core_ext' unless defined?(ActiveSupport)
|
4
|
+
|
5
|
+
class Simple
|
6
|
+
class Base
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
attr_accessor :env, :request
|
11
|
+
|
12
|
+
def reset!
|
13
|
+
@namespace, @env = [], {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def inherited(subclass)
|
17
|
+
subclass.reset!
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def params; _params.merge(env['router.params']); end
|
22
|
+
def session; env['rack.session'] ||= {}; end
|
23
|
+
|
24
|
+
def namespace(path, &blk)
|
25
|
+
@namespace.push(path)
|
26
|
+
blk.yield
|
27
|
+
@namespace.pop
|
28
|
+
end
|
29
|
+
alias_method :path, :namespace
|
30
|
+
alias_method :resource, :namespace
|
31
|
+
alias_method :resources, :namespace
|
32
|
+
alias_method :segment, :namespace
|
33
|
+
alias_method :group, :namespace
|
34
|
+
|
35
|
+
def get(path, options = {}, &blk); route(:get, path, options, &blk); end
|
36
|
+
def post(path, options = {}, &blk); route(:post, path, options, &blk); end
|
37
|
+
def put(path, options = {}, &blk); route(:put, path, options, &blk); end
|
38
|
+
def delete(path, options = {}, &blk); route(:delete, path, options, &blk); end
|
39
|
+
def head(path, options = {}, &blk); route(:head, path, options, &blk); end
|
40
|
+
|
41
|
+
def call(env)
|
42
|
+
@request = Rack::Request.new(env)
|
43
|
+
@params = @request.params.symbolize_keys
|
44
|
+
return not_found unless router.recognize(env)
|
45
|
+
@env = env
|
46
|
+
compile_response(env)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def _params
|
52
|
+
(env['rack.request.form_hash'] || {}).symbolize_keys.merge (env['rack.request.query_hash'] || {}).symbolize_keys
|
53
|
+
end
|
54
|
+
|
55
|
+
def compile_response(env)
|
56
|
+
data = router.call(env)
|
57
|
+
return data if data.is_a?(Array)
|
58
|
+
response = Rack::Response.new(data, 200)
|
59
|
+
response.finish
|
60
|
+
end
|
61
|
+
|
62
|
+
def not_found
|
63
|
+
response ||= Rack::Response.new("Not Found", 404)
|
64
|
+
response.finish
|
65
|
+
end
|
66
|
+
|
67
|
+
def route(method, path, options = {}, &blk)
|
68
|
+
router.send(method.to_sym, @namespace * '/' + path, options) {|env| @env=env; instance_eval(&blk) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def router
|
72
|
+
@router ||= HttpRouter.new
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
API = Class.new(Base)
|
80
|
+
|
81
|
+
end
|
data/pkg/simple-0.1.gem
ADDED
Binary file
|
data/simple.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "simple/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "simple"
|
8
|
+
gem.version = Simple::VERSION
|
9
|
+
gem.author = "Bryan Goines"
|
10
|
+
gem.summary = "Simple lightweight web development framework for Ruby"
|
11
|
+
gem.email = "bryann83@gmail.com"
|
12
|
+
gem.homepage = "http://simplerb.com/"
|
13
|
+
gem.files = Dir['**/*']
|
14
|
+
# gem.executables = ""
|
15
|
+
gem.add_dependency "rack", "~> 1.4.1"
|
16
|
+
gem.add_dependency "http_router", "~> 0.10.2"
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe "ExampleApp" do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
let(:app) { Example }
|
7
|
+
|
8
|
+
it "GET /admin/show and then expect 200" do
|
9
|
+
get "/admin/show"
|
10
|
+
last_response.status.should == 200
|
11
|
+
last_response.body.should == "admin"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "GET /hello and then expect 200" do
|
15
|
+
get "/hello"
|
16
|
+
last_response.status.should == 200
|
17
|
+
last_response.body.should == "get"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "GET /blah/404 and then expect 403" do
|
21
|
+
get "/blah/404"
|
22
|
+
last_response.status.should == 404
|
23
|
+
last_response.body.should == "Not Found"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "POST /hello and then expect 200" do
|
27
|
+
post "/hello"
|
28
|
+
last_response.status.should == 200
|
29
|
+
last_response.body.should == "post"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "PUT /hello and then expect 200" do
|
33
|
+
put "/hello"
|
34
|
+
last_response.status.should == 200
|
35
|
+
last_response.body.should == "put"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "DELETE /hello and then expect 200" do
|
39
|
+
delete "/hello"
|
40
|
+
last_response.status.should == 200
|
41
|
+
last_response.body.should == "delete"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
ENV['RACK_ENV'] ||= "test"
|
4
|
+
|
5
|
+
require 'simple'
|
6
|
+
require 'rack/test'
|
7
|
+
|
8
|
+
class Example < Simple::Base
|
9
|
+
|
10
|
+
namespace :admin do
|
11
|
+
get "/show" do
|
12
|
+
"admin"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/hello' do
|
17
|
+
"get"
|
18
|
+
end
|
19
|
+
|
20
|
+
post "/hello" do
|
21
|
+
"post"
|
22
|
+
end
|
23
|
+
|
24
|
+
put "/hello" do
|
25
|
+
"put"
|
26
|
+
end
|
27
|
+
|
28
|
+
delete "/hello" do
|
29
|
+
"delete"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def session
|
35
|
+
last_request.env['rack.session']
|
36
|
+
end
|
metadata
CHANGED
@@ -1,95 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 0.0.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bryan Goines
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
name: thor
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-02-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70265566059960 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.1
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rake
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *70265566059960
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: http_router
|
27
|
+
requirement: &70265566059420 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
description: " ...\n"
|
50
|
-
email:
|
51
|
-
- bryann83@gmail.com
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.10.2
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70265566059420
|
36
|
+
description:
|
37
|
+
email: bryann83@gmail.com
|
52
38
|
executables: []
|
53
|
-
|
54
39
|
extensions: []
|
55
|
-
|
56
40
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
41
|
+
files:
|
42
|
+
- examples/benchmark.log
|
43
|
+
- examples/helloworld.ru
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- lib/simple/core_ext.rb
|
47
|
+
- lib/simple/version.rb
|
48
|
+
- lib/simple.rb
|
49
|
+
- pkg/simple-0.1.gem
|
50
|
+
- Rakefile
|
51
|
+
- README.md
|
52
|
+
- simple.gemspec
|
53
|
+
- spec/example_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
homepage: http://simplerb.com/
|
62
56
|
licenses: []
|
63
|
-
|
64
57
|
post_install_message:
|
65
58
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
59
|
+
require_paths:
|
68
60
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
62
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
68
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
87
73
|
requirements: []
|
88
|
-
|
89
74
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.8.10
|
91
76
|
signing_key:
|
92
77
|
specification_version: 3
|
93
|
-
summary:
|
78
|
+
summary: Simple lightweight web development framework for Ruby
|
94
79
|
test_files: []
|
95
|
-
|