cpjk / canary

:hatching_chick: Elixir authorization and resource-loading library for Plug applications.
MIT License
474 stars 51 forks source link

load the resource into a variable with a name inferred from the model name #11

Closed cpjk closed 9 years ago

cpjk commented 9 years ago

For example, plug :load_resource, model: Project.User would load the user resource into conn.assigns.user, which would then be available in views as @user

mgwidmann commented 9 years ago

:+1: this!

Hate to see <%= @loaded_resource.name %> in the view layer!

cpjk commented 9 years ago

Thanks for letting me know!

I'm thinking of inferring the name through naming conventions, while also allowing the user to specify the target variable with something like plug load_resource model: Project.User, as: :user.

I'll look at implementing the as flag as soon as possible, while I am figuring out the best way to implement the variable name inference.

mgwidmann commented 9 years ago

Great! Good to see such an early start on an important project like this!

cpjk commented 9 years ago

I've pushed up some preliminary changes to https://github.com/cpjk/canary/tree/fix_double_loading that implement opts[:as] for resource loading, e.g. load_resource model: User, as: :user.

There's no model inference yet, but I think this is a good start.

cpjk commented 9 years ago

Added another commit to infer the name from the model specified in the plug.

For example, plug load_resource, model: Project.Post will load the resource into conn.assigns.post and plug load_resource, model: Project.BlogPost would load the resource into conn.assigns.blog_post

mgwidmann commented 9 years ago

:+1: Awesome!

cpjk commented 9 years ago

Closing the issue as the changes were merged into master over the weekend