lib/rubanok/dsl/mapping.rb in rubanok-0.1.3 vs lib/rubanok/dsl/mapping.rb in rubanok-0.2.0

- old
+ new

@@ -1,10 +1,10 @@ # frozen_string_literal: true module Rubanok module DSL - # Adds `.map` method to Plane to define key-matching rules: + # Adds `.map` method to Processor 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 @@ -18,15 +18,21 @@ def build_method_name "#{METHOD_PREFIX}#{super}" end end - def map(*fields, **options, &block) - rule = Rule.new(fields, options) + module ClassMethods + def map(*fields, **options, &block) + rule = Rule.new(fields, options) - define_method(rule.to_method_name, &block) + define_method(rule.to_method_name, &block) - rules << rule + add_rule rule + end + end + + def self.included(base) + base.extend ClassMethods end end end end