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

Version Path
mustermann-3.0.3 lib/mustermann/sinatra/try_convert.rb
mustermann-3.0.2 lib/mustermann/sinatra/try_convert.rb
mustermann-3.0.1 lib/mustermann/sinatra/try_convert.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/try_convert.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/try_convert.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/try_convert.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/mustermann-3.0.0/lib/mustermann/sinatra/try_convert.rb
mustermann-3.0.0 lib/mustermann/sinatra/try_convert.rb
mustermann-2.0.2 lib/mustermann/sinatra/try_convert.rb
mustermann-2.0.1 lib/mustermann/sinatra/try_convert.rb
mustermann-2.0.0 lib/mustermann/sinatra/try_convert.rb
mustermann-1.1.2 lib/mustermann/sinatra/try_convert.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/mustermann-1.1.1/lib/mustermann/sinatra/try_convert.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/mustermann-1.1.1/lib/mustermann/sinatra/try_convert.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/mustermann-1.1.1/lib/mustermann/sinatra/try_convert.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/mustermann-1.0.3/lib/mustermann/sinatra/try_convert.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/mustermann-1.1.1/lib/mustermann/sinatra/try_convert.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/mustermann-1.0.3/lib/mustermann/sinatra/try_convert.rb
mustermann-1.1.1 lib/mustermann/sinatra/try_convert.rb
mustermann-1.1.0 lib/mustermann/sinatra/try_convert.rb