mustermann 3.1.0 → 3.1.1

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
2
  SHA256:
3
- metadata.gz: e0b15c2c5c75d712dde03df8b83d4f0b646455aa892eb59365f1b09ce01bfa7c
4
- data.tar.gz: 358ce50be0eb8638e47ea8bb3cd65512f57e10eb65b93600098145214a2f6d39
3
+ metadata.gz: b56ff4d495f7e79eb6deff2145be811154fa646813a21af4de4f21de27666bb1
4
+ data.tar.gz: fc15e2c23029429dbcf0fe0ba17d4189304edd60d50e9f010312fa1d198ebbbf
5
5
  SHA512:
6
- metadata.gz: 3360ad1465989d2179b97d67c64261d7a68cf22ca1cea2a02f2450bd5b0894948efd4d99581b7d7609dc7698d4ed0595d85613b67d79dce3ce79b84d08e614ff
7
- data.tar.gz: 8c32fae7ff72697598dacf54c1ddae95ea80a48814fa887c61d91e18bca6a0a1c79768a981fba0cd4d60d986db76c0961a3f6dae5c5a7a8b8276978428fb105e
6
+ metadata.gz: fa699c65cb5921435ed6e8f210bbf07110e8babedc5aa71efb0f012eb094cf4d6f530511e1bc08ff54b324a4fd5608078fa01bffd23846a6dee7f65cd40c6793
7
+ data.tar.gz: a0a8c22f1d075e3c980830fa2c3e16f56b2b19cb333f625c27f2c6160b9e8fe83b0bdb3fb16f1f8682d9683f73884ed589a2f07ff38a522634065b859e2dbc2b
data/README.md CHANGED
@@ -311,7 +311,7 @@ require 'mustermann'
311
311
 
312
312
  Mustermann.new("/:name").to_templates # => ["/{name}"]
313
313
  Mustermann.new("/:foo(@:bar)?/*baz").to_templates # => ["/{foo}@{bar}/{+baz}", "/{foo}/{+baz}"]
314
- Mustermann.new("/{name}", type: :template).to_templates # => ["/{name}"
314
+ Mustermann.new("/{name}", type: :template).to_templates # => ["/{name}"]
315
315
  ```
316
316
 
317
317
  Union Composite patterns (with the | operator) support template generation if all patterns they are composed of also support it.
@@ -828,3 +828,115 @@ Using anchors will break [peeking](#-peeking) and [concatenation](#-concatenatio
828
828
  </tr>
829
829
  </tbody>
830
830
  </table>
831
+
832
+ <a name="-rails-pattern"></a>
833
+ ### `rails`
834
+
835
+ Mustermann also implements the `rails` pattern. It is compatible with [Ruby on Rails](http://rubyonrails.org/), [Journey](https://github.com/rails/journey), the [http_router gem](https://github.com/joshbuddy/http_router), [Lotus](http://lotusrb.org/) and [Scalatra](http://scalatra.org/) (if [configured](http://scalatra.org/2.3/guides/http/routes.html#toc_248))</td>
836
+
837
+ **Supported options:**
838
+ [`capture`](#-available-options--capture),
839
+ [`except`](#-available-options--except),
840
+ [`greedy`](#-available-options--greedy),
841
+ [`space_matches_plus`](#-available-options--space_matches_plus),
842
+ [`uri_decode`](#-available-options--uri_decode),
843
+ [`version`](#-rails-pattern--version),
844
+ [`ignore_unknown_options`](#-available-options--ignore_unknown_options).
845
+
846
+ **External documentation:**
847
+ [Ruby on Rails Guides: Routing](http://guides.rubyonrails.org/routing.html).
848
+
849
+ ``` ruby
850
+ require 'mustermann'
851
+
852
+ pattern = Mustermann.new('/:example', type: :rails)
853
+ pattern === "/foo.bar" # => true
854
+ pattern === "/foo/bar" # => false
855
+ pattern.params("/foo.bar") # => { "example" => "foo.bar" }
856
+ pattern.params("/foo/bar") # => nil
857
+
858
+ pattern = Mustermann.new('/:example(/:optional)', type: :rails)
859
+ pattern === "/foo.bar" # => true
860
+ pattern === "/foo/bar" # => true
861
+ pattern.params("/foo.bar") # => { "example" => "foo.bar", "optional" => nil }
862
+ pattern.params("/foo/bar") # => { "example" => "foo", "optional" => "bar" }
863
+
864
+ pattern = Mustermann.new('/*example', type: :rails)
865
+ pattern === "/foo.bar" # => true
866
+ pattern === "/foo/bar" # => true
867
+ pattern.params("/foo.bar") # => { "example" => "foo.bar" }
868
+ pattern.params("/foo/bar") # => { "example" => "foo/bar" }
869
+ ```
870
+
871
+ <a name="-rails-pattern--version"></a>
872
+ #### `version`
873
+
874
+ Rails syntax changed over time. You can target different Ruby on Rails versions by setting the `version` option to the desired Rails version.
875
+
876
+ The default is `5.0`. Versions prior to `2.3` are not supported.
877
+
878
+ ``` ruby
879
+ require 'mustermann'
880
+ Mustermann.new('/', type: :rails, version: "2.3")
881
+ Mustermann.new('/', type: :rails, version: "3.0.0")
882
+
883
+ require 'rails'
884
+ Mustermann.new('/', type: :rails, version: Rails::VERSION::STRING)
885
+ ```
886
+
887
+ #### Syntax
888
+
889
+
890
+ <table>
891
+ <thead>
892
+ <tr>
893
+ <th>Syntax Element</th>
894
+ <th>Description</th>
895
+ </tr>
896
+ </thead>
897
+ <tbody>
898
+ <tr>
899
+ <td><b>:</b><i>name</i></td>
900
+ <td>
901
+ Captures anything but a forward slash in a semi-greedy fashion. Capture is named <i>name</i>.
902
+ Capture behavior can be modified with <tt>capture</tt> and <tt>greedy</tt> option.
903
+ </td>
904
+ </tr>
905
+ <tr>
906
+ <td><b>*</b><i>name</i></td>
907
+ <td>
908
+ Captures anything in a non-greedy fashion. Capture is named <i>name</i>.
909
+ </td>
910
+ </tr>
911
+ <tr>
912
+ <td><b>(</b><i>expression</i><b>)</b></td>
913
+ <td>Enclosed <i>expression</i> is optional. Not available in 2.3 compatibility mode.</td>
914
+ </tr>
915
+ <tr>
916
+ <td><b>/</b></td>
917
+ <td>
918
+ Matches forward slash. Does not match URI encoded version of forward slash.
919
+ </td>
920
+ </tr>
921
+ <tr>
922
+ <td><b>\</b><i>x</i></td>
923
+ <td>
924
+ In 3.x compatibility mode and starting with 4.2:
925
+ Matches <i>x</i> or URI encoded version of <i>x</i>. For instance <tt>\*</tt> matches <tt>*</tt>.<br>
926
+ In 4.0 or 4.1 compatibility mode:
927
+ <b>\</b> is ignored, <i>x</i> is parsed normally.<br>
928
+ </td>
929
+ </tr>
930
+ <tr>
931
+ <td><i>expression</i> <b>|</b> <i>expression</i></td>
932
+ <td>
933
+ 3.2+ mode: This will raise a `Mustermann::ParseError`. While Ruby on Rails happily parses this character, it will result in broken routes due to a buggy implementation.<br>
934
+ 5.0 mode: It will match if any of the nested expressions matches.
935
+ </td>
936
+ </tr>
937
+ <tr>
938
+ <td><i>any other character</i></td>
939
+ <td>Matches exactly that character or a URI encoded version of it.</td>
940
+ </tr>
941
+ </tbody>
942
+ </table>
@@ -110,7 +110,7 @@ module Mustermann
110
110
  # Used by Ruby internally for hashing.
111
111
  # @return [Integer] same has value for patterns that are equal
112
112
  def hash
113
- self.class.hash | @string.hash | options.hash
113
+ self.class.hash ^ @string.hash ^ options.hash
114
114
  end
115
115
 
116
116
  # Two patterns are considered equal if they are of the same type, have the same pattern string
@@ -2,7 +2,7 @@
2
2
  module Mustermann
3
3
  class Sinatra < AST::Pattern
4
4
  # Generates a string that can safely be concatenated with other strings
5
- # without chaning its semantics
5
+ # without changing its semantics
6
6
  # @see #safe_string
7
7
  # @!visibility private
8
8
  SafeRenderer = AST::Translator.create do
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Mustermann
3
- VERSION ||= '3.1.0'
3
+ VERSION ||= '3.1.1'
4
4
  end
data/lib/mustermann.rb CHANGED
@@ -122,12 +122,3 @@ module Mustermann
122
122
  require 'mustermann/extension'
123
123
  end
124
124
  end
125
-
126
- # :nocov:
127
- begin
128
- require 'mustermann/visualizer' if defined?(Pry) or defined?(IRB)
129
- rescue LoadError => error
130
- raise error unless error.path == 'mustermann/visualizer'
131
- $stderr.puts(error.message) if caller_locations[1].absolute_path =~ %r{/lib/pry/|/irb/|^\((?:irb|pry)\)$}
132
- end
133
- # :nocov:
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: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase