Sha256: 921b41217b86205a6923dbb3858271ba853460a0137977fa38e378d2a438bc51

Contents?: true

Size: 709 Bytes

Versions: 3

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true

module Rubanok
  module DSL
    # Adds `.map` method to Plane to define key-matching rules:
    #
    #   map :q do |q:|
    #    # this rule is activated iff "q" (or :q) param is present
    #    # the value is passed to the handler
    #   end
    module Mapping
      class Rule < Rubanok::Rule
        METHOD_PREFIX = "__map"

        private

        # prefix rule method name to avoid collisions
        def build_method_name
          "#{METHOD_PREFIX}#{super}"
        end
      end

      def map(*fields, **options, &block)
        rule = Rule.new(fields, options)

        define_method(rule.to_method_name, &block)

        rules << rule
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubanok-0.1.3 lib/rubanok/dsl/mapping.rb
rubanok-0.1.1 lib/rubanok/dsl/mapping.rb
rubanok-0.1.0 lib/rubanok/dsl/mapping.rb