Class: Mustermann::Sinatra
- Inherits:
-
AST::Pattern
- Object
- Pattern
- RegexpBased
- AST::Pattern
- Mustermann::Sinatra
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/parser.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/try_convert.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/safe_renderer.rb
Overview
Sinatra 2.0 style pattern implementation.
Constant Summary
Constants included from Mustermann
CompileError, DEFAULT_TYPE, Error, ExpandError, ParseError
Instance Attribute Summary
Attributes inherited from RegexpBased
Attributes inherited from Pattern
Class Method Summary collapse
-
.escape(string) ⇒ String
Takes a string and espaces any characters that have special meaning for Sinatra patterns.
Instance Method Summary collapse
-
#safe_string ⇒ String
Generates a string represenation of the pattern that can safely be used for def interpolation without changing its semantics.
-
#|(other) ⇒ Mustermann::Pattern
Creates a pattern that matches any string matching either one of the patterns.
Methods inherited from AST::Pattern
Methods inherited from RegexpBased
#initialize, #peek_match, #peek_size
Methods inherited from Pattern
#+, #==, #===, #=~, #eql?, #expand, #hash, #initialize, #match, #named_captures, #names, new, #params, #peek, #peek_match, #peek_params, #peek_size, supported?, supported_options, #to_proc, #to_s, #to_templates
Methods included from Mustermann
Constructor Details
This class inherits a constructor from Mustermann::RegexpBased
Class Method Details
.escape(string) ⇒ String
Takes a string and espaces any characters that have special meaning for Sinatra patterns.
29 30 31 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra.rb', line 29 def self.escape(string) string.to_s.gsub(/[\?\(\)\*:\\\|\{\}]/) { |c| "\\#{c}" } end |
Instance Method Details
#safe_string ⇒ String
Generates a string represenation of the pattern that can safely be used for def interpolation without changing its semantics.
76 77 78 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra.rb', line 76 def safe_string @safe_string ||= SafeRenderer.translate(to_ast) end |
#|(other) ⇒ Mustermann::Pattern
Creates a pattern that matches any string matching either one of the patterns. If a string is supplied, it is treated as a fully escaped Sinatra pattern.
If the other pattern is also a Sintara pattern, it might join the two to a third sinatra pattern instead of generating a composite for efficiency reasons.
This only happens if the sinatra pattern behaves exactly the same as a composite would in regards to matching, parsing, expanding and template generation.
59 60 61 62 63 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra.rb', line 59 def |(other) return super unless converted = self.class.try_convert(other, **) return super unless converted.names.empty? or names.empty? self.class.new(safe_string + "|" + converted.safe_string, **) end |