Sha256: 537a9f522a00bd562e0c81362d7cb0317a7bf7c2f8abe8171ddbd9903f34dc00

Contents?: true

Size: 530 Bytes

Versions: 2

Compression:

Stored size: 530 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.1.1 lib/tiny_filter/filter_finder.rb
tiny_filter-0.1.0 lib/tiny_filter/filter_finder.rb