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