Using Devise with ActiveModel::Datastore

This weekend I've been hacking away at getting some proper authentication working for my photos site. I'm making this in Ruby because I seem to like the language and its overall flexibility.But I also want to use Google's Datastore which is hands-down better than DynamoDB that I can get from AWS.The problem is that there is not native integration with Devise and the ActiveModel implementation that talks to Google's Datastore.I managed to get it to work with only a few lines of code. This isn't an exhaustive test, but I can create uses, log in, log out, and the normal stuff.Here's the bit of code I added to my User class:

def self.to_adapterAdapter.newendclass Adapterdef get(id)result = User.find(id)if result.size > 0result[0]elsenilendenddef find_first(opts)query_params = []opts.each do |k,v|query_params << [k.to_s, '=', v]endresult = User.all(where: query_params)if result.size > 0result[0]elsenilendendend

From what I can tell, the get and find_first methods are the only critical ones... and I need to make some object to return when to_adapter is called. But once I made these changes, everything started to work as it was supposed to!Anyway... just wanted to share my findings.

Previous
Previous

110-year-old wood

Next
Next

Every once in a while you win