The code is fine. I like how you use local functions in order to control visibility.
I have a few thoughts though. Why don't you create an update() function inside the base_user table? So we could have this:
local function base_user()
local this = {}
function this.doc()
return {
type = "user";
id = this.id;
user_email = this.email;
user_email_lower = this.email.lower();
user_password = this.password;
}
end
function this.update()
local doc = this.doc()
Lucene.db.save_document(doc)
this.id = doc.id
end
return this
end
This would simplify the new_user() function. Actually, I think the new_user() function shouldn't save the user. For example, the code that invokes the new_user() could get the user and set other properties, like age, name, etc. So it should save the user only at the very end. Does this make sense?