module ActsAsExplorable::Explorable

Public Class Methods

explorable?() click to toggle source
# File lib/acts_as_explorable/explorable.rb, line 5
def self.explorable?
  false
end
extended(base) click to toggle source
# File lib/acts_as_explorable/explorable.rb, line 3
def self.extended(base)
  base.class_eval do
    def self.explorable?
      false
    end
  end
end

Public Instance Methods

explorable(filters = {}) { |config| ... } click to toggle source

Configure ActsAsExplorable’s behavior in a model.

The plugin can be customized using parameters or through a ‘block`.

class Player < ActiveRecord::Base
  extend ActsAsExplorable
  explorable in: [:first_name, :last_name, :position, :city, :club],
             sort: [:first_name, :last_name, :position, :city, :club, :created_at],
             position: ['GK', 'MF', 'FW']
end

Using a block (TODO: This will be available in future versions):

class Player < ActiveRecord::Base
  extend ActsAsExplorable
  explorable do |config|
    config.filters = {
      in: [:first_name, :last_name, :position, :city, :club],
      sort: [:first_name, :last_name, :position, :city, :club, :created_at],
      position: ['GK', 'MF', 'FW']
    }
  end
end

@yield Provides access to the model class’s config, which

allows to customize types and filters

@yieldparam config The model class’s {ActsAsExplorable::Configuration config}.

# File lib/acts_as_explorable/explorable.rb, line 39
def explorable(filters = {}, &_block)
  class_eval do
    def self.explorable?
      true
    end
  end

  if block_given?
    ActsAsExplorable.setup { |config| yield config }
  else
    explorable_set_filters filters
  end
end

Protected Instance Methods

explorable_set_filters(filters = {}) click to toggle source

Configure ActsAsExplorable’s permitted filters per type in a model.

class Person < ActiveRecord::Base
  extend ActsAsExplorable
  explorable_filters in: [:first_name, :last_name, :city],
                     sort: [:first_name, :last_name, :city, :created_at]
end

@param [Hash] filters Filters for types @return [Array] Permitted filters

# File lib/acts_as_explorable/explorable.rb, line 66
def explorable_set_filters(filters = {})
  ActsAsExplorable.filters = filters if filters.present?

  ActsAsExplorable.filters.each_pair do |f, _a|
    ActsAsExplorable.filters[f].map!(&:downcase)
  end

  ActsAsExplorable.filters
end