Skip to content

Instantly share code, notes, and snippets.

@1997roylee
Created October 3, 2021 19:46
Show Gist options
  • Save 1997roylee/705723e37155b258eac31780441994a1 to your computer and use it in GitHub Desktop.
Save 1997roylee/705723e37155b258eac31780441994a1 to your computer and use it in GitHub Desktop.
tokens_helper.rb
module TokensHelper
extend ActiveSupport::Concern
module ClassMethods
def define_token_helpers(mapping)
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def current_#{mapping}_token
@current_#{mapping}_token ||= #{mapping}_application.access_tokens.find_by(resource_owner_id: current_user.id)
@current_#{mapping}_token.token
end
def #{mapping}_application
Doorkeeper::Application.find_by!(name: "#{mapping}".titleize)
end
METHODS
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment