mustermann 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/mustermann.rb +1 -0
- data/lib/mustermann/ast/compiler.rb +1 -1
- data/lib/mustermann/ast/expander.rb +6 -6
- data/lib/mustermann/ast/parser.rb +2 -2
- data/lib/mustermann/ast/translator.rb +2 -2
- data/lib/mustermann/composite.rb +2 -2
- data/lib/mustermann/concat.rb +1 -1
- data/lib/mustermann/mapper.rb +1 -5
- data/lib/mustermann/pattern.rb +1 -1
- data/lib/mustermann/version.rb +1 -1
- data/mustermann.gemspec +2 -0
- data/spec/expander_spec.rb +2 -0
- data/spec/mapper_spec.rb +2 -9
- metadata +18 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f6e92bdd2542114b33a9f209cf71fdbe0b876b35abe09c1bb7309b640304e105
|
4
|
+
data.tar.gz: 8146636bb8dba303e828db1379302d3623912670c7cbf4238a24e4b6d766ff70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5982de41f3bdfa52e627f73a7c54dd4292681cf65acda63306dff7835a4f05126681ff6a0a1912448713d6f9103e55df4c5470368b9724040eb99cdf9190e07e
|
7
|
+
data.tar.gz: 6a8755d02a86521d0d3e1c68496a54b33ab5c88da85ec920d63b072647f861de36ee156a8b1524ea628b06a3439d940da4570031306763db589ed773b3eff088
|
data/lib/mustermann.rb
CHANGED
@@ -92,11 +92,11 @@ module Mustermann
|
|
92
92
|
# @see Mustermann::Pattern#expand
|
93
93
|
# @!visibility private
|
94
94
|
def expand(values)
|
95
|
-
|
95
|
+
adjusted = values.each_with_object({}){ |(key, value), new_hash|
|
96
96
|
new_hash[value.instance_of?(Array) ? [key] * value.length : key] = value }
|
97
|
-
keys, pattern, filters = mappings.fetch(
|
98
|
-
filters.each { |key, filter|
|
99
|
-
pattern % (
|
97
|
+
keys, pattern, filters = mappings.fetch(adjusted.keys.flatten.sort) { error_for(values) }
|
98
|
+
filters.each { |key, filter| adjusted[key] &&= escape(adjusted[key], also_escape: filter) }
|
99
|
+
pattern % (adjusted[keys] || adjusted.values_at(*keys))
|
100
100
|
end
|
101
101
|
|
102
102
|
# @see Mustermann::Pattern#expandable?
|
@@ -122,7 +122,7 @@ module Mustermann
|
|
122
122
|
|
123
123
|
# @see Mustermann::AST::Translator#expand
|
124
124
|
# @!visibility private
|
125
|
-
def escape(string, *args)
|
125
|
+
ruby2_keywords def escape(string, *args)
|
126
126
|
# URI::Parser is pretty slow, let's not send every string to it, even if it's unnecessary
|
127
127
|
string =~ /\A\w*\Z/ ? string : super
|
128
128
|
end
|
@@ -137,7 +137,7 @@ module Mustermann
|
|
137
137
|
# @!visibility private
|
138
138
|
def add_to(list, result)
|
139
139
|
list << [[], ""] if list.empty?
|
140
|
-
list.inject([]) { |l, (k1, p1, f1)| l + result.map { |k2, p2, f2| [k1+k2, p1+p2,
|
140
|
+
list.inject([]) { |l, (k1, p1, f1)| l + result.map { |k2, p2, f2| [k1+k2, p1+p2, f1.merge(f2)] } }
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
@@ -64,7 +64,7 @@ module Mustermann
|
|
64
64
|
# @param [Symbol] type node type
|
65
65
|
# @return [Mustermann::AST::Node]
|
66
66
|
# @!visibility private
|
67
|
-
def node(type, *args, &block)
|
67
|
+
ruby2_keywords def node(type, *args, &block)
|
68
68
|
type = Node[type] unless type.respond_to? :new
|
69
69
|
start = pos
|
70
70
|
node = block ? type.parse(*args, &block) : type.new(*args)
|
@@ -153,7 +153,7 @@ module Mustermann
|
|
153
153
|
def read_brackets(open, close, char: nil, escape: ?\\, quote: false, **options)
|
154
154
|
result = String.new
|
155
155
|
escape = false if escape.nil?
|
156
|
-
while current = getch
|
156
|
+
while (current = getch)
|
157
157
|
case current
|
158
158
|
when close then return result
|
159
159
|
when open then result << open << read_brackets(open, close) << close
|
@@ -36,7 +36,7 @@ module Mustermann
|
|
36
36
|
|
37
37
|
# shorthand for translating a nested object
|
38
38
|
# @!visibility private
|
39
|
-
def t(*args, &block)
|
39
|
+
ruby2_keywords def t(*args, &block)
|
40
40
|
return translator unless args.any?
|
41
41
|
translator.translate(*args, &block)
|
42
42
|
end
|
@@ -109,7 +109,7 @@ module Mustermann
|
|
109
109
|
|
110
110
|
# Start the translation dance for a (sub)tree.
|
111
111
|
# @!visibility private
|
112
|
-
def translate(node, *args, &block)
|
112
|
+
ruby2_keywords def translate(node, *args, &block)
|
113
113
|
result = decorator_for(node).translate(*args, &block)
|
114
114
|
result = result.node while result.is_a? NodeTranslator
|
115
115
|
result
|
data/lib/mustermann/composite.rb
CHANGED
@@ -102,9 +102,9 @@ module Mustermann
|
|
102
102
|
end
|
103
103
|
|
104
104
|
# @!visibility private
|
105
|
-
def patterns_from(pattern, options
|
105
|
+
def patterns_from(pattern, **options)
|
106
106
|
return pattern.patterns if pattern.is_a? Composite and pattern.operator == self.operator
|
107
|
-
[options ? Mustermann.new(pattern, **options)
|
107
|
+
[options.empty? && pattern.is_a?(Pattern) ? pattern : Mustermann.new(pattern, **options)]
|
108
108
|
end
|
109
109
|
|
110
110
|
private :with_matching, :patterns_from
|
data/lib/mustermann/concat.rb
CHANGED
data/lib/mustermann/mapper.rb
CHANGED
@@ -40,11 +40,7 @@ module Mustermann
|
|
40
40
|
#
|
41
41
|
# @example map before options
|
42
42
|
# require 'mustermann/mapper'
|
43
|
-
# Mustermann::Mapper.new("/:foo" => "/:foo.html", type: :rails)
|
44
|
-
#
|
45
|
-
# @example map after options
|
46
|
-
# require 'mustermann/mapper'
|
47
|
-
# Mustermann::Mapper.new(type: :rails, "/:foo" => "/:foo.html")
|
43
|
+
# Mustermann::Mapper.new({"/:foo" => "/:foo.html"}, type: :rails)
|
48
44
|
def initialize(map = {}, additional_values: :ignore, **options, &block)
|
49
45
|
@map = []
|
50
46
|
@options = options
|
data/lib/mustermann/pattern.rb
CHANGED
@@ -56,7 +56,7 @@ module Mustermann
|
|
56
56
|
end
|
57
57
|
|
58
58
|
@map ||= EqualityMap.new
|
59
|
-
@map.fetch([string, options]) { super(string, options) { options } }
|
59
|
+
@map.fetch([string, options]) { super(string, **options) { options } }
|
60
60
|
end
|
61
61
|
|
62
62
|
supported_options :uri_decode, :ignore_unknown_options
|
data/lib/mustermann/version.rb
CHANGED
data/mustermann.gemspec
CHANGED
@@ -14,4 +14,6 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
|
18
|
+
s.add_runtime_dependency('ruby2_keywords', '~> 0.0.1')
|
17
19
|
end
|
data/spec/expander_spec.rb
CHANGED
@@ -64,6 +64,8 @@ describe Mustermann::Expander do
|
|
64
64
|
example { expander.expand(a: ?a).should be == '/a' }
|
65
65
|
example { expander.expand(a: ?a, b: ?b).should be == '/a' }
|
66
66
|
example { expect { expander.expand(b: ?b) }.to raise_error(Mustermann::ExpandError) }
|
67
|
+
example { expect { expander.expand(b: ?b, c: []) }.to raise_error(Mustermann::ExpandError) }
|
68
|
+
example { expect { expander.expand(b: ?b, c: [], d: ?d) }.to raise_error(Mustermann::ExpandError) }
|
67
69
|
end
|
68
70
|
|
69
71
|
context :append do
|
data/spec/mapper_spec.rb
CHANGED
@@ -19,21 +19,14 @@ describe Mustermann::Mapper do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'accepts mappings followed by options' do
|
22
|
-
subject(:mapper) { Mustermann::Mapper.new("/foo" => "/bar", additional_values: :raise) }
|
23
|
-
its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
|
24
|
-
example { mapper['/foo'].should be == '/bar' }
|
25
|
-
example { mapper['/fox'].should be == '/fox' }
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'accepts options followed by mappings' do
|
29
|
-
subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise, "/foo" => "/bar") }
|
22
|
+
subject(:mapper) { Mustermann::Mapper.new({ "/foo" => "/bar" }, additional_values: :raise) }
|
30
23
|
its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
|
31
24
|
example { mapper['/foo'].should be == '/bar' }
|
32
25
|
example { mapper['/fox'].should be == '/fox' }
|
33
26
|
end
|
34
27
|
|
35
28
|
context 'allows specifying type' do
|
36
|
-
subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise, type: :rails
|
29
|
+
subject(:mapper) { Mustermann::Mapper.new({ "/foo" => "/bar" }, additional_values: :raise, type: :rails) }
|
37
30
|
its(:to_h) { should be == { Mustermann.new("/foo", type: :rails) => Mustermann::Expander.new("/bar", type: :rails) } }
|
38
31
|
example { mapper['/foo'].should be == '/bar' }
|
39
32
|
example { mapper['/fox'].should be == '/fox' }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustermann
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
@@ -9,8 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2019-12-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ruby2_keywords
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.0.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.0.1
|
14
28
|
description: A library implementing patterns that behave like regular expressions.
|
15
29
|
email: sinatrarb@googlegroups.com
|
16
30
|
executables: []
|
@@ -91,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
105
|
- !ruby/object:Gem::Version
|
92
106
|
version: '0'
|
93
107
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.6.8
|
108
|
+
rubygems_version: 3.0.3
|
96
109
|
signing_key:
|
97
110
|
specification_version: 4
|
98
111
|
summary: Your personal string matching expert.
|