Sha256: 038e4365f56af0d2f3b4a6a56ea008b859f9f6defb111335b30c46331b1e74a1

Contents?: true

Size: 1.08 KB

Versions: 48

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Alchemy
  # Defines the methods that are needed to
  # make a model searchable in Alchemy's admin search by Ransack.
  module SearchableResource
    SEARCHABLE_COLUMN_TYPES = %i[string text]

    # Allow all string and text attributes to be searchable by Ransack.
    def ransackable_attributes(_auth_object = nil)
      searchable_alchemy_resource_attributes
    end

    # Allow all attributes to be sortable by Ransack.
    def ransortable_attributes(_auth_object = nil)
      columns.map(&:name)
    end

    # Allow all associations defined in +alchemy_resource_relations+ to be searchable by Ransack.
    def ransackable_associations(_auth_object = nil)
      searchable_alchemy_resource_associations
    end

    protected

    def searchable_alchemy_resource_attributes
      columns.select { |c| c.type.in?(SEARCHABLE_COLUMN_TYPES) }.map(&:name)
    end

    def searchable_alchemy_resource_associations
      if respond_to?(:alchemy_resource_relations)
        alchemy_resource_relations.keys.map!(&:to_s)
      else
        []
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 lib/alchemy/searchable_resource.rb
alchemy_cms-7.3.3 lib/alchemy/searchable_resource.rb
alchemy_cms-7.3.2 lib/alchemy/searchable_resource.rb
alchemy_cms-7.2.7 lib/alchemy/searchable_resource.rb
alchemy_cms-7.3.1 lib/alchemy/searchable_resource.rb
alchemy_cms-7.3.0 lib/alchemy/searchable_resource.rb
alchemy_cms-7.2.6 lib/alchemy/searchable_resource.rb
alchemy_cms-7.2.5 lib/alchemy/searchable_resource.rb
alchemy_cms-7.1.12 lib/alchemy/searchable_resource.rb
alchemy_cms-7.0.15 lib/alchemy/searchable_resource.rb
alchemy_cms-7.2.4 lib/alchemy/searchable_resource.rb
alchemy_cms-7.1.11 lib/alchemy/searchable_resource.rb
alchemy_cms-7.2.3 lib/alchemy/searchable_resource.rb
alchemy_cms-7.1.10 lib/alchemy/searchable_resource.rb
alchemy_cms-7.2.2 lib/alchemy/searchable_resource.rb
alchemy_cms-7.1.9 lib/alchemy/searchable_resource.rb
alchemy_cms-7.0.14 lib/alchemy/searchable_resource.rb
alchemy_cms-7.2.1 lib/alchemy/searchable_resource.rb
alchemy_cms-7.0.13 lib/alchemy/searchable_resource.rb
alchemy_cms-7.1.8 lib/alchemy/searchable_resource.rb