Sha256: a6d0f718909c3535b0e2d2d0d16143f5b7d73437cb40c6ef2f79be7711d1f086
Contents?: true
Size: 1.4 KB
Versions: 27
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true module Mustermann class Sinatra < AST::Pattern # Tries to translate objects to Sinatra patterns. # @!visibility private class TryConvert < AST::Translator # @return [Mustermann::Sinatra, nil] # @!visibility private def self.convert(input, **options) new(options).translate(input) end # Expected options for the resulting pattern. # @!visibility private attr_reader :options # @!visibility private def initialize(options) @options = options end # @return [Mustermann::Sinatra] # @!visibility private def new(input, escape = false) input = Mustermann::Sinatra.escape(input) if escape Mustermann::Sinatra.new(input, **options) end # @return [true, false] whether or not expected pattern should have uri_decode option set # @!visibility private def uri_decode options.fetch(:uri_decode, true) end translate(Object) { nil } translate(String) { t.new(self, true) } translate(Identity) { t.new(self, true) if uri_decode == t.uri_decode } translate(Sinatra) { node if options == t.options } translate AST::Pattern do next unless options == t.options t.new(SafeRenderer.translate(to_ast)) rescue nil end end private_constant :TryConvert end end
Version data entries
27 entries across 24 versions & 5 rubygems