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_adapter
  Adapter.new
end

class Adapter
  def get(id)
    result = User.find(id)
    if result.size > 0
      result[0]
    else
      nil
    end
  end

  def find_first(opts)
    query_params = []
    opts.each do |k,v|
      query_params << [k.to_s, '=', v]
    end
    result = User.all(where: query_params)
    if result.size > 0
      result[0]
    else
      nil
    end
  end

end

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.