Class: Percolate::Adapter::BaseAdapter
- Inherits:
-
Object
- Object
- Percolate::Adapter::BaseAdapter
- Defined in:
- lib/percolate/adapter/base_adapter.rb
Overview
A base class to build off of.
Direct Known Subclasses
Instance Method Summary collapse
-
#configure_facet(facet, attr_hash) ⇒ Object
Configures a facet according to the given attribute hash.
-
#create_facet(facet_name) ⇒ Object
Creates a facet from the given name.
-
#initialize(data_source = nil) ⇒ BaseAdapter
constructor
The constructor.
-
#load_entities ⇒ Hash
Loads entities in an adapter-specific way.
-
#load_facet(context, facet_name) ⇒ Object
Loads a facet.
-
#method_missing(sym, *args, &block) ⇒ Object
If the given method isn’t found, check for a setter of the same name.
Constructor Details
#initialize(data_source = nil) ⇒ BaseAdapter
The constructor.
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.
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.
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_entities ⇒ Hash
Loads entities in an adapter-specific way.
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.
43 44 45 |
# File 'lib/percolate/adapter/base_adapter.rb', line 43 def load_facet(context, facet_name) create_facet(facet_name) end |