Allow to use non-proc object in cache_path option #2

Merged
merged 1 commit into from Mar 1, 2013

Projects

None yet

4 participants

@LTe
Contributor
LTe commented Feb 9, 2013

You can use :cache_path option with object that respond to #call method.
Before this patch ActionCacheFilter check that object respond to #call
method and execute #instance_exec on controller instance. It was strange
because #instance_exec method can work only with Proc objects.

When you pass Proc object to :cache_option it will be execute #instance_exec
with this Proc otherwise when object is respond to #call method will be called
on this object.

  class CachePath
    def call(controller)
      controller.id
    end
  end

  class TestController < ApplicationController
    caches_action :index, :cache_path => CachePath.new
    def index; end
  end
@LTe LTe Allow to use non-proc object in cache_path option
You can use :cache_path option with object that respond to #call method.
Before this patch ActionCacheFilter check that object respond to #call
method and execute #instance_exec on controller instance. It was strange
because #instance_exec method can work only with Proc objects.

When you pass Proc object to :cache_option it will be execute #instance_exec
with this Proc otherwise when object is respond to #call method will be called
on this object.

  class CachePath
    def call(controller)
      controller.id
    end
  end

  class TestController < ApplicationController
    caches_action :index, :cache_path => CachePath.new
    def index; end
  end
11c4a0a
@frodsan
Contributor
frodsan commented Feb 11, 2013

It seems good to me 👍 @rafaelfranca @carlosantoniodasilva WDYT?

@carlosantoniodasilva carlosantoniodasilva commented on the diff Feb 11, 2013
lib/action_controller/caching/actions.rb
@@ -43,6 +43,8 @@ module Caching
# <tt>ActionCachePath.new</tt>. This is handy for actions with
# multiple possible routes that should be cached differently. If a
# block is given, it is called with the current controller instance.
+ # If a object is given, it is called <tt>call</tt> method with the
@carlosantoniodasilva
carlosantoniodasilva Feb 11, 2013 Member

How about: If an object that responds to <tt>call</tt> is given, it'll be called with the current controller instance.

@carlosantoniodasilva

Seems fine I guess. Is it worth to start its own changelog maybe?

@rafaelfranca
Member

I think is better to release the version 1.0.0 before to pull this in

@frodsan
Contributor
frodsan commented Mar 1, 2013

1.0.0 is released.

@rafaelfranca
Member

Right. @frodsan can you merge this in and start the CHANGELOG?

@frodsan
Contributor
frodsan commented Mar 1, 2013

@rafaelfranca Sure, but what about @carlosantoniodasilva comments?

@rafaelfranca
Member

You can merge and apply those changes after

@frodsan frodsan merged commit ab2c52f into rails:master Mar 1, 2013

1 check passed

default The Travis build passed
Details
@frodsan
Contributor
frodsan commented Mar 1, 2013

Ok, no problem. @LTe Thanks! 😄

@frodsan frodsan pushed a commit that referenced this pull request Mar 1, 2013
Francesco Rodriguez add CHANGELOG entry for #2 b74cb2b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment