Sha256: 1949683abacf9b0b6c0c92f718a45c5d2b78a82538a6681deb92d0c57e25d160

Contents?: true

Size: 527 Bytes

Versions: 2

Compression:

Stored size: 527 Bytes

Contents

# frozen_string_literal: true

module TinyFilter
  class FilterFinder
    SUFFIX = "Filter"

    class << self
      def find(object)
        filter_class(object)
      end

      private

      def filter_class(object)
        if object.respond_to?(:filter_class)
          object.filter_class
        elsif object.respond_to?(:model_name)
          "#{object.model_name}#{SUFFIX}".constantize
        else
          raise Error, "unable to find appropriate filter class for #{object}"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tiny_filter-0.2.1 lib/tiny_filter/filter_finder.rb
tiny_filter-0.2.0 lib/tiny_filter/filter_finder.rb