mustermann 1.0.0.beta2 → 1.0.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +23 -0
  3. data/lib/mustermann.rb +1 -0
  4. data/lib/mustermann/ast/boundaries.rb +2 -1
  5. data/lib/mustermann/ast/compiler.rb +1 -0
  6. data/lib/mustermann/ast/expander.rb +1 -0
  7. data/lib/mustermann/ast/param_scanner.rb +1 -0
  8. data/lib/mustermann/ast/parser.rb +4 -3
  9. data/lib/mustermann/ast/pattern.rb +2 -2
  10. data/lib/mustermann/ast/template_generator.rb +1 -0
  11. data/lib/mustermann/ast/transformer.rb +1 -0
  12. data/lib/mustermann/ast/translator.rb +3 -2
  13. data/lib/mustermann/ast/validation.rb +1 -0
  14. data/lib/mustermann/caster.rb +1 -0
  15. data/lib/mustermann/composite.rb +1 -0
  16. data/lib/mustermann/concat.rb +1 -0
  17. data/lib/mustermann/equality_map.rb +3 -1
  18. data/lib/mustermann/error.rb +2 -1
  19. data/lib/mustermann/expander.rb +1 -0
  20. data/lib/mustermann/extension.rb +1 -0
  21. data/lib/mustermann/identity.rb +1 -0
  22. data/lib/mustermann/mapper.rb +1 -0
  23. data/lib/mustermann/pattern.rb +2 -1
  24. data/lib/mustermann/pattern_cache.rb +3 -2
  25. data/lib/mustermann/regexp_based.rb +1 -0
  26. data/lib/mustermann/regular.rb +1 -0
  27. data/lib/mustermann/simple_match.rb +1 -0
  28. data/lib/mustermann/sinatra.rb +1 -0
  29. data/lib/mustermann/sinatra/parser.rb +1 -0
  30. data/lib/mustermann/sinatra/safe_renderer.rb +1 -0
  31. data/lib/mustermann/sinatra/try_convert.rb +2 -1
  32. data/lib/mustermann/to_pattern.rb +1 -0
  33. data/lib/mustermann/version.rb +2 -1
  34. data/mustermann.gemspec +3 -3
  35. data/spec/ast_spec.rb +2 -1
  36. data/spec/composite_spec.rb +1 -0
  37. data/spec/concat_spec.rb +2 -1
  38. data/spec/equality_map_spec.rb +3 -2
  39. data/spec/expander_spec.rb +1 -0
  40. data/spec/extension_spec.rb +2 -1
  41. data/spec/identity_spec.rb +1 -0
  42. data/spec/mapper_spec.rb +1 -0
  43. data/spec/mustermann_spec.rb +2 -1
  44. data/spec/pattern_spec.rb +1 -0
  45. data/spec/regexp_based_spec.rb +1 -0
  46. data/spec/regular_spec.rb +1 -0
  47. data/spec/simple_match_spec.rb +1 -0
  48. data/spec/sinatra_spec.rb +1 -0
  49. data/spec/to_pattern_spec.rb +1 -0
  50. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90d5c978f69743fdbee3eec3efc6bc6c05a83dfb
4
- data.tar.gz: e777bda67af6ff598fc5a584ae786fa78eb68c4b
3
+ metadata.gz: 1dcbbae7585845981a56f957deb4b729d311ffab
4
+ data.tar.gz: 5c446520da882ed59f6fa38304343c10b7b67dab
5
5
  SHA512:
6
- metadata.gz: 2b92c4b696adefa6c6c0ce16fc6a3ef7a3e85834e9579dbc8a7108fc535888da5dc907f39c087fac8abf5b26a387b81e85c7c45f161b691e40f9709e382df07b
7
- data.tar.gz: fe32e08661344ce33c9066610e6d1591999fb62210597714e1f406b2161e4e517438d5c026fe801b84a262ec97cdbc76e471ecffae233275888aa4d1f6139814
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.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/pattern'
2
3
  require 'mustermann/composite'
3
4
  require 'mustermann/concat'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/ast/translator'
2
3
 
3
4
  module Mustermann
@@ -41,4 +42,4 @@ module Mustermann
41
42
  end
42
43
  end
43
44
  end
44
- end
45
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/ast/translator'
2
3
 
3
4
  module Mustermann
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/ast/translator'
2
3
  require 'mustermann/ast/compiler'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/ast/translator'
2
3
 
3
4
  module Mustermann
@@ -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.message << ": %p" % @string
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/translator'
2
3
 
3
4
  module Mustermann
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/ast/translator'
2
3
 
3
4
  module Mustermann
@@ -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
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/ast/translator'
2
3
 
3
4
  module Mustermann
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'delegate'
2
3
 
3
4
  module Mustermann
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mustermann
2
3
  # Class for pattern objects composed of multiple patterns using binary logic.
3
4
  # @see Mustermann::Pattern#&
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mustermann
2
3
  # Class for pattern objects that are a concatenation of other patterns.
3
4
  # @see Mustermann::Pattern#+
@@ -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 [Fixnum] hash for key
54
+ # @param [Integer] hash for key
53
55
  # @return [Proc] finalizer callback
54
56
  def finalizer(hash)
55
57
  proc { @keys.delete(hash) }
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/ast/expander'
2
3
  require 'mustermann/caster'
3
4
  require 'mustermann'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sinatra/version'
2
3
  fail "no need to load the Mustermann extension for #{::Sinatra::VERSION}" if ::Sinatra::VERSION >= '2.0.0'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann'
2
3
  require 'mustermann/pattern'
3
4
  require 'mustermann/ast/node'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann'
2
3
  require 'mustermann/expander'
3
4
 
@@ -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 [Fixnum] same has value for patterns that are equal
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann/pattern'
2
3
  require 'forwardable'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann'
2
3
  require 'mustermann/regexp_based'
3
4
  require 'strscan'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mustermann
2
3
  # Fakes MatchData for patterns that do not support capturing.
3
4
  # @see http://ruby-doc.org/core-2.0/MatchData.html MatchData
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann'
2
3
  require 'mustermann/identity'
3
4
  require 'mustermann/ast/pattern'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mustermann
2
3
  class Sinatra < AST::Pattern
3
4
  # Sinatra syntax definition.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mustermann
2
3
  class Sinatra < AST::Pattern
3
4
  # Generates a string that can safely be concatenated with other strings
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mustermann
2
3
  class Sinatra < AST::Pattern
3
4
  # Tries to translate objects to Sinatra patterns.
@@ -45,4 +46,4 @@ module Mustermann
45
46
 
46
47
  private_constant :TryConvert
47
48
  end
48
- end
49
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'mustermann'
2
3
 
3
4
  module Mustermann
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mustermann
2
- VERSION ||= '1.0.0.beta2'
3
+ VERSION ||= '1.0.0'
3
4
  end
@@ -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.author = "Konstantin Haase"
8
- s.email = "konstantin.mailinglists@googlemail.com"
9
- s.homepage = "https://github.com/rkh/mustermann"
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'
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann'
3
4
 
@@ -111,4 +112,4 @@ describe Mustermann::Concat do
111
112
  it { should generate_template("/{foo}") }
112
113
  it { should generate_template("{bar}") }
113
114
  end
114
- end
115
+ end
@@ -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("foo") { "foo" }
20
+ subject.fetch(String.new('foo')) { "foo" }
20
21
  expect(subject.map).to receive(:[]).and_return(nil)
21
- result = subject.fetch("foo") { "bar" }
22
+ result = subject.fetch(String.new('foo')) { "bar" }
22
23
  expect(result).to be == "bar"
23
24
  end
24
25
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/expander'
3
4
 
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/identity'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/mapper'
3
4
 
@@ -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, "Fixnum can't be coerced into Mustermann::Pattern")
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/pattern'
3
4
  require 'mustermann/sinatra'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/regexp_based'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/regular'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/simple_match'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/sinatra'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'support'
2
3
  require 'mustermann/to_pattern'
3
4
  require 'delegate'
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.beta2
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: 2016-08-22 00:00:00.000000000 Z
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: konstantin.mailinglists@googlemail.com
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/rkh/mustermann
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: 1.3.1
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: