Skip to content

Instantly share code, notes, and snippets.

@rwehresmann
Created May 16, 2019 00:48
Show Gist options
  • Select an option

  • Save rwehresmann/066d6f9eee23c30e46c23abd5d279059 to your computer and use it in GitHub Desktop.

Select an option

Save rwehresmann/066d6f9eee23c30e46c23abd5d279059 to your computer and use it in GitHub Desktop.
...
Knock::Authenticable.module_eval do
def define_current_entity_getter(entity_class, getter_name)
unless self.respond_to?(getter_name)
memoization_var_name = "@_#{getter_name}"
self.class.send(:define_method, getter_name) do
unless instance_variable_defined?(memoization_var_name)
current = Knock::AuthToken.new(token: token).entity_for(entity_class)
instance_variable_set(memoization_var_name, current)
end
instance_variable_get(memoization_var_name)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment