nyara 0.0.1.pre.5 → 0.0.1.pre.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/example/factorial.rb +19 -0
  3. data/ext/accept.c +2 -2
  4. data/ext/event.c +48 -23
  5. data/ext/extconf.rb +2 -0
  6. data/ext/hashes.c +28 -3
  7. data/ext/http-parser/http_parser.h +1 -0
  8. data/ext/nyara.c +20 -3
  9. data/ext/nyara.h +13 -2
  10. data/ext/request.c +90 -13
  11. data/ext/request.h +8 -2
  12. data/ext/request_parse.c +135 -6
  13. data/ext/route.cc +7 -10
  14. data/ext/test_response.c +155 -0
  15. data/ext/url_encoded.c +0 -5
  16. data/lib/nyara/config.rb +5 -0
  17. data/lib/nyara/controller.rb +91 -28
  18. data/lib/nyara/cookie.rb +7 -0
  19. data/lib/nyara/flash.rb +23 -0
  20. data/lib/nyara/hashes/header_hash.rb +2 -0
  21. data/lib/nyara/nyara.rb +14 -2
  22. data/lib/nyara/part.rb +156 -0
  23. data/lib/nyara/patches/array.rb +5 -0
  24. data/lib/nyara/patches/blank.rb +128 -0
  25. data/lib/nyara/patches/json.rb +15 -0
  26. data/lib/nyara/patches/mini_support.rb +6 -0
  27. data/lib/nyara/patches/string.rb +21 -0
  28. data/lib/nyara/patches/to_query.rb +113 -0
  29. data/lib/nyara/request.rb +13 -15
  30. data/lib/nyara/route.rb +15 -80
  31. data/lib/nyara/route_entry.rb +69 -2
  32. data/lib/nyara/session.rb +66 -21
  33. data/lib/nyara/test.rb +170 -0
  34. data/lib/nyara/view.rb +5 -6
  35. data/lib/nyara.rb +7 -6
  36. data/nyara.gemspec +2 -2
  37. data/rakefile +34 -4
  38. data/readme.md +8 -1
  39. data/spec/config_spec.rb +28 -0
  40. data/spec/cpu_counter_spec.rb +9 -0
  41. data/spec/evented_io_spec.rb +1 -0
  42. data/spec/flash_spec.rb +29 -0
  43. data/spec/hashes_spec.rb +8 -0
  44. data/spec/mini_support_spec.rb +54 -0
  45. data/spec/part_spec.rb +52 -0
  46. data/spec/path_helper_spec.rb +22 -14
  47. data/spec/request_delegate_spec.rb +19 -11
  48. data/spec/route_entry_spec.rb +55 -0
  49. data/spec/session_spec.rb +69 -7
  50. data/spec/spec_helper.rb +3 -0
  51. data/spec/test_spec.rb +58 -0
  52. data/tools/hello.rb +11 -3
  53. data/tools/memcheck.rb +33 -0
  54. data/tools/s.rb +11 -0
  55. metadata +23 -7
  56. data/example/design.rb +0 -62
  57. data/example/fib.rb +0 -15
  58. data/spec/route_spec.rb +0 -84
  59. /data/ext/inc/{status_codes.inc → status_codes.h} +0 -0
data/tools/memcheck.rb ADDED
@@ -0,0 +1,33 @@
1
+ require_relative "../lib/nyara/nyara"
2
+
3
+ module Nyara
4
+ class SimpleController < Controller
5
+ end
6
+ end
7
+
8
+ %w[on tag get post put delete patch options].each do |m|
9
+ eval <<-RUBY
10
+ def #{m} *xs, &blk
11
+ Nyara::SimpleController.#{m} *xs, &blk
12
+ end
13
+ RUBY
14
+ end
15
+
16
+ configure do
17
+ map '/', 'nyara::simple'
18
+ end
19
+
20
+ get '/' do
21
+ send_string 'hello world'
22
+ end
23
+
24
+ get '/gc' do
25
+ GC.stress = true
26
+ end
27
+
28
+ get '/ngc' do
29
+ GC.stress = false
30
+ end
31
+
32
+ Nyara.setup
33
+ Nyara.start_server
data/tools/s.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "sinatra"
2
+ require "active_support/core_ext"
3
+
4
+ configure {
5
+ disable :logging
6
+ disable :protection
7
+ }
8
+
9
+ get '/' do
10
+ 'hello world'
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.5
4
+ version: 0.0.1.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zete Lui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-27 00:00:00.000000000 Z
11
+ date: 2013-07-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fast, slim and fuzzy ruby web framework + server, based on preforked
14
14
  event queue and Fiber. NO rack NOR eventmachine are used.
@@ -21,8 +21,7 @@ files:
21
21
  - rakefile
22
22
  - nyara.gemspec
23
23
  - readme.md
24
- - example/design.rb
25
- - example/fib.rb
24
+ - example/factorial.rb
26
25
  - example/hello.rb
27
26
  - example/stream.rb
28
27
  - ext/extconf.rb
@@ -30,25 +29,39 @@ files:
30
29
  - lib/nyara/controller.rb
31
30
  - lib/nyara/cookie.rb
32
31
  - lib/nyara/cpu_counter.rb
32
+ - lib/nyara/flash.rb
33
33
  - lib/nyara/hashes/config_hash.rb
34
34
  - lib/nyara/hashes/header_hash.rb
35
35
  - lib/nyara/hashes/param_hash.rb
36
36
  - lib/nyara/mime_types.rb
37
37
  - lib/nyara/nyara.rb
38
+ - lib/nyara/part.rb
39
+ - lib/nyara/patches/array.rb
40
+ - lib/nyara/patches/blank.rb
41
+ - lib/nyara/patches/json.rb
42
+ - lib/nyara/patches/mini_support.rb
43
+ - lib/nyara/patches/string.rb
38
44
  - lib/nyara/patches/tcp_socket.rb
45
+ - lib/nyara/patches/to_query.rb
39
46
  - lib/nyara/request.rb
40
47
  - lib/nyara/route.rb
41
48
  - lib/nyara/route_entry.rb
42
49
  - lib/nyara/session.rb
50
+ - lib/nyara/test.rb
43
51
  - lib/nyara/view.rb
44
52
  - lib/nyara.rb
45
53
  - spec/apps/connect.rb
54
+ - spec/config_spec.rb
55
+ - spec/cpu_counter_spec.rb
46
56
  - spec/evented_io_spec.rb
47
57
  - spec/ext_mime_match_spec.rb
48
58
  - spec/ext_parse_accept_value_spec.rb
49
59
  - spec/ext_parse_spec.rb
50
60
  - spec/ext_route_spec.rb
61
+ - spec/flash_spec.rb
51
62
  - spec/hashes_spec.rb
63
+ - spec/mini_support_spec.rb
64
+ - spec/part_spec.rb
52
65
  - spec/path_helper_spec.rb
53
66
  - spec/performance/layout_render.rb
54
67
  - spec/performance/parse_accept_value.rb
@@ -58,15 +71,18 @@ files:
58
71
  - spec/request_delegate_spec.rb
59
72
  - spec/request_spec.rb
60
73
  - spec/route_entry_spec.rb
61
- - spec/route_spec.rb
62
74
  - spec/session_spec.rb
63
75
  - spec/spec_helper.rb
76
+ - spec/test_spec.rb
64
77
  - spec/view_spec.rb
65
78
  - tools/bench-cookie.rb
66
79
  - tools/hello.rb
80
+ - tools/memcheck.rb
81
+ - tools/s.rb
67
82
  - ext/http-parser/http_parser.h
68
83
  - ext/inc/epoll.h
69
84
  - ext/inc/kqueue.h
85
+ - ext/inc/status_codes.h
70
86
  - ext/inc/str_intern.h
71
87
  - ext/multipart-parser-c/multipart_parser.h
72
88
  - ext/nyara.h
@@ -85,9 +101,9 @@ files:
85
101
  - ext/nyara.c
86
102
  - ext/request.c
87
103
  - ext/request_parse.c
104
+ - ext/test_response.c
88
105
  - ext/url_encoded.c
89
106
  - ext/route.cc
90
- - ext/inc/status_codes.inc
91
107
  - ext/inc/version.inc
92
108
  - ext/http-parser/AUTHORS
93
109
  - ext/http-parser/CONTRIBUTIONS
@@ -95,7 +111,7 @@ files:
95
111
  - ext/multipart-parser-c/README.md
96
112
  homepage: https://github.com/luikore/nyara
97
113
  licenses:
98
- - BSD
114
+ - BSD 3-Clause
99
115
  metadata: {}
100
116
  post_install_message:
101
117
  rdoc_options: []
data/example/design.rb DELETED
@@ -1,62 +0,0 @@
1
- meta '#hello', accept: %w[js html] | default is text/html, default / * not implemented yet
2
- get '/' do
3
- send_data ... --> will make encoding chunked
4
-
5
- # set resp status
6
- status 302 | :not_found
7
-
8
- # content type is separated out from render
9
- content_type :js
10
-
11
- # terminal action : render view, or file for download
12
- render ..., layout: [a, b, c]
13
-
14
- render file # choose renderer by ext
15
- render :slim => template_content
16
-
17
- ... Fiber.yield
18
-
19
- s = stream ... # same arg as render
20
- ...
21
- r.resume
22
- ...
23
- r.resume
24
-
25
- render :slim, 'content'
26
-
27
- # terminal action
28
- redirect_to path_for '...'
29
- redirect_to '/'
30
- redirect_to :back # referrer
31
-
32
- # terminate process
33
- halt status
34
-
35
- # loop response
36
- loop do
37
- sleep 4
38
- send_data ...
39
- end
40
-
41
- # can use accept when meta is configured, raise error if not configured
42
- case accept
43
- when 'html'
44
- ...
45
- when 'js'
46
- end
47
- end
48
-
49
- # default is no scheme, the links start with // to fit all schemes
50
- configure url_for, default_scheme nil / 'https'
51
-
52
- url_for '#b', scheme: 'http', format: 'js', host: 'a.b.c:3000' # string keys are put in query
53
-
54
- path_for 'cont#action', 12, 3, :format => 'js', # string keys are put in query, (what about hash tags?)
55
-
56
- partial '...'
57
-
58
- # for middleware, we use life cycle callbacks
59
- # on :header_complete
60
- # on :init
61
-
62
- # before
data/example/fib.rb DELETED
@@ -1,15 +0,0 @@
1
- require "nyara"
2
-
3
- configure do
4
- port 3000
5
- end
6
-
7
- def fib i
8
- a, b = 0, 1
9
- i.times { a, b = b, a + b }
10
- a
11
- end
12
-
13
- get '/fib/%d' do |i|
14
- send_string "fib(#{i}) = #{fib i}\n"
15
- end
data/spec/route_spec.rb DELETED
@@ -1,84 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- module Nyara
4
- describe Route do
5
- # fixme: ugly code
6
- it "#process" do
7
- entries1 = [
8
- RouteEntry.new{
9
- @http_method = 'GET',
10
- @path = '/hello/%f',
11
- @id = :'#hello_f'
12
- },
13
- RouteEntry.new{
14
- @http_method = 'POST',
15
- @path = '/%s/%u-%d',
16
- @id = :'#post'
17
- }
18
- ]
19
- entries2 = [
20
- RouteEntry.new{
21
- @http_method = 'GET',
22
- @path = '/',
23
- @id = :'#hel'
24
- }
25
- ]
26
- entries3 = [
27
- RouteEntry.new{
28
- @http_method = 'GET',
29
- @path = '/%s',
30
- @id = :'#ello_s'
31
- }
32
- ]
33
-
34
- preprocessed_rules = [
35
- ['/', 'Stub1', entries1],
36
- ['/hel', 'Stub2', entries2],
37
- ['/ello', 'Stub3', entries3]
38
- ]
39
-
40
- rules = Route.process preprocessed_rules
41
- e_prefices, e_scopes, e_ids = [
42
- ['/hello/', '/', :'#hello_f'],
43
- ['/hel', '/hel', :'#hel'],
44
- ['/ello/', '/ello', :'#ello_s'],
45
- ['/', '/', :'#post']
46
- ].transpose
47
-
48
- assert_equal e_prefices, rules.map(&:prefix)
49
- assert_equal e_scopes, rules.map(&:scope)
50
- assert_equal e_ids, rules.map(&:id)
51
- end
52
-
53
- it "#compile_re" do
54
- re, conv = Route.compile_re '%s/%u/%d/%f/%x'
55
- assert_equal [:to_s, :to_i, :to_i, :to_f, :hex], conv
56
- s = '1/2/-3/4.5/F'
57
- assert_equal [s, *s.split('/')], s.match(Regexp.new re).to_a
58
-
59
- re, conv = Route.compile_re '/'
60
- assert_equal '^/$', re
61
- assert_equal [], conv
62
- end
63
-
64
- it "#compile_re with utf-8 chars" do
65
- re, conv = Route.compile_re '/目录/%da/也可以'
66
- assert_equal [:to_i], conv
67
- s = "/目录/12a/也可以"
68
- assert_equal [s, '12'], s.match(Regexp.new re).to_a
69
- end
70
-
71
- it "#analyse_path" do
72
- r = Route.analyse_path '/hello/%d-world%u/%s/'
73
- assert_equal ['/hello/', '%d-world%u/%s'], r
74
-
75
- prefix, suffix = Route.analyse_path '/hello'
76
- assert_equal '/hello', prefix
77
- assert_equal nil, suffix
78
-
79
- prefix, suffix = Route.analyse_path '/'
80
- assert_equal '/', prefix
81
- assert_equal nil, suffix
82
- end
83
- end
84
- end
File without changes