Class: Percolate::Adapter::BaseAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/percolate/adapter/base_adapter.rb

Overview

A base class to build off of.

Direct Known Subclasses

ChefDataBagAdapter, FixtureAdapter

Instance Method Summary collapse

Constructor Details

#initialize(data_source = nil) ⇒ BaseAdapter

The constructor.

Parameters:

  • data_source (Object) (defaults to: nil)

    the data source.



26
27
28
# File 'lib/percolate/adapter/base_adapter.rb', line 26

def initialize(data_source = nil)
  @data_source = data_source
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

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



79
80
81
82
83
84
85
86
# File 'lib/percolate/adapter/base_adapter.rb', line 79

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

Instance Method Details

#configure_facet(facet, attr_hash) ⇒ Object

Configures a facet according to the given attribute hash.

Parameters:

  • facet (Object)

    the facet.

  • attr_hash (Hash)

    the attribute hash.

Returns:

  • (Object)

    the facet.



70
71
72
73
74
75
76
# File 'lib/percolate/adapter/base_adapter.rb', line 70

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) ⇒ Object

Creates a facet from the given name.

Parameters:

  • facet_name (Symbol)

    the facet name.

Returns:

  • (Object)

    the facet.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/percolate/adapter/base_adapter.rb', line 52

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_entitiesHash

Loads entities in an adapter-specific way.

Returns:

  • (Hash)

    the loaded entities.



33
34
35
# File 'lib/percolate/adapter/base_adapter.rb', line 33

def load_entities
  {}
end

#load_facet(context, facet_name) ⇒ Object

Loads a facet.

Parameters:

  • context (String)

    the lookup context.

  • facet_name (Symbol)

    the facet name.

Returns:

  • (Object)

    the loaded facet.



43
44
45
# File 'lib/percolate/adapter/base_adapter.rb', line 43

def load_facet(context, facet_name)
  create_facet(facet_name)
end