nancy 0.2.0 → 0.3.0
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/README.md +4 -0
- data/lib/nancy/base.rb +11 -14
- data/lib/nancy/version.rb +1 -1
- metadata +4 -3
data/README.md
CHANGED
@@ -104,6 +104,10 @@ Check examples folder for a detailed example.
|
|
104
104
|
|
105
105
|
## Version history
|
106
106
|
|
107
|
+
### 0.3.0 (Octuber 3, 2012)
|
108
|
+
* Removed unneccesary Thread accessors, use simple instance getters instead
|
109
|
+
* Refactored Nancy::Base#halt
|
110
|
+
|
107
111
|
### 0.2.0 (April 12, 2012)
|
108
112
|
|
109
113
|
* Set PATH INFO to '/' when is blank
|
data/lib/nancy/base.rb
CHANGED
@@ -2,6 +2,8 @@ require 'rack'
|
|
2
2
|
|
3
3
|
module Nancy
|
4
4
|
class Base
|
5
|
+
attr_reader :request, :response, :params, :env
|
6
|
+
|
5
7
|
class << self
|
6
8
|
%w(GET POST PATCH PUT DELETE HEAD OPTIONS).each do |verb|
|
7
9
|
define_method(verb.downcase) do |pattern, &block|
|
@@ -20,11 +22,7 @@ module Nancy
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.route_set
|
23
|
-
@route_set ||= Hash.new { |
|
24
|
-
end
|
25
|
-
|
26
|
-
%w(request response params env).each do |accessor|
|
27
|
-
define_method(accessor){ Thread.current[accessor.to_sym] }
|
25
|
+
@route_set ||= Hash.new { |hash, key| hash[key] = [] }
|
28
26
|
end
|
29
27
|
|
30
28
|
def session
|
@@ -55,10 +53,10 @@ module Nancy
|
|
55
53
|
end
|
56
54
|
|
57
55
|
def call(env)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
@request = Rack::Request.new(env)
|
57
|
+
@response = Rack::Response.new
|
58
|
+
@params = request.params
|
59
|
+
@env = env
|
62
60
|
response = catch(:halt) do
|
63
61
|
route_eval(request.request_method, request.path_info)
|
64
62
|
end.finish
|
@@ -70,7 +68,7 @@ module Nancy
|
|
70
68
|
if match = path_info.match(matcher[0])
|
71
69
|
if (captures = match.captures) && !captures.empty?
|
72
70
|
url_params = Hash[*matcher[1].zip(captures).flatten]
|
73
|
-
|
71
|
+
@params = url_params.merge(params)
|
74
72
|
end
|
75
73
|
response.write instance_eval(&block)
|
76
74
|
halt response
|
@@ -81,10 +79,9 @@ module Nancy
|
|
81
79
|
|
82
80
|
def halt(*res)
|
83
81
|
throw :halt, res.first if res.first.is_a?(Rack::Response)
|
84
|
-
response.status = res.
|
85
|
-
|
86
|
-
response.
|
87
|
-
response.body = [(res.select{|x| x.is_a?(String)}.first || "")]
|
82
|
+
response.status = res.detect{|x| x.is_a?(Fixnum) } || 200
|
83
|
+
response.header.merge!(res.detect{|x| x.is_a?(Hash) } || {})
|
84
|
+
response.body = [res.detect{|x| x.is_a?(String) } || ""]
|
88
85
|
throw :halt, response
|
89
86
|
end
|
90
87
|
end
|
data/lib/nancy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.23
|
129
129
|
signing_key:
|
130
130
|
specification_version: 3
|
131
131
|
summary: Ruby Microframework inspired in Sinatra
|
@@ -138,3 +138,4 @@ test_files:
|
|
138
138
|
- test/render_test.rb
|
139
139
|
- test/test_helper.rb
|
140
140
|
- test/use_test.rb
|
141
|
+
has_rdoc:
|