Sha256: 3f3ac057f4d910134387021a511db21891d98fd6a1151657b071f3f270f24302

Contents?: true

Size: 1.18 KB

Versions: 15

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module LittleWeasel
  module Filters
    # This module validates word filter types.
    module WordFilterValidatable
      def self.validate(word_filter:)
        raise ArgumentError, "Argument word_filter does not quack right: #{word_filter.class}" \
          unless valid_word_filter?(word_filter: word_filter)
      end

      # You can use your own word filter types as long as they quack correctly;
      # however, you are responsible for the behavior of these required methods/
      # attributes. It's probably better to follow the pattern of existing word
      # filter objects (e.g. Filters::EnUs::NumericFilter) and inherit from
      # Filters::WordFilter.
      def self.valid_word_filter?(word_filter:)
        word_filter.respond_to?(:filter_on?) &&
          word_filter.respond_to?(:filter_off?) &&
          word_filter.respond_to?(:filter_on) &&
          word_filter.respond_to?(:filter_on=) &&
          word_filter.respond_to?(:filter_match?) &&
          word_filter.class.respond_to?(:filter_match?)
      end

      def validate_word_filter(word_filter:)
        WordFilterValidatable.validate word_filter: word_filter
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
LittleWeasel-5.0.13 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.12 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.11 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.10 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.9 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.8 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.7 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.6 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.5 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.4 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.3 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.2 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.1 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-5.0.0 lib/LittleWeasel/filters/word_filter_validatable.rb
LittleWeasel-4.0.0 lib/LittleWeasel/filters/word_filter_validatable.rb