Skip to content

Instantly share code, notes, and snippets.

@patcoll
Created September 11, 2017 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patcoll/4c8cb3cf33b520ff424f43eb82a2ead8 to your computer and use it in GitHub Desktop.
Save patcoll/4c8cb3cf33b520ff424f43eb82a2ead8 to your computer and use it in GitHub Desktop.
module Luma
class Policy
def initialize(user, model)
@user = user
@model = model
end
%w(create read see update change destroy manage search).freeze.each do |attr|
define_method("#{attr}?".to_sym) do
@user&.send(:can?, attr.to_sym, @model)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment