Class: Norman::Adapter
- Inherits:
-
Object
- Object
- Norman::Adapter
- Defined in:
- lib/norman/adapter.rb
Overview
Adapters are responsible for persisting the database. This base adapter offers no persistence, all IO operations are just stubs. Adapters must also present the full database as a Hash to the mapper, and provide a ‘key` method that returns an array with all the keys for the specified model class.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#db_for(klass) ⇒ Object
Get a hash of all the data for the specified model class.
-
#export_data ⇒ Object
Inheriting adapters can overload this method to export the data to a String.
-
#import_data ⇒ Object
Inheriting adapters can overload this method to load the data from some kind of storage.
-
#initialize(options = {}) ⇒ Adapter
constructor
A new instance of Adapter.
-
#load_database ⇒ Object
Loads the database.
-
#save_database ⇒ Object
Inheriting adapters can overload this method to persist the data to some kind of storage.
Constructor Details
#initialize(options = {}) ⇒ Adapter
Returns a new instance of Adapter.
14 15 16 17 18 |
# File 'lib/norman/adapter.rb', line 14 def initialize( = {}) @name = [:name] || Norman.default_adapter_name load_database Norman.register_adapter(self) end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
11 12 13 |
# File 'lib/norman/adapter.rb', line 11 def db @db end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/norman/adapter.rb', line 10 def name @name end |
Instance Method Details
#db_for(klass) ⇒ Object
Get a hash of all the data for the specified model class.
22 23 24 |
# File 'lib/norman/adapter.rb', line 22 def db_for(klass) @db[klass.to_s] ||= {} end |
#export_data ⇒ Object
Inheriting adapters can overload this method to export the data to a String.
37 38 39 |
# File 'lib/norman/adapter.rb', line 37 def export_data true end |
#import_data ⇒ Object
Inheriting adapters can overload this method to load the data from some kind of storage.
43 44 45 |
# File 'lib/norman/adapter.rb', line 43 def import_data true end |
#load_database ⇒ Object
Loads the database. For this adapter, that means simply creating a new hash.
28 29 30 |
# File 'lib/norman/adapter.rb', line 28 def load_database @db = {} end |
#save_database ⇒ Object
Inheriting adapters can overload this method to persist the data to some kind of storage.
49 50 51 |
# File 'lib/norman/adapter.rb', line 49 def save_database true end |