mustermann 1.0.2 → 1.0.3

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: c50c1eac97dced280798f1af3eb0f66862a13001
4
- data.tar.gz: d7a7b5fa451c60d78b1d264b612e83a49918ce8a
3
+ metadata.gz: 0f9565d31c5b29a990840eb04f933be370358de6
4
+ data.tar.gz: 5f4dc020bd50b6d11f787dc555e0fcab6252d486
5
5
  SHA512:
6
- metadata.gz: 4431ea0c5e349895c64147b504326f895b1209ce814509ae18d0ed506ad1ac99f9baffa8ebdb22d88545db7f851f2f7058414a36f7df36b59af6bb5007c94275
7
- data.tar.gz: a199975d61ee06913ee9484af167d995fd25ebe9206129a6943f97a5adba649b4bb62552b3b4e0d335a15f5dd92d1b7e90baea31f8cad27c609a9dcc36e40fe9
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(*args) { super }
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 [Array<#hash>] key for caching
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(*key)
33
+ def fetch(key)
34
34
  identity = @keys[key.hash]
35
- key = identity == key ? identity : key
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
@@ -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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Mustermann
3
- VERSION ||= '1.0.2'
3
+ VERSION ||= '1.0.3'
4
4
  end
@@ -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
@@ -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(Timeout::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
 
@@ -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.2
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-02-16 00:00:00.000000000 Z
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