class Pod4::Interface
Abstract class, The parent of all interfaces.
An interface encapsulates whatever method we are using up connect to the data. Its state is therefore that of the connection, not the DB table or whatever entity that the data source uses to group data. It raises only SwingShift errors (wrapping the error it gets inside a SwingShift error).
We would expect a child of Interface
for each data access type (sequelInterface, NebulousInterface
, etc). These children *will not change* the signatures of the methods below.
The methods below are the required ones. Interfaces will likely implement other, interface-specific, ways of accessing data.
In Normal use, the interface classes may in turn be subclassed as inner classes within each model, in order to customise them for the specific entity that they are drawing data from.
Note that your Interface
subclass probably returns an Octothorpe rather than a Hash, q.v.. (But you should be able to treat the former as if it were the latter in most cases.)
Note that if an Interface
raises a Pod4::WeakError
, then Pod4::Model
will catch that and turn it into a Pod4::Alert
.
Constants
- ACTIONS
Public Class Methods
Individual implementations are likely to have very different initialize methods, which will accept whatever SwingShift object is needed to contact the data store, eg. the Sequel DB object.
# File lib/pod4/interface.rb, line 56 def initialize raise NotImplemented, "Interface needs to define an 'initialize' method" end
Public Instance Methods
For testing purposes you should expose a _connection method that returns the Connection
object the Interface
uses
# File lib/pod4/interface.rb, line 121 def _connection raise NotImplemented, "Interface needs to define a '_connection' method" end
Called by a Connection
Object to close the connection.
# File lib/pod4/interface.rb, line 113 def close_connection(conn) raise NotImplemented, "Interface needs to define a 'close_connection' method" end
Create accepts a record parameter (Hash or OT, but again, the format of this will vary) representing a record, and creates the record. Should return the ID for the new record.
# File lib/pod4/interface.rb, line 76 def create(record) raise NotImplemented, "Interface needs to define a 'create' method" end
delete removes the record with the given ID. returns self.
# File lib/pod4/interface.rb, line 99 def delete(id) raise NotImplemented, "Interface needs to define a 'delete' method" end
true if id_fld
autoincrements
# File lib/pod4/interface.rb, line 47 def id_ai raise NotImplemented, "Interface has no 'id_ai' method (use `set_id_fld`?)" end
A field name in the data source, the name of the unique ID field.
# File lib/pod4/interface.rb, line 40 def id_fld raise NotImplemented, "Interface has no 'id_fld' method (use `set_id_fld`?)" end
List accepts a parameter as selection criteria, and returns an array of Octothorpes. Exactly what the selection criteria look like will vary from interface to interface. So will the contents of the return OT, although it must include the ID field. (Ideally each element of the return array should follow the same format as the return value for read(). )
Note that list should ALWAYS return an array; never nil.
# File lib/pod4/interface.rb, line 68 def list(selection=nil) raise NotImplemented, "Interface needs to define a 'list' method" end
Called by a Connection
object to start a database connection
# File lib/pod4/interface.rb, line 106 def new_connection(args) raise NotImplemented, "Interface needs to define a 'new_connection' method" end
Read accepts an ID, and returns an Octothorpe representing the unique record for that ID. If there is no record matching the ID then it returns an empty Octothorpe.
# File lib/pod4/interface.rb, line 84 def read(id) raise NotImplemented, "Interface needs to define a 'read' method" end
Update accepts an ID and a record parameter. It updates the record on the data source that matches the ID using the record parameter. It returns self.
# File lib/pod4/interface.rb, line 92 def update(id, record) raise NotImplemented, "Interface needs to define a 'update' method" end