renee-core 0.1.1 → 0.2.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/lib/renee-core/application/chaining.rb +1 -0
- data/lib/renee-core/application/responding.rb +1 -1
- data/lib/renee-core/application/routing.rb +2 -2
- data/lib/renee-core/application/transform.rb +3 -0
- data/lib/renee-core/matcher.rb +14 -5
- data/lib/renee-core/settings.rb +10 -1
- data/lib/renee-core/version.rb +1 -1
- metadata +49 -19
@@ -80,7 +80,7 @@ class Renee
|
|
80
80
|
when Integer then Renee::Core::Response.new("Status code #{response}", response).finish
|
81
81
|
when Symbol then interpret_response(HTTP_CODES[response] || response.to_s)
|
82
82
|
when Proc then instance_eval(&response)
|
83
|
-
else
|
83
|
+
else raise "Unable to render #{response.inspect}"
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -43,7 +43,7 @@ class Renee
|
|
43
43
|
end
|
44
44
|
chain_method :exact_path
|
45
45
|
|
46
|
-
# Like #path, doesn't look for leading slashes.
|
46
|
+
# Like #path, but doesn't look for leading slashes.
|
47
47
|
def part(p, &blk)
|
48
48
|
p = /\/?#{Regexp.quote(p)}/ if p.is_a?(String)
|
49
49
|
if match = env['PATH_INFO'][p]
|
@@ -196,7 +196,7 @@ class Renee
|
|
196
196
|
# Match only when the path has been completely consumed.
|
197
197
|
#
|
198
198
|
# @example
|
199
|
-
#
|
199
|
+
# complete { halt [200, {}, "hello world"] }
|
200
200
|
#
|
201
201
|
# @api public
|
202
202
|
def complete(&blk)
|
@@ -1,6 +1,9 @@
|
|
1
1
|
class Renee
|
2
2
|
class Core
|
3
3
|
class Application
|
4
|
+
# Module used for transforming arbitrary values using the registerd variable types.
|
5
|
+
# @see #register_variable_name.
|
6
|
+
#
|
4
7
|
module Transform
|
5
8
|
# Transforms a value according to the rules specified by #register_variable_name.
|
6
9
|
# @param [Symbol] name The name of the variable type.
|
data/lib/renee-core/matcher.rb
CHANGED
@@ -1,32 +1,39 @@
|
|
1
1
|
class Renee
|
2
2
|
class Core
|
3
|
-
#
|
3
|
+
# Class used for variable matching.
|
4
4
|
class Matcher
|
5
5
|
attr_accessor :name
|
6
6
|
|
7
|
+
# @param [Regexp] matcher The regexp matcher to determine what is part of the variable.
|
7
8
|
def initialize(matcher)
|
8
9
|
@matcher = matcher
|
9
10
|
end
|
10
11
|
|
12
|
+
# Used to specific the error handler if the matcher doesn't match anything. By default, there is no error handler.
|
13
|
+
# @yield The block to be executed it fails to match.
|
11
14
|
def on_error(&blk)
|
12
15
|
@error_handler = blk
|
13
16
|
self
|
14
17
|
end
|
15
18
|
|
19
|
+
# Used to transform the value matched.
|
20
|
+
# @yield TODO
|
16
21
|
def on_transform(&blk)
|
17
22
|
@transform_handler = blk
|
18
23
|
self
|
19
24
|
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
# Convienence method to creating halting error handler.
|
27
|
+
# @param [Symbol, Integer] error_code The HTTP code to halt with.
|
28
|
+
# @see #interpret_response
|
25
29
|
def raise_on_error!(error_code = :bad_request)
|
26
30
|
on_error { halt error_code }
|
27
31
|
self
|
28
32
|
end
|
29
33
|
|
34
|
+
# Matcher for string
|
35
|
+
# @param [String] val The value to attempt to match on.
|
36
|
+
# @raise [ClientError] If the match fails to match and there is an error handler defined.
|
30
37
|
def [](val)
|
31
38
|
match = nil
|
32
39
|
case @matcher
|
@@ -47,6 +54,8 @@ class Renee
|
|
47
54
|
end
|
48
55
|
end
|
49
56
|
end
|
57
|
+
|
58
|
+
# Matcher for Integers
|
50
59
|
IntegerMatcher = Matcher.new(/\d+/).on_transform{|v| Integer(v)}
|
51
60
|
end
|
52
61
|
end
|
data/lib/renee-core/settings.rb
CHANGED
@@ -12,11 +12,12 @@ class Renee
|
|
12
12
|
def initialize
|
13
13
|
@includes = []
|
14
14
|
@variable_types = {}
|
15
|
+
@encoding = 'utf-8'
|
15
16
|
register_variable_type :integer, IntegerMatcher
|
16
17
|
register_variable_type :int, :integer
|
17
18
|
end
|
18
19
|
|
19
|
-
#
|
20
|
+
# Gets or sets the views_path for an application.
|
20
21
|
#
|
21
22
|
# @param [String] path The path to the view files.
|
22
23
|
#
|
@@ -29,7 +30,15 @@ class Renee
|
|
29
30
|
path ? @views_path = path : @views_path
|
30
31
|
end
|
31
32
|
|
33
|
+
# Gets or sets the default encoding used.
|
34
|
+
#
|
35
|
+
# @param [String] encoding The encoding to use. e.g. "utf-8"
|
36
|
+
def default_encoding(encoding = nil)
|
37
|
+
encoding ? @encoding = encoding : @encoding
|
38
|
+
end
|
39
|
+
|
32
40
|
# Module(s) to include into the base application.
|
41
|
+
#
|
33
42
|
# @param [Module] mods Modules to include.
|
34
43
|
def include(*mods)
|
35
44
|
mods.each { |mod| includes << mod }
|
data/lib/renee-core/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: renee-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Josh Hull
|
@@ -12,63 +17,88 @@ autorequire:
|
|
12
17
|
bindir: bin
|
13
18
|
cert_chain: []
|
14
19
|
|
15
|
-
date: 2011-10-
|
20
|
+
date: 2011-10-20 00:00:00 Z
|
16
21
|
dependencies:
|
17
22
|
- !ruby/object:Gem::Dependency
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
20
24
|
none: false
|
21
25
|
requirements:
|
22
26
|
- - ~>
|
23
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
- 0
|
24
33
|
version: 1.3.0
|
34
|
+
requirement: *id001
|
25
35
|
type: :runtime
|
26
36
|
prerelease: false
|
27
|
-
|
37
|
+
name: rack
|
28
38
|
- !ruby/object:Gem::Dependency
|
29
|
-
|
30
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
31
40
|
none: false
|
32
41
|
requirements:
|
33
42
|
- - ~>
|
34
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 21
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 6
|
48
|
+
- 1
|
35
49
|
version: 2.6.1
|
50
|
+
requirement: *id002
|
36
51
|
type: :development
|
37
52
|
prerelease: false
|
38
|
-
|
53
|
+
name: minitest
|
39
54
|
- !ruby/object:Gem::Dependency
|
40
|
-
|
41
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
42
56
|
none: false
|
43
57
|
requirements:
|
44
58
|
- - ~>
|
45
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 0
|
64
|
+
- 10
|
46
65
|
version: 1.0.10
|
66
|
+
requirement: *id003
|
47
67
|
type: :development
|
48
68
|
prerelease: false
|
49
|
-
|
69
|
+
name: bundler
|
50
70
|
- !ruby/object:Gem::Dependency
|
51
|
-
|
52
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
53
72
|
none: false
|
54
73
|
requirements:
|
55
74
|
- - ">="
|
56
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 11
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 5
|
80
|
+
- 0
|
57
81
|
version: 0.5.0
|
82
|
+
requirement: *id004
|
58
83
|
type: :development
|
59
84
|
prerelease: false
|
60
|
-
|
85
|
+
name: rack-test
|
61
86
|
- !ruby/object:Gem::Dependency
|
62
|
-
|
63
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
64
88
|
none: false
|
65
89
|
requirements:
|
66
90
|
- - "="
|
67
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 49
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
- 8
|
96
|
+
- 7
|
68
97
|
version: 0.8.7
|
98
|
+
requirement: *id005
|
69
99
|
type: :development
|
70
100
|
prerelease: false
|
71
|
-
|
101
|
+
name: rake
|
72
102
|
description: The super-friendly rack helpers.
|
73
103
|
email:
|
74
104
|
- joshbuddy@gmail.com
|
@@ -119,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
149
|
requirements:
|
120
150
|
- - ">="
|
121
151
|
- !ruby/object:Gem::Version
|
122
|
-
hash:
|
152
|
+
hash: 3
|
123
153
|
segments:
|
124
154
|
- 0
|
125
155
|
version: "0"
|
@@ -128,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
158
|
requirements:
|
129
159
|
- - ">="
|
130
160
|
- !ruby/object:Gem::Version
|
131
|
-
hash:
|
161
|
+
hash: 3
|
132
162
|
segments:
|
133
163
|
- 0
|
134
164
|
version: "0"
|