Class: CurlyMustache::Adapters::Abstract
- Inherits:
-
Object
- Object
- CurlyMustache::Adapters::Abstract
- Defined in:
- lib/curly_mustache/adapters/abstract.rb
Overview
Subclass this class to make new adapters.
The required methods for basic functionality are: new
, get
, put
and delete
.
If you want to include CurlyMustache::Locking, then you must implement lock
and unlock
and locked?
.
If you want unit tests to run using your adapter, you must implement flush_db
.
Instance Attribute Summary collapse
-
#model_class ⇒ Object
Holds a reference to the class that is currently using this adapter.
Instance Method Summary collapse
-
#adapter_name ⇒ Object
This returns the name of the adapter which can be used in #establish_connection.
-
#delete(key) ⇒ Object
Implementing this is required for basic functionality.
-
#flush_db ⇒ Object
Implement this if you want unit tests to run for your adapter.
-
#get(key) ⇒ Object
Implementing this is required for basic functionality.
-
#initialize(config) ⇒ Abstract
constructor
Implementing this is required for basic functionality.
-
#lock(key) ⇒ Object
Implement this if you want to include the <tt>CurlyMustache::Locking<tt> module into your model class.
-
#locked?(key) ⇒ Boolean
Implement this if you want to include the <tt>CurlyMustache::Locking<tt> module into your model class.
-
#mget(keys) ⇒ Object
The default implementation of this just iterates over keys calling
get
on them. -
#put(key, value) ⇒ Object
Implementing this is required for basic functionality.
-
#unlock(key) ⇒ Object
Implement this if you want to include the <tt>CurlyMustache::Locking<tt> module into your model class.
Constructor Details
#initialize(config) ⇒ Abstract
Implementing this is required for basic functionality. config
is passed directly from #establish_connection.
20 21 22 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 20 def initialize(config) raise NotImplementedError end |
Instance Attribute Details
#model_class ⇒ Object
Holds a reference to the class that is currently using this adapter.
12 13 14 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 12 def model_class @model_class end |
Instance Method Details
#adapter_name ⇒ Object
This returns the name of the adapter which can be used in #establish_connection. If your adapter class’s name is “MyFunkyAdapter”, then this method will return :my_funky_adapter
.
80 81 82 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 80 def adapter_name @adapter_name ||= self.class.name.split("::").last.underscore.to_sym end |
#delete(key) ⇒ Object
Implementing this is required for basic functionality.
38 39 40 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 38 def delete(key) raise NotImplementedError end |
#flush_db ⇒ Object
Implement this if you want unit tests to run for your adapter.
47 48 49 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 47 def flush_db raise NotImplementedError end |
#get(key) ⇒ Object
Implementing this is required for basic functionality. The output should be a hash of attributes that will be used to instantiate a model, or the input of an “in” serializer if one is being used.
27 28 29 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 27 def get(key) raise NotImplementedError end |
#lock(key) ⇒ Object
Implement this if you want to include the <tt>CurlyMustache::Locking<tt> module into your model class.
52 53 54 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 52 def lock(key) raise NotImplementedError end |
#locked?(key) ⇒ Boolean
Implement this if you want to include the <tt>CurlyMustache::Locking<tt> module into your model class.
62 63 64 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 62 def locked?(key) raise NotImplementedError end |
#mget(keys) ⇒ Object
The default implementation of this just iterates over keys calling get
on them. Override this implementation if your data store has a more efficient way of retrieving multiple keys. The return value should be an array of values where each value follow the same rules for the output of get
. Also the order of the values in the array should match the order of the keys
argument.
74 75 76 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 74 def mget(keys) keys.collect{ |key| get(key) }.compact end |
#put(key, value) ⇒ Object
Implementing this is required for basic functionality. value
is the model’s attributes hash, or the output of an “out” serializer if one is being used.
33 34 35 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 33 def put(key, value) raise NotImplementedError end |
#unlock(key) ⇒ Object
Implement this if you want to include the <tt>CurlyMustache::Locking<tt> module into your model class.
57 58 59 |
# File 'lib/curly_mustache/adapters/abstract.rb', line 57 def unlock(key) raise NotImplementedError end |