Created
February 13, 2015 01:45
-
-
Save gschorkopf/2c7a3ecc81fc9301d6b5 to your computer and use it in GitHub Desktop.
Revisions
-
gschorkopf created this gist
Feb 13, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ Hum. I don't think I know of a good way to do that that isn't a bit meta-y. I assume you're saying, for this group of policy methods, return false if ```assigned_to_company?``` is false. Here's a fun thing I found with help from the interwebs. Whether it's a good solution or not is up for debate. ```ruby module CompanyPolicyHelper def check_company_affiliation_for(*methods) methods.each do |method_name| method = instance_method(method_name) define_method(method_name) do |*args, &block| yield method.bind(self).(*args, &block) end end end end class OperationPolicy extend CompanyPolicyHelper def show? # stuff end def index? # stuff end check_company_affiliation_for([:show, :index]) do return false if assigned_to_company? end end