module Alchemy::SearchableResource

Defines the methods that are needed to make a model searchable in Alchemy’s admin search by Ransack.

Constants

SEARCHABLE_COLUMN_TYPES

Public Instance Methods

ransackable_associations(_auth_object = nil) click to toggle source

Allow all associations defined in alchemy_resource_relations to be searchable by Ransack.

# File lib/alchemy/searchable_resource.rb, line 20
def ransackable_associations(_auth_object = nil)
  searchable_alchemy_resource_associations
end
ransackable_attributes(_auth_object = nil) click to toggle source

Allow all string and text attributes to be searchable by Ransack.

# File lib/alchemy/searchable_resource.rb, line 10
def ransackable_attributes(_auth_object = nil)
  searchable_alchemy_resource_attributes
end
ransortable_attributes(_auth_object = nil) click to toggle source

Allow all attributes to be sortable by Ransack.

# File lib/alchemy/searchable_resource.rb, line 15
def ransortable_attributes(_auth_object = nil)
  columns.map(&:name)
end

Protected Instance Methods

searchable_alchemy_resource_associations() click to toggle source
# File lib/alchemy/searchable_resource.rb, line 30
def searchable_alchemy_resource_associations
  if respond_to?(:alchemy_resource_relations)
    alchemy_resource_relations.keys.map!(&:to_s)
  else
    []
  end
end
searchable_alchemy_resource_attributes() click to toggle source
# File lib/alchemy/searchable_resource.rb, line 26
def searchable_alchemy_resource_attributes
  columns.select { |c| c.type.in?(SEARCHABLE_COLUMN_TYPES) }.map(&:name)
end