module Rubanok::DSL::Matching

Adds `.match` method to Processor class to define key-value-matching rules:

match :sort, :sort_by do |sort:, sort_by:|
  # this rule is activated iff both "sort" and "sort_by" params are present
  # the values are passed to the matcher
  #
  # then we match against values
  having "name" do |sort_by:|
    raw.joins(:user).order("users.name #{sort_by}")
  end
end

Public Class Methods

included(base) click to toggle source
# File lib/rubanok/dsl/matching.rb, line 95
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

default_match_handler(rule, params, fail_when_no_matches) click to toggle source
# File lib/rubanok/dsl/matching.rb, line 99
      def default_match_handler(rule, params, fail_when_no_matches)
        fail_when_no_matches = Rubanok.fail_when_no_matches if fail_when_no_matches.nil?
        return raw unless fail_when_no_matches

        raise ::Rubanok::UnexpectedInputError, <<~MSG
          Unexpected input: #{params.slice(*rule.fields)}.
          Available values are:
            #{rule.clauses.map(&:values).join("\n  ")}
        MSG
      end