Sha256: 6b83a52448fef564af1e9c0b4a0b2d280e8b85396efc88f796199150c05b80ae

Contents?: true

Size: 821 Bytes

Versions: 2

Compression:

Stored size: 821 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.const_get("#{object.model_name}#{SUFFIX}")
        elsif object.respond_to?(:model)
          if object.model.respond_to?(:filter_class)
            object.model.filter_class
          else
            Object.const_get("#{object.model}#{SUFFIX}")
          end
        else
          Object.const_get("#{object}#{SUFFIX}")
        end
      rescue NameError
        raise Error, "unable to find appropriate filter class for #{object}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tiny_filter-0.3.1 lib/tiny_filter/filter_finder.rb
tiny_filter-0.3.0 lib/tiny_filter/filter_finder.rb