sinarey 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sinarey/base.rb +42 -7
- data/lib/sinarey/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52320fa050cf68249ee686d1d8a0e08ac28f1905
|
4
|
+
data.tar.gz: 66a2858bbde53da9b3b81137cf026575d7d073fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29e990f9e64c1fce9b008ab756f8f6cca957e338e3c78e8b9017f1ec7a6ff171e01ddf15a0c7443ff8eae100e32df4474ad4f6c481f6b52fc04e7045ba40b59
|
7
|
+
data.tar.gz: b16ba1a755d2b37232017eb21b5cf3425605e4798a81bf602acc4061b0980b83f6764179ce5f46043a84dc68e97444e02ade5e2a4671d5e3c8e3806fc0c47b90
|
data/lib/sinarey/base.rb
CHANGED
@@ -95,7 +95,7 @@ module Sinatra
|
|
95
95
|
# Run filters defined on the class and all superclasses.
|
96
96
|
def filter!(type, base = settings)
|
97
97
|
filter! type, base.superclass if base.superclass.respond_to?(:filters)
|
98
|
-
base.filters[type].each { |args|
|
98
|
+
base.filters[type].each { |args| process_filter(*args) }
|
99
99
|
end
|
100
100
|
|
101
101
|
# Run routes defined on the class and all superclasses.
|
@@ -170,15 +170,31 @@ module Sinatra
|
|
170
170
|
#
|
171
171
|
# Returns pass block.
|
172
172
|
|
173
|
+
def process_route(pattern, keys, conditions, block_id = nil, values = [])
|
174
|
+
route = @request.path_info
|
175
|
+
return unless match = pattern.match(route)
|
176
|
+
values += match.captures.map! { |v| force_encoding URI_INSTANCE.unescape(v) if v }
|
177
|
+
|
178
|
+
if values.any?
|
179
|
+
original, @params = params, params.merge('splat' => [], 'captures' => values)
|
180
|
+
keys.zip(values) { |k,v| Array === @params[k] ? @params[k] << v : @params[k] = v if v }
|
181
|
+
end
|
182
|
+
|
183
|
+
catch(:pass) do
|
184
|
+
conditions.each { |c| throw :pass if c.bind(self).call == false }
|
185
|
+
(block_id && (block = settings.blocks[block_id])) ? block[self, values] : yield(self, values)
|
186
|
+
end
|
187
|
+
ensure
|
188
|
+
@params = original if original
|
189
|
+
end
|
190
|
+
|
173
191
|
def process_turbo_route(block = nil)
|
174
192
|
catch(:pass) do
|
175
193
|
block ? block[self, []] : yield(self, [])
|
176
194
|
end
|
177
195
|
end
|
178
196
|
|
179
|
-
def
|
180
|
-
route = @request.path_info
|
181
|
-
return unless match = pattern.match(route)
|
197
|
+
def process_mount_route(match, keys, conditions, block_id = nil, values = [])
|
182
198
|
values += match.captures.map! { |v| force_encoding URI_INSTANCE.unescape(v) if v }
|
183
199
|
|
184
200
|
if values.any?
|
@@ -194,7 +210,10 @@ module Sinatra
|
|
194
210
|
@params = original if original
|
195
211
|
end
|
196
212
|
|
197
|
-
def
|
213
|
+
def process_filter(pattern, keys, conditions, block = nil, values = [])
|
214
|
+
route = @request.path_info
|
215
|
+
route = '/' if route.empty? and not settings.empty_path_info?
|
216
|
+
return unless match = pattern.match(route)
|
198
217
|
values += match.captures.map! { |v| force_encoding URI_INSTANCE.unescape(v) if v }
|
199
218
|
|
200
219
|
if values.any?
|
@@ -204,7 +223,7 @@ module Sinatra
|
|
204
223
|
|
205
224
|
catch(:pass) do
|
206
225
|
conditions.each { |c| throw :pass if c.bind(self).call == false }
|
207
|
-
|
226
|
+
block ? block[self, values] : yield(self, values)
|
208
227
|
end
|
209
228
|
ensure
|
210
229
|
@params = original if original
|
@@ -535,7 +554,7 @@ module Sinatra
|
|
535
554
|
# add a filter
|
536
555
|
def add_filter(type, path = nil, options = {}, &block)
|
537
556
|
path, options = //, path if path.respond_to?(:each_pair)
|
538
|
-
filters[type] <<
|
557
|
+
filters[type] << compile_filter!(type, path || //, block, options)
|
539
558
|
end
|
540
559
|
|
541
560
|
# Add a route condition. The route is considered non-matching when the
|
@@ -833,6 +852,22 @@ module Sinatra
|
|
833
852
|
[ pattern, keys, conditions, block_id ]
|
834
853
|
end
|
835
854
|
|
855
|
+
def compile_filter!(verb, path, block, options = {})
|
856
|
+
options.each_pair { |option, args| send(option, *args) }
|
857
|
+
method_name = "#{verb} #{path}"
|
858
|
+
unbound_method = generate_method(method_name, &block)
|
859
|
+
pattern, keys = compile path
|
860
|
+
conditions, @conditions = @conditions, []
|
861
|
+
|
862
|
+
wrapper = block.arity != 0 ?
|
863
|
+
proc { |a,p| unbound_method.bind(a).call(*p) } :
|
864
|
+
proc { |a,p| unbound_method.bind(a).call }
|
865
|
+
wrapper.instance_variable_set(:@route_name, method_name)
|
866
|
+
|
867
|
+
[ pattern, keys, conditions, wrapper ]
|
868
|
+
end
|
869
|
+
|
870
|
+
|
836
871
|
def compile(path)
|
837
872
|
if path.respond_to? :to_str
|
838
873
|
keys = []
|
data/lib/sinarey/version.rb
CHANGED