annotate LibModuleDBShare-1.0/LibModuleDBShare-1.0.lua @ 15:1dd07f05ecac

added param checks to LMDBS:NewGroup
author Andrew Knoll <andrewtknoll@gmail.com>
date Sun, 10 Mar 2013 22:50:29 -0400
parents 5947b9721b9c
children 2384f5c2a707
rev   line source
>@5 1 --- **LibModuleDBShare-1.0**\\
>@5 2 -- A description will eventually be here.
>@5 3 --
>@5 4 -- @usage
>@5 5 -- Also coming soon.
>@5 6 -- @class file
>@5 7 -- @name LibModuleDBShare-1.0.lua
>@3 8 local MAJOR, MINOR = "LibModuleDBShare-1.0", 1
>@3 9 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
>@3 10
>@4 11 if not LibModuleDBShare then return end -- No upgrade needed
>@4 12
andrewtknoll@15 13 -- Lua APIs
andrewtknoll@15 14 local assert = assert;
andrewtknoll@15 15
@12 16 local AceDB = LibStub("AceDB-3.0");
@12 17
>@4 18 LibModuleDBShare.groups = LibModuleDBShare.groups or {};
>@4 19
>@5 20 local DBGroup = {};
>@5 21
>@5 22 --- Creates a new DB group.
>@5 23 -- @param groupName The name of the new DB group.
@12 24 -- @param usesDualSpec True if this group should use LibDualSpec, false otherwise. (NYI)
andrewtknoll@11 25 -- @param initialProfile The name of the profile to start with.
>@5 26 -- @usage
>@5 27 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", true)
>@5 28 -- @return the new DB group object
andrewtknoll@11 29 function LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile)
andrewtknoll@15 30 assert(type(groupName) == "string", "Usage: LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' is not a string.");
andrewtknoll@15 31 assert(type(LibModuleDBShare.groups[groupName]) == "nil", "LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' already exists");
@12 32 local group = {}
@12 33 group.name = groupName;
@12 34 group.syncDBTable = {};
@12 35 group.syncDB = AceDB:New(group.syncDBTable, nil, true);
@12 36 for k, v in pairs(DBGroup) do
@12 37 group[k] = v;
@12 38 end
@12 39 return group;
>@4 40 end
>@4 41
>@5 42 --- Retrieves an existing DB group.
>@5 43 -- @param groupName The name of the DB group to retrieve.
>@5 44 -- @usage
>@5 45 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName")
>@5 46 -- @return the DB group object, or nil if not found
>@5 47 function LibModuleDBShare:GetGroup(groupName)
@12 48 return LibModuleDBShare.groups[groupName];
>@4 49 end
>@5 50
>@5 51 --- Adds a database to the group.
>@5 52 -- @param db The name of the new DB group.
>@5 53 -- @usage
>@5 54 -- myAddonDBGroup:AddDB(MyAddon.db)
>@5 55 function DBGroup:AddDB(db)
>@5 56
>@5 57 end