class Percolate::Adapter::BaseAdapter

A base class to build off of.

Public Class Methods

new(data_source = nil) click to toggle source

The constructor.

@param data_source [Object] the data source.

# File lib/percolate/adapter/base_adapter.rb, line 25
def initialize(data_source = nil)
  @data_source = data_source
end

Public Instance Methods

configure_facet(facet, attr_hash) click to toggle source

Configures a facet according to the given attribute hash.

@param facet [Object] the facet. @param attr_hash [Hash] the attribute hash.

@return [Object] the facet.

# File lib/percolate/adapter/base_adapter.rb, line 69
def configure_facet(facet, attr_hash)
  attr_hash.each_pair do |attr, value|
    facet.send((attr + "=").to_sym, value)
  end

  facet
end
create_facet(facet_name) click to toggle source

Creates a facet from the given name.

@param facet_name [Symbol] the facet name.

@return [Object] the facet.

# File lib/percolate/adapter/base_adapter.rb, line 51
def create_facet(facet_name)
  const_str = ActiveSupport::Inflector.camelize(facet_name) + "Facet"

  begin
    require "percolate/facet/#{facet_name}_facet"
  rescue LoadError
    # Do nothing. Give the benefit of the doubt if the file doesn't exist.
  end if !Facet.const_defined?(const_str)

  Facet.const_get(const_str).new
end
load_entities() click to toggle source

Loads entities in an adapter-specific way.

@return [Hash] the loaded entities.

# File lib/percolate/adapter/base_adapter.rb, line 32
def load_entities
  {}
end
load_facet(context, facet_name) click to toggle source

Loads a facet.

@param context [String] the lookup context. @param facet_name [Symbol] the facet name.

@return [Object] the loaded facet.

# File lib/percolate/adapter/base_adapter.rb, line 42
def load_facet(context, facet_name)
  create_facet(facet_name)
end
method_missing(sym, *args, &block) click to toggle source

If the given method isn't found, check for a setter of the same name.

Calls superclass method
# File lib/percolate/adapter/base_adapter.rb, line 78
def method_missing(sym, *args, &block)
  if sym[-1] != "="
    sym_set = (sym.to_s + "=").to_sym
    return send(sym_set, *args, &block) if respond_to?(sym_set)
  end

  super
end