I've been toying around with MongoRecord, but I'm not sure I like it. I
have yet to figure out how to set default values. Also, it incorrectly
includes ActiveRecord as ancestor, which caused merb-auth to mix in
stuff that didn't quite work, mainly because of callbacks.
Moving back to the raw ruby driver, I found it lacks some more examples,
and some way to make DBRef handling easier.
> I'm currently using MongoDB with merb in several applications as the
> primary database. I've also used Redis as the primary DB with great
> success. I don't use an ORM since this often doesn't make much sense,
> if you have a one to one mapping of objects to collections this works
> (I believe DM couchdb adapter made this assumption). To get the real
> value of a document database or key-value store you're often using
> some of the more interesting features like embedded queries, the mongo
> increment/update operations, capped collections, etc. these don't map
> well to your typical ORM.
>
> In regard to the original question about authentication, the merb-auth
> slices out of the box just require that you implement the class method
> authenticate(login, pass) and return the user object if successfully
> authenticated, or nil if unsuccessful. The class below is a self
> contained User model object for merb which will enable you to
> save/retrieve/authenticate users with merb-auth.
>
>
> class User
> attr_accessor :id, :login, :password
>
> @@collection =
> XGen::Mongo::Driver::Mongo.new.db('mydb').collection('mycollection')
>
>
> def initialize(params=nil)
> params = params.kind_of?(Hash) ? params : {}
> @id, @login, @password = params[:_id], params[:login], params[:password]
> end
>
> def save
> self.id ||= XGen::Mongo::Driver::ObjectID.new
> @@collection.save({:_id => self.id, :login => self.login,
> :password => self.password})
> end
>
> class << self
> def get(login)
> h = @@collection.find_first(:login => login)
> h.nil? ? nil : User.new(h.to_mash)
> end
>
> def authenticate(login, password)
> u = get(login)
> if u && u.login == login && u.password == password
> return u
> end
> nil
> end
> end
> en
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---