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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c8547363a6513e1929f8c835e306ea76be70e41
4
- data.tar.gz: 5e53fcf63738709b08343cb80a64bea2869e54bd
3
+ metadata.gz: 52320fa050cf68249ee686d1d8a0e08ac28f1905
4
+ data.tar.gz: 66a2858bbde53da9b3b81137cf026575d7d073fe
5
5
  SHA512:
6
- metadata.gz: 636e193c4b1feefc03c28e7aa41ae80ba3ea0e63ff9668fbca9b952568543aabdaac06b0746fe6d053ca995c2b8ea2d87088aed43223efa8f033cc1361f91aea
7
- data.tar.gz: 90aa1a593c73faf5b5f6881f7263871b06409fac3b667818a1c784909eb9f2327029fbcfc138e12c884a174eadd1a466d2f0bc0063819b4448d7f99e29549f8d
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| process_route(*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 process_route(pattern, keys, conditions, block_id = nil, values = [])
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 process_mount_route(match, keys, conditions, block_id = nil, values = [])
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
- (block_id && (block = settings.blocks[block_id])) ? block[self, values] : yield(self, values)
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] << compile!(type, path || //, block, options)
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 = []
@@ -1,3 +1,3 @@
1
1
  module Sinarey
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinarey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey