mustermann 1.0.3 → 1.1.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.
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: f6e92bdd2542114b33a9f209cf71fdbe0b876b35abe09c1bb7309b640304e105
4
+ data.tar.gz: 8146636bb8dba303e828db1379302d3623912670c7cbf4238a24e4b6d766ff70
5
5
  SHA512:
6
- metadata.gz: 7bf3d61ccac65e24d83b5551188ae5d9836b7664dad722fd077264d9b1b6e3097bc57b474c09acc3b250c009bd7852378b3049ee5630c28706335111ec651e60
7
- data.tar.gz: b4ab4965dd93dae14ddf44c60116711a488ead67e0bf1109582c79ed86bf81c70315c1b9b4b6258978093515f4813e8f01d0aeca302de883289d65ccbcf5e870
6
+ metadata.gz: 5982de41f3bdfa52e627f73a7c54dd4292681cf65acda63306dff7835a4f05126681ff6a0a1912448713d6f9103e55df4c5470368b9724040eb99cdf9190e07e
7
+ data.tar.gz: 6a8755d02a86521d0d3e1c68496a54b33ab5c88da85ec920d63b072647f861de36ee156a8b1524ea628b06a3439d940da4570031306763db589ed773b3eff088
@@ -3,6 +3,7 @@ require 'mustermann/pattern'
3
3
  require 'mustermann/composite'
4
4
  require 'mustermann/concat'
5
5
  require 'thread'
6
+ require 'ruby2_keywords'
6
7
 
7
8
  # Namespace and main entry point for the Mustermann library.
8
9
  #
@@ -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
 
@@ -92,11 +92,11 @@ module Mustermann
92
92
  # @see Mustermann::Pattern#expand
93
93
  # @!visibility private
94
94
  def expand(values)
95
- values = values.each_with_object({}){ |(key, value), new_hash|
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(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))
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, **f1, **f2] } }
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
@@ -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.0'
4
4
  end
@@ -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
@@ -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,7 +1,7 @@
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.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: 2018-08-16 00:00:00.000000000 Z
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
- rubyforge_project:
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.