Mercurial > wow > libmoduledbshare-1-0
comparison LibModuleDBShare-1.0/LibModuleDBShare-1.0.lua @ 26:4bc47e7b549d
Rewrote parameter checks - now checks to see if DBs are actually DBs
| author | Andrew Knoll <andrewtknoll@gmail.com> |
|---|---|
| date | Sat, 16 Mar 2013 20:09:19 -0400 |
| parents | e825492d4edd |
| children | 0739db0c99ac |
comparison
equal
deleted
inserted
replaced
| 25:e825492d4edd | 26:4bc47e7b549d |
|---|---|
| 9 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR) | 9 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
| 10 | 10 |
| 11 if not LibModuleDBShare then return end -- No upgrade needed | 11 if not LibModuleDBShare then return end -- No upgrade needed |
| 12 | 12 |
| 13 -- Lua APIs | 13 -- Lua APIs |
| 14 local assert, type, pairs, time = assert, type, pairs, time; | 14 local error, type, pairs, time = error, type, pairs, time; |
| 15 | 15 |
| 16 -- Required Libraries | 16 -- Required Libraries |
| 17 local AceDB = LibStub("AceDB-3.0"); | 17 local AceDB = LibStub("AceDB-3.0"); |
| 18 local AceDBOptions = LibStub("AceDBOptions-3.0"); | 18 local AceDBOptions = LibStub("AceDBOptions-3.0"); |
| 19 local AceConfigRegistry = LibStub("AceConfigRegistry-3.0"); | 19 local AceConfigRegistry = LibStub("AceConfigRegistry-3.0"); |
| 31 -- @usage | 31 -- @usage |
| 32 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", true) | 32 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", true) |
| 33 -- @return the new DB group object | 33 -- @return the new DB group object |
| 34 function LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec) | 34 function LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec) |
| 35 -- verify parameters | 35 -- verify parameters |
| 36 assert(type(groupName) == "string", "Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupName' must be a string."); | 36 if type(groupName) ~= "string" then |
| 37 assert(type(groupDescription) == "string", "Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupDescription' must be a string."); | 37 error("Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupName' must be a string.", 2); |
| 38 assert(type(LibModuleDBShare.groups[groupName]) == "nil", "LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): group '"..groupName.."' already exists."); | 38 elseif type(groupDescription) ~= "string" then |
| 39 assert(type(initialDB) == "table", "LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'initalDB must be a table."); | 39 error("Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupDescription' must be a string.", 2); |
| 40 elseif type(LibModuleDBShare.groups[groupName]) ~= "nil" then | |
| 41 error("LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): group '"..groupName.."' already exists.", 2); | |
| 42 elseif type(initialDB) ~= "table" or not AceDB.db_registry[initial] then | |
| 43 error("LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'initalDB must be an AceDB-3.0 database.", 2); | |
| 44 end | |
| 40 -- create group | 45 -- create group |
| 41 local group = {} | 46 local group = {} |
| 42 group.name = groupName; | 47 group.name = groupName; |
| 43 group.members = {}; | 48 group.members = {}; |
| 44 -- create root option panel for group | 49 -- create root option panel for group |
| 99 -- @param newDB The database to add. | 104 -- @param newDB The database to add. |
| 100 -- @usage | 105 -- @usage |
| 101 -- myAddonDBGroup:AddDB(MyAddon.db) | 106 -- myAddonDBGroup:AddDB(MyAddon.db) |
| 102 function DBGroup:AddDB(newDB) | 107 function DBGroup:AddDB(newDB) |
| 103 -- verify parameters | 108 -- verify parameters |
| 104 assert(type(newDB) == "table", "Usage: DBGroup:AddDB(newDB): 'newDB' must be a table."); | 109 if type(newDB) ~= "table" or not AceDB.db_registry[newDB] then |
| 105 assert(type(self.members[newDB]) == "nil", "DBGroup:AddDB(newDB): 'newDB' is already a member of DBGroup."); | 110 error("Usage: DBGroup:AddDB(newDB): 'newDB' must be a table.", 2); |
| 111 elseif type(self.members[newDB]) ~= "nil" then | |
| 112 error("DBGroup:AddDB(newDB): 'newDB' is already a member of DBGroup.", 2); | |
| 113 end | |
| 106 -- record current profile | 114 -- record current profile |
| 107 local syncProfile = self.syncDB:GetCurrentProfile(); | 115 local syncProfile = self.syncDB:GetCurrentProfile(); |
| 108 -- add new profiles to syncDB | 116 -- add new profiles to syncDB |
| 109 self.squelchCallbacks = true; | 117 self.squelchCallbacks = true; |
| 110 for i, profile in pairs(newDB:GetProfiles()) do | 118 for i, profile in pairs(newDB:GetProfiles()) do |
