Sha256: 57e77a3aa5accee927bb69fea63a5b6012aa2c46418fa6acd4c7790f744a554b

Contents?: true

Size: 878 Bytes

Versions: 14

Compression:

Stored size: 878 Bytes

Contents

module Godmin
  module Resource
    module Filters
      extend ActiveSupport::Concern

      included do
        helper_method :filter_map
      end

      def filter_map
        self.class.filter_map
      end

      def apply_filters(resources)
        if params[:filter].present?
          params[:filter].each do |name, value|
            if filter_map.key?(name.to_sym) && value.present?
              resources = send("filter_#{name}", resources, value)
            end
          end
        end
        resources
      end

      module ClassMethods
        def filter_map
          @filter_map ||= {}
        end

        def filter(attr, options = {})
          filter_map[attr] = {
            as: :string,
            option_text: "to_s",
            option_value: "id",
            collection: nil
          }.merge(options)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
godmin-0.10.3 lib/godmin/resource/filters.rb
godmin-0.10.2 lib/godmin/resource/filters.rb
godmin-0.10.1 lib/godmin/resource/filters.rb
godmin-0.10.0 lib/godmin/resource/filters.rb
godmin-0.9.9 lib/godmin/resource/filters.rb
godmin-0.9.8 lib/godmin/resource/filters.rb
godmin-0.9.7 lib/godmin/resource/filters.rb
godmin-0.9.6 lib/godmin/resource/filters.rb
godmin-0.9.5 lib/godmin/resource/filters.rb
godmin-0.9.4 lib/godmin/resource/filters.rb
godmin-0.9.3 lib/godmin/resource/filters.rb
godmin-0.9.2 lib/godmin/resource/filters.rb
godmin-0.9.1 lib/godmin/resource/filters.rb
godmin-0.9.0 lib/godmin/resource/filters.rb