-
Notifications
You must be signed in to change notification settings - Fork 5
Persistance API
tpickett66 edited this page Mar 18, 2013
·
2 revisions
The following two methods could provide the template for basic interaction with the persistance layer.
-
Database.store_ticket(attrs)
store a new TGT with the supplied attributes (Hash?), returns either success or a message indicating the problem -
Database.retreive_ticket(tgt_string)
Retreive a ticket I see two options for return value here- An object that responds to a method corresponding to each of the attributes on the ticket (easy for DM and ActiveRecord adapters)
- A hash with the attributes
Additional methods will likely be necessary for finding via relations (i.e. find a TGT from the supplied ST string).
In memory 'persistance' could be done using hashes where the keys are the ticket strings and the values are the ticket attributes supplied to store_ticket methods. Relations could be simulated using another hash with the keys being the 'child' ticket string and the value being the 'parent' ticket string:
# A really crude implementation without any value checking at all
tgts = {
'TGT-ABCDE54321' => attributes
}
sts = {
'ST-12345EDCBA' => attributes
}
st_tgt_parents = {
'ST-12345EDCBA' => 'TGT-ABCDE54321'
}
# A TGT could then be found from an ST string like the following
module Database
def self.get_tgt(tgt_string)
tgts[tgt_string]
end
def self.get_tgt_from_st(st_string)
st_tgt_parents[st_string]
end
end