mustermann 1.0.3 → 1.1.2

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
- SHA1:
3
- metadata.gz: 0f9565d31c5b29a990840eb04f933be370358de6
4
- data.tar.gz: 5f4dc020bd50b6d11f787dc555e0fcab6252d486
2
+ SHA256:
3
+ metadata.gz: 66586a7576074e21ef117955d2af89012bbe08d48a36ac85c42574d671350292
4
+ data.tar.gz: e08f66d8a4d5b33760fe0ee3c328ef6aa016207f1f248e64a79742c344d98195
5
5
  SHA512:
6
- metadata.gz: 7bf3d61ccac65e24d83b5551188ae5d9836b7664dad722fd077264d9b1b6e3097bc57b474c09acc3b250c009bd7852378b3049ee5630c28706335111ec651e60
7
- data.tar.gz: b4ab4965dd93dae14ddf44c60116711a488ead67e0bf1109582c79ed86bf81c70315c1b9b4b6258978093515f4813e8f01d0aeca302de883289d65ccbcf5e870
6
+ metadata.gz: f82b3641946356fad899d72b3ad3bdfde241030fbc25829f2e1e5a3b3f7da8cc642147d2e9021cb6bb7f88a2268360983b6cab1e07423115c3f3281282066777
7
+ data.tar.gz: eb6bcb7b642b03d83c3c463d72f8997755af3919dbcd2a2df212ee95c3b5cb51dc6fa0bf2cb5e5539a2ad1aa47d26c905f87d3ffcc15a925c48dcd8cf664d5a9
@@ -40,7 +40,7 @@ module Mustermann
40
40
 
41
41
  # @!visibility private
42
42
  def translate(**options)
43
- return pattern(options) if options[:no_captures]
43
+ return pattern(**options) if options[:no_captures]
44
44
  "(?<#{name}>#{translate(no_captures: true, **options)})"
45
45
  end
46
46
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'mustermann/ast/translator'
3
3
  require 'mustermann/ast/compiler'
4
+ require 'ruby2_keywords'
4
5
 
5
6
  module Mustermann
6
7
  module AST
@@ -92,11 +93,11 @@ module Mustermann
92
93
  # @see Mustermann::Pattern#expand
93
94
  # @!visibility private
94
95
  def expand(values)
95
- values = values.each_with_object({}){ |(key, value), new_hash|
96
+ adjusted = values.each_with_object({}){ |(key, value), new_hash|
96
97
  new_hash[value.instance_of?(Array) ? [key] * value.length : key] = value }
97
- keys, pattern, filters = mappings.fetch(values.keys.flatten.sort) { error_for(values) }
98
- filters.each { |key, filter| values[key] &&= escape(values[key], also_escape: filter) }
99
- pattern % (values[keys] || values.values_at(*keys))
98
+ keys, pattern, filters = mappings.fetch(adjusted.keys.flatten.sort) { error_for(values) }
99
+ filters.each { |key, filter| adjusted[key] &&= escape(adjusted[key], also_escape: filter) }
100
+ pattern % (adjusted[keys] || adjusted.values_at(*keys))
100
101
  end
101
102
 
102
103
  # @see Mustermann::Pattern#expandable?
@@ -122,7 +123,7 @@ module Mustermann
122
123
 
123
124
  # @see Mustermann::AST::Translator#expand
124
125
  # @!visibility private
125
- def escape(string, *args)
126
+ ruby2_keywords def escape(string, *args)
126
127
  # URI::Parser is pretty slow, let's not send every string to it, even if it's unnecessary
127
128
  string =~ /\A\w*\Z/ ? string : super
128
129
  end
@@ -137,7 +138,7 @@ module Mustermann
137
138
  # @!visibility private
138
139
  def add_to(list, result)
139
140
  list << [[], ""] if list.empty?
140
- list.inject([]) { |l, (k1, p1, f1)| l + result.map { |k2, p2, f2| [k1+k2, p1+p2, **f1, **f2] } }
141
+ list.inject([]) { |l, (k1, p1, f1)| l + result.map { |k2, p2, f2| [k1+k2, p1+p2, f1.merge(f2)] } }
141
142
  end
142
143
  end
143
144
  end
@@ -108,7 +108,7 @@ module Mustermann
108
108
  # @see Mustermann::AST::Node#parse
109
109
  # @!visibility private
110
110
  def parse
111
- self.payload ||= ""
111
+ self.payload ||= String.new
112
112
  super
113
113
  end
114
114
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'mustermann/ast/node'
3
3
  require 'forwardable'
4
+ require 'ruby2_keywords'
4
5
  require 'strscan'
5
6
 
6
7
  module Mustermann
@@ -64,7 +65,7 @@ module Mustermann
64
65
  # @param [Symbol] type node type
65
66
  # @return [Mustermann::AST::Node]
66
67
  # @!visibility private
67
- def node(type, *args, &block)
68
+ ruby2_keywords def node(type, *args, &block)
68
69
  type = Node[type] unless type.respond_to? :new
69
70
  start = pos
70
71
  node = block ? type.parse(*args, &block) : type.new(*args)
@@ -153,7 +154,7 @@ module Mustermann
153
154
  def read_brackets(open, close, char: nil, escape: ?\\, quote: false, **options)
154
155
  result = String.new
155
156
  escape = false if escape.nil?
156
- while current = getch
157
+ while (current = getch)
157
158
  case current
158
159
  when close then return result
159
160
  when open then result << open << read_brackets(open, close) << close
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'mustermann/ast/node'
3
3
  require 'mustermann/error'
4
+ require 'ruby2_keywords'
4
5
  require 'delegate'
5
6
 
6
7
  module Mustermann
@@ -36,7 +37,7 @@ module Mustermann
36
37
 
37
38
  # shorthand for translating a nested object
38
39
  # @!visibility private
39
- def t(*args, &block)
40
+ ruby2_keywords def t(*args, &block)
40
41
  return translator unless args.any?
41
42
  translator.translate(*args, &block)
42
43
  end
@@ -109,7 +110,7 @@ module Mustermann
109
110
 
110
111
  # Start the translation dance for a (sub)tree.
111
112
  # @!visibility private
112
- def translate(node, *args, &block)
113
+ ruby2_keywords def translate(node, *args, &block)
113
114
  result = decorator_for(node).translate(*args, &block)
114
115
  result = result.node while result.is_a? NodeTranslator
115
116
  result
@@ -119,7 +120,7 @@ module Mustermann
119
120
  # @!visibility private
120
121
  def escape(char, parser: URI::DEFAULT_PARSER, escape: parser.regexp[:UNSAFE], also_escape: nil)
121
122
  escape = Regexp.union(also_escape, escape) if also_escape
122
- char =~ escape ? parser.escape(char, Regexp.union(*escape)) : char
123
+ char.to_s =~ escape ? parser.escape(char, Regexp.union(*escape)) : char
123
124
  end
124
125
  end
125
126
  end
@@ -102,9 +102,9 @@ module Mustermann
102
102
  end
103
103
 
104
104
  # @!visibility private
105
- def patterns_from(pattern, options = nil)
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) : pattern]
107
+ [options.empty? && pattern.is_a?(Pattern) ? pattern : Mustermann.new(pattern, **options)]
108
108
  end
109
109
 
110
110
  private :with_matching, :patterns_from
@@ -40,7 +40,7 @@ module Mustermann
40
40
 
41
41
  # Should not be used directly.
42
42
  # @!visibility private
43
- def initialize(*)
43
+ def initialize(*, **)
44
44
  super
45
45
  AST::Validation.validate(combined_ast) if respond_to? :expand
46
46
  end
@@ -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
@@ -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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Mustermann
3
- VERSION ||= '1.0.3'
3
+ VERSION ||= '1.1.2'
4
4
  end
data/lib/mustermann.rb CHANGED
@@ -75,8 +75,8 @@ module Mustermann
75
75
  end
76
76
  end
77
77
 
78
- @mutex ||= Mutex.new
79
- @types ||= {}
78
+ @mutex = Mutex.new
79
+ @types = {}
80
80
 
81
81
  # Maps a type to its factory.
82
82
  #
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
@@ -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, "/foo" => "/bar") }
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,16 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mustermann
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
8
8
  - Zachary Scott
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-16 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2022-07-17 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: []
@@ -76,7 +90,7 @@ homepage: https://github.com/sinatra/mustermann
76
90
  licenses:
77
91
  - MIT
78
92
  metadata: {}
79
- post_install_message:
93
+ post_install_message:
80
94
  rdoc_options: []
81
95
  require_paths:
82
96
  - lib
@@ -91,9 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
105
  - !ruby/object:Gem::Version
92
106
  version: '0'
93
107
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.8
96
- signing_key:
108
+ rubygems_version: 3.2.3
109
+ signing_key:
97
110
  specification_version: 4
98
111
  summary: Your personal string matching expert.
99
112
  test_files: