mustermann 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/lib/mustermann/equality_map.rb +8 -4
- data/lib/mustermann/pattern.rb +1 -1
- data/lib/mustermann/sinatra/safe_renderer.rb +1 -0
- data/lib/mustermann/version.rb +1 -1
- data/spec/equality_map_spec.rb +16 -0
- data/spec/regular_spec.rb +1 -1
- data/spec/sinatra_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f9565d31c5b29a990840eb04f933be370358de6
|
4
|
+
data.tar.gz: 5f4dc020bd50b6d11f787dc555e0fcab6252d486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bf3d61ccac65e24d83b5551188ae5d9836b7664dad722fd077264d9b1b6e3097bc57b474c09acc3b250c009bd7852378b3049ee5630c28706335111ec651e60
|
7
|
+
data.tar.gz: b4ab4965dd93dae14ddf44c60116711a488ead67e0bf1109582c79ed86bf81c70315c1b9b4b6258978093515f4813e8f01d0aeca302de883289d65ccbcf5e870
|
@@ -10,7 +10,7 @@ module Mustermann
|
|
10
10
|
# @map = Mustermann::EqualityMap.new
|
11
11
|
#
|
12
12
|
# def self.new(*args)
|
13
|
-
# @map.fetch(
|
13
|
+
# @map.fetch(args) { super }
|
14
14
|
# end
|
15
15
|
# end
|
16
16
|
#
|
@@ -27,12 +27,16 @@ module Mustermann
|
|
27
27
|
@map = ObjectSpace::WeakMap.new
|
28
28
|
end
|
29
29
|
|
30
|
-
# @param [
|
30
|
+
# @param [#hash] key for caching
|
31
31
|
# @yield block that will be called to populate entry if missing (has to be idempotent)
|
32
32
|
# @return value stored in map or result of block
|
33
|
-
def fetch(
|
33
|
+
def fetch(key)
|
34
34
|
identity = @keys[key.hash]
|
35
|
-
|
35
|
+
if identity == key
|
36
|
+
key = identity
|
37
|
+
elsif key.frozen?
|
38
|
+
key = key.dup
|
39
|
+
end
|
36
40
|
|
37
41
|
# it is ok that this is not thread-safe, worst case it has double cost in
|
38
42
|
# generating, object equality is not guaranteed anyways
|
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
|
@@ -12,6 +12,7 @@ module Mustermann
|
|
12
12
|
translate(:group) { "(#{t(payload)})" }
|
13
13
|
translate(:union) { "(#{t(payload, join: ?|)})" }
|
14
14
|
translate(:optional) { "#{t(payload)}?" }
|
15
|
+
translate(:with_look_ahead) { t([head, payload]) }
|
15
16
|
translate(Array) { |join: ""| map { |e| t(e) }.join(join) }
|
16
17
|
|
17
18
|
translate(:capture) do
|
data/lib/mustermann/version.rb
CHANGED
data/spec/equality_map_spec.rb
CHANGED
@@ -22,5 +22,21 @@ RSpec.describe Mustermann::EqualityMap do
|
|
22
22
|
result = subject.fetch(String.new('foo')) { "bar" }
|
23
23
|
expect(result).to be == "bar"
|
24
24
|
end
|
25
|
+
|
26
|
+
specify 'allows a frozen key and value' do
|
27
|
+
next if subject.is_a? Hash
|
28
|
+
key = "foo".freeze
|
29
|
+
value = "bar".freeze
|
30
|
+
subject.fetch(key) { value }
|
31
|
+
result = subject.fetch("foo".dup) { raise "not executed" }
|
32
|
+
expect(result).to be == value
|
33
|
+
expect(result).not_to equal value
|
34
|
+
end
|
35
|
+
|
36
|
+
specify 'allows only a single argument to be compatible with Hash#fetch' do
|
37
|
+
expect {
|
38
|
+
subject.fetch("foo", "bar", "baz") { "value" }
|
39
|
+
}.to raise_error(ArgumentError)
|
40
|
+
end
|
25
41
|
end
|
26
42
|
end
|
data/spec/regular_spec.rb
CHANGED
@@ -51,7 +51,7 @@ describe Mustermann::Regular do
|
|
51
51
|
(.+) # match the second SHA1
|
52
52
|
}x
|
53
53
|
}
|
54
|
-
example { expect { Timeout.timeout(1){ Mustermann::Regular.new(pattern) }}.not_to raise_error
|
54
|
+
example { expect { Timeout.timeout(1){ Mustermann::Regular.new(pattern) }}.not_to raise_error }
|
55
55
|
it { expect(Mustermann::Regular.new(pattern)).to match('/compare/foo/bar..baz') }
|
56
56
|
end
|
57
57
|
|
data/spec/sinatra_spec.rb
CHANGED
@@ -826,4 +826,11 @@ describe Mustermann::Sinatra do
|
|
826
826
|
its(:class) { should be == Mustermann::Composite }
|
827
827
|
end
|
828
828
|
end
|
829
|
+
|
830
|
+
describe "native concatination" do
|
831
|
+
subject { Mustermann.new(prefix) + Mustermann.new(pattern) }
|
832
|
+
let(:prefix) { "/a" }
|
833
|
+
let(:pattern) { "/:b(.:c)?" }
|
834
|
+
it { should match("/a/b.json") }
|
835
|
+
end
|
829
836
|
end
|
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.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A library implementing patterns that behave like regular expressions.
|
15
15
|
email: sinatrarb@googlegroups.com
|