mustermann 1.0.0.beta2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +23 -0
- data/lib/mustermann.rb +1 -0
- data/lib/mustermann/ast/boundaries.rb +2 -1
- data/lib/mustermann/ast/compiler.rb +1 -0
- data/lib/mustermann/ast/expander.rb +1 -0
- data/lib/mustermann/ast/param_scanner.rb +1 -0
- data/lib/mustermann/ast/parser.rb +4 -3
- data/lib/mustermann/ast/pattern.rb +2 -2
- data/lib/mustermann/ast/template_generator.rb +1 -0
- data/lib/mustermann/ast/transformer.rb +1 -0
- data/lib/mustermann/ast/translator.rb +3 -2
- data/lib/mustermann/ast/validation.rb +1 -0
- data/lib/mustermann/caster.rb +1 -0
- data/lib/mustermann/composite.rb +1 -0
- data/lib/mustermann/concat.rb +1 -0
- data/lib/mustermann/equality_map.rb +3 -1
- data/lib/mustermann/error.rb +2 -1
- data/lib/mustermann/expander.rb +1 -0
- data/lib/mustermann/extension.rb +1 -0
- data/lib/mustermann/identity.rb +1 -0
- data/lib/mustermann/mapper.rb +1 -0
- data/lib/mustermann/pattern.rb +2 -1
- data/lib/mustermann/pattern_cache.rb +3 -2
- data/lib/mustermann/regexp_based.rb +1 -0
- data/lib/mustermann/regular.rb +1 -0
- data/lib/mustermann/simple_match.rb +1 -0
- data/lib/mustermann/sinatra.rb +1 -0
- data/lib/mustermann/sinatra/parser.rb +1 -0
- data/lib/mustermann/sinatra/safe_renderer.rb +1 -0
- data/lib/mustermann/sinatra/try_convert.rb +2 -1
- data/lib/mustermann/to_pattern.rb +1 -0
- data/lib/mustermann/version.rb +2 -1
- data/mustermann.gemspec +3 -3
- data/spec/ast_spec.rb +2 -1
- data/spec/composite_spec.rb +1 -0
- data/spec/concat_spec.rb +2 -1
- data/spec/equality_map_spec.rb +3 -2
- data/spec/expander_spec.rb +1 -0
- data/spec/extension_spec.rb +2 -1
- data/spec/identity_spec.rb +1 -0
- data/spec/mapper_spec.rb +1 -0
- data/spec/mustermann_spec.rb +2 -1
- data/spec/pattern_spec.rb +1 -0
- data/spec/regexp_based_spec.rb +1 -0
- data/spec/regular_spec.rb +1 -0
- data/spec/simple_match_spec.rb +1 -0
- data/spec/sinatra_spec.rb +1 -0
- data/spec/to_pattern_spec.rb +1 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dcbbae7585845981a56f957deb4b729d311ffab
|
4
|
+
data.tar.gz: 5c446520da882ed59f6fa38304343c10b7b67dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5c237bc73e1cfd18d923ba55514ffc66a575f81086f935eec4aa6831554f57ac955aad122cb169f09693c3265d544a6d32cbcb60557c64fe93582586ee98975
|
7
|
+
data.tar.gz: a6e0cda3b4b51c0b914806b86467374d7222e026b9be9d5f4a43e09a7acbd25d736e1075b13dee2c864750e16b55c1ccb7b3d74d1e6de23440879f31b381e972
|
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013-2017 Konstantin Haase
|
2
|
+
Copyright (c) 2016-2017 Zachary Scott
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/mustermann.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'mustermann/ast/node'
|
2
3
|
require 'forwardable'
|
3
4
|
require 'strscan'
|
@@ -150,7 +151,7 @@ module Mustermann
|
|
150
151
|
#
|
151
152
|
# @!visibility private
|
152
153
|
def read_brackets(open, close, char: nil, escape: ?\\, quote: false, **options)
|
153
|
-
result =
|
154
|
+
result = String.new
|
154
155
|
escape = false if escape.nil?
|
155
156
|
while current = getch
|
156
157
|
case current
|
@@ -193,7 +194,7 @@ module Mustermann
|
|
193
194
|
case current
|
194
195
|
when *close then return result
|
195
196
|
when ignore then nil # do nothing
|
196
|
-
when separator then result <<
|
197
|
+
when separator then result << String.new
|
197
198
|
when escape then element << getch
|
198
199
|
when *quotes then element << read_escaped(current, escape: escape)
|
199
200
|
else element << current
|
@@ -206,7 +207,7 @@ module Mustermann
|
|
206
207
|
#
|
207
208
|
# @!visibility private
|
208
209
|
def read_escaped(close, escape: ?\\, **options)
|
209
|
-
result =
|
210
|
+
result = String.new
|
210
211
|
while current = getch
|
211
212
|
case current
|
212
213
|
when close then return result
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'mustermann/ast/parser'
|
2
3
|
require 'mustermann/ast/boundaries'
|
3
4
|
require 'mustermann/ast/compiler'
|
@@ -79,8 +80,7 @@ module Mustermann
|
|
79
80
|
options[:except] &&= parse options[:except]
|
80
81
|
compiler.compile(to_ast, **options)
|
81
82
|
rescue CompileError => error
|
82
|
-
error.
|
83
|
-
raise error
|
83
|
+
raise error.class, "#{error.message}: #{@string.inspect}", error.backtrace
|
84
84
|
end
|
85
85
|
|
86
86
|
# Internal AST representation of pattern.
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'mustermann/ast/node'
|
2
3
|
require 'mustermann/error'
|
3
4
|
require 'delegate'
|
@@ -79,13 +80,13 @@ module Mustermann
|
|
79
80
|
# @example
|
80
81
|
# require 'mustermann'
|
81
82
|
# require 'mustermann/ast/translator'
|
82
|
-
#
|
83
|
+
#
|
83
84
|
# translator = Mustermann::AST::Translator.create do
|
84
85
|
# translate(:node) { [type, *t(payload)].flatten.compact }
|
85
86
|
# translate(Array) { map { |e| t(e) } }
|
86
87
|
# translate(Object) { }
|
87
88
|
# end
|
88
|
-
#
|
89
|
+
#
|
89
90
|
# ast = Mustermann.new('/:name').to_ast
|
90
91
|
# translator.translate(ast) # => [:root, :separator, :capture]
|
91
92
|
#
|
data/lib/mustermann/caster.rb
CHANGED
data/lib/mustermann/composite.rb
CHANGED
data/lib/mustermann/concat.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Mustermann
|
2
3
|
# A simple wrapper around ObjectSpace::WeakMap that allows matching keys by equality rather than identity.
|
3
4
|
# Used for caching. Note that `fetch` is not guaranteed to return the object, even if it has not been
|
@@ -42,6 +43,7 @@ module Mustermann
|
|
42
43
|
# @param [Object] object to be stored
|
43
44
|
# @return [Object] same as the second parameter
|
44
45
|
def track(key, object)
|
46
|
+
object = object.dup if object.frozen?
|
45
47
|
ObjectSpace.define_finalizer(object, finalizer(key.hash))
|
46
48
|
@keys[key.hash] = key
|
47
49
|
object
|
@@ -49,7 +51,7 @@ module Mustermann
|
|
49
51
|
|
50
52
|
# Finalizer proc needs to be generated in different scope so it doesn't keep a reference to the object.
|
51
53
|
#
|
52
|
-
# @param [
|
54
|
+
# @param [Integer] hash for key
|
53
55
|
# @return [Proc] finalizer callback
|
54
56
|
def finalizer(hash)
|
55
57
|
proc { @keys.delete(hash) }
|
data/lib/mustermann/error.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Mustermann
|
2
3
|
Error ||= Class.new(StandardError) # Raised if anything goes wrong while generating a {Pattern}.
|
3
4
|
CompileError ||= Class.new(Error) # Raised if anything goes wrong while compiling a {Pattern}.
|
4
5
|
ParseError ||= Class.new(Error) # Raised if anything goes wrong while parsing a {Pattern}.
|
5
6
|
ExpandError ||= Class.new(Error) # Raised if anything goes wrong while expanding a {Pattern}.
|
6
|
-
end
|
7
|
+
end
|
data/lib/mustermann/expander.rb
CHANGED
data/lib/mustermann/extension.rb
CHANGED
data/lib/mustermann/identity.rb
CHANGED
data/lib/mustermann/mapper.rb
CHANGED
data/lib/mustermann/pattern.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'mustermann/error'
|
2
3
|
require 'mustermann/simple_match'
|
3
4
|
require 'mustermann/equality_map'
|
@@ -107,7 +108,7 @@ module Mustermann
|
|
107
108
|
end
|
108
109
|
|
109
110
|
# Used by Ruby internally for hashing.
|
110
|
-
# @return [
|
111
|
+
# @return [Integer] same has value for patterns that are equal
|
111
112
|
def hash
|
112
113
|
self.class.hash | @string.hash | options.hash
|
113
114
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'set'
|
2
3
|
require 'thread'
|
3
4
|
require 'mustermann'
|
@@ -8,7 +9,7 @@ module Mustermann
|
|
8
9
|
# @example
|
9
10
|
# require 'mustermann/pattern_cache'
|
10
11
|
# cache = Mustermann::PatternCache.new
|
11
|
-
#
|
12
|
+
#
|
12
13
|
# # use this instead of Mustermann.new
|
13
14
|
# pattern = cache.create_pattern("/:name", type: :rails)
|
14
15
|
#
|
@@ -46,4 +47,4 @@ module Mustermann
|
|
46
47
|
@mutex.synchronize { @cached.size }
|
47
48
|
end
|
48
49
|
end
|
49
|
-
end
|
50
|
+
end
|
data/lib/mustermann/regular.rb
CHANGED
data/lib/mustermann/sinatra.rb
CHANGED
data/lib/mustermann/version.rb
CHANGED
data/mustermann.gemspec
CHANGED
@@ -4,9 +4,9 @@ require "mustermann/version"
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "mustermann"
|
6
6
|
s.version = Mustermann::VERSION
|
7
|
-
s.
|
8
|
-
s.email = "
|
9
|
-
s.homepage = "https://github.com/
|
7
|
+
s.authors = ["Konstantin Haase", "Zachary Scott"]
|
8
|
+
s.email = "sinatrarb@googlegroups.com"
|
9
|
+
s.homepage = "https://github.com/sinatra/mustermann"
|
10
10
|
s.summary = %q{use patterns like regular expressions}
|
11
11
|
s.description = %q{library implementing patterns that behave like regular expressions}
|
12
12
|
s.license = 'MIT'
|
data/spec/ast_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'support'
|
2
3
|
require 'mustermann/ast/node'
|
3
4
|
|
@@ -11,4 +12,4 @@ describe Mustermann::AST do
|
|
11
12
|
example { Mustermann::AST::Node[:char].new.min_size.should be == 1 }
|
12
13
|
example { Mustermann::AST::Node[:node].new.min_size.should be == 0 }
|
13
14
|
end
|
14
|
-
end
|
15
|
+
end
|
data/spec/composite_spec.rb
CHANGED
data/spec/concat_spec.rb
CHANGED
data/spec/equality_map_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'support'
|
2
3
|
require 'mustermann/equality_map'
|
3
4
|
|
@@ -16,9 +17,9 @@ RSpec.describe Mustermann::EqualityMap do
|
|
16
17
|
|
17
18
|
specify 'with GC-removed entry' do
|
18
19
|
next if subject.is_a? Hash
|
19
|
-
subject.fetch(
|
20
|
+
subject.fetch(String.new('foo')) { "foo" }
|
20
21
|
expect(subject.map).to receive(:[]).and_return(nil)
|
21
|
-
result = subject.fetch(
|
22
|
+
result = subject.fetch(String.new('foo')) { "bar" }
|
22
23
|
expect(result).to be == "bar"
|
23
24
|
end
|
24
25
|
end
|
data/spec/expander_spec.rb
CHANGED
data/spec/extension_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'support'
|
2
3
|
require 'mustermann/extension'
|
3
4
|
require 'sinatra/base'
|
@@ -293,4 +294,4 @@ describe Mustermann::Extension do
|
|
293
294
|
example { get('/auth/dunno').body.should be == 'auth required' }
|
294
295
|
example { get('/auth/login').body.should be == 'please log in' }
|
295
296
|
end
|
296
|
-
end
|
297
|
+
end
|
data/spec/identity_spec.rb
CHANGED
data/spec/mapper_spec.rb
CHANGED
data/spec/mustermann_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'support'
|
2
3
|
require 'mustermann'
|
3
4
|
require 'mustermann/extension'
|
@@ -49,7 +50,7 @@ describe Mustermann do
|
|
49
50
|
|
50
51
|
context "invalid arguments" do
|
51
52
|
it "raise a TypeError for unsupported types" do
|
52
|
-
expect { Mustermann.new(10) }.to raise_error(TypeError,
|
53
|
+
expect { Mustermann.new(10) }.to raise_error(TypeError, /(Integer|Fixnum) can't be coerced into Mustermann::Pattern/)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
data/spec/pattern_spec.rb
CHANGED
data/spec/regexp_based_spec.rb
CHANGED
data/spec/regular_spec.rb
CHANGED
data/spec/simple_match_spec.rb
CHANGED
data/spec/sinatra_spec.rb
CHANGED
data/spec/to_pattern_spec.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustermann
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
8
|
+
- Zachary Scott
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-03-04 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
14
|
description: library implementing patterns that behave like regular expressions
|
14
|
-
email:
|
15
|
+
email: sinatrarb@googlegroups.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- LICENSE
|
19
21
|
- README.md
|
20
22
|
- bench/capturing.rb
|
21
23
|
- bench/regexp.rb
|
@@ -70,7 +72,7 @@ files:
|
|
70
72
|
- spec/simple_match_spec.rb
|
71
73
|
- spec/sinatra_spec.rb
|
72
74
|
- spec/to_pattern_spec.rb
|
73
|
-
homepage: https://github.com/
|
75
|
+
homepage: https://github.com/sinatra/mustermann
|
74
76
|
licenses:
|
75
77
|
- MIT
|
76
78
|
metadata: {}
|
@@ -85,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
87
|
version: 2.2.0
|
86
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
89
|
requirements:
|
88
|
-
- - "
|
90
|
+
- - ">="
|
89
91
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
92
|
+
version: '0'
|
91
93
|
requirements: []
|
92
94
|
rubyforge_project:
|
93
95
|
rubygems_version: 2.5.1
|
@@ -95,4 +97,3 @@ signing_key:
|
|
95
97
|
specification_version: 4
|
96
98
|
summary: use patterns like regular expressions
|
97
99
|
test_files: []
|
98
|
-
has_rdoc:
|