Sha256: a430d33e09f83975e78f895d2c8453b14f1028b415153ddbd8d9e76ce640f710

Contents?: true

Size: 1.55 KB

Versions: 22

Compression:

Stored size: 1.55 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The Integer_matcher_max plugin sets the maximum integer value
    # value that the Integer class matcher will match by default.
    # By default, loading this plugin sets the maximum value to
    # 2**63-1, the largest signed 64-bit integer value:
    #
    #   plugin :Integer_matcher_max
    #   route do |r|
    #     r.is Integer do
    #       # Matches /9223372036854775807
    #       # Does not match /9223372036854775808
    #     end
    #   end
    #
    # To specify a different maximum value, you can pass a different
    # maximum value when loading the plugin:
    # 
    #   plugin :Integer_matcher_max, 2**64-1
    module IntegerMatcherMax
      def self.configure(app, max=nil)
        if max
          app::RodaRequest.class_eval do
            define_method(:_match_class_max_Integer){max}
            alias_method :_match_class_max_Integer, :_match_class_max_Integer
            private :_match_class_max_Integer
          end
        end
      end

      module RequestMethods
        private

        # Do not have the Integer matcher max when over the maximum
        # configured Integer value.
        def _match_class_convert_Integer(value)
          value = super
          value if value <= _match_class_max_Integer
        end

        # Use 2**63-1 as the default maximum value for the Integer
        # matcher.
        def _match_class_max_Integer
          9223372036854775807
        end
      end
    end

    register_plugin(:Integer_matcher_max, IntegerMatcherMax)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
roda-3.84.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.83.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.82.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.81.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.79.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.78.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.77.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.76.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.75.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.74.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.73.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.72.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.71.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.70.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.69.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.68.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.67.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.66.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.65.0 lib/roda/plugins/Integer_matcher_max.rb
roda-3.64.0 lib/roda/plugins/Integer_matcher_max.rb