Being able to specify a method name (of the ability) used for checking abilities (instead of procs) #702

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants

Currently, it isn't possible to Marshal.dump ability instances with "procced abilities".

class Foo
  include CanCan::Ability
end

foo = Foo.new
foo.can :read, String, nil do |instance|
  # do something
end

Marshal.dump foo
=> TypeError: no marshal_dump is defined for class Proc

So instead of providing a proc, I have made it possible to specify a method of the ability instance used for checking abilities.

class Foo
  include CanCan::Ability
  def evaluate(instance, conditions)
    # do something
  end
end

foo = Foo.new
foo.can :read, String, nil, :evaluate

Marshal.dump foo
=> "\x04\bo:\bFoo\x06:\v@rules[\x06o:\x11CanCan::Rule\f:\x0F@match_allF:\x13@base_behaviorT:\r@actions[\x06:\tread:\x0E@subjects[\x06c\vString:\x10@conditions{\x00:\f@method:\revaluate:\r@ability@\x00"
Being able to accept a method name of the ability used for checking a…
…bilities

Doing this provides us Marshal dumping abilities with "proc ability checking"
Collaborator

andhapp commented Jul 27, 2012

@archan937: What's the reason to Marshal the ability class? I've never had to do it so curious to know.

We are storing our abilities in Memcache. Except "procced abilities" aren't possible to dump.

xhoy commented Apr 10, 2014

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still.
Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment