Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using non-ORM bindings #69

Open
fancyremarker opened this issue Jul 16, 2014 · 1 comment
Open

Using non-ORM bindings #69

fancyremarker opened this issue Jul 16, 2014 · 1 comment

Comments

@fancyremarker
Copy link
Contributor

I'm using Garner in a project (really, a couple projects) where we don't ever need to bind to ActiveRecord or Mongoid objects. Instead, we want to cache certain data (the roles to which a user belongs) and bind it to the OAuth token they present.

Right now, I'm doing this by monkey-patching the AccessToken class in an initializer:

Garner.configure do |config|
  # Other configuration options...
  config.binding_key_strategy = Garner::Strategies::Binding::Key::CacheKey
end

module Fridge
  class AccessToken
    include Garner::Cache::Binding

    def cache_key
      id
    end
  end
end

Then I can do stuff like:

garner.bind(token) { roles.map(&:href) }

What do we think is the appropriate way to "Garner-ify" non-ORM objects? Is re-opening the class the right way to do this? Right now, it's necessary to, at a minimum include Garner::Cache::Binding in any class whose instances will be used as bindings. Is there a better way?

@dblock
Copy link
Contributor

dblock commented Jul 17, 2014

Reopening is probably fine, except I think I would like to write something like Fridge::AccessToken.extend Garner::Cache::Binding::GenericBindingById. Maybe there's a way to delegate this, too?

config.something = {
    Fridge::AccessToken => ...
}

This could allow delegating Object's binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants