Skip to content

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

Merged
frodsan merged 1 commit into
rails:masterfrom
LTe:object-with-call
Mar 1, 2013
Merged

Allow to use non-proc object in cache_path option#2
frodsan merged 1 commit into
rails:masterfrom
LTe:object-with-call

Conversation

@LTe

@LTe LTe commented Feb 9, 2013

Copy link
Copy Markdown
Contributor

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

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
@frodsan

frodsan commented Feb 11, 2013

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@carlosantoniodasilva

Copy link
Copy Markdown
Member

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

@rafaelfranca

Copy link
Copy Markdown
Member

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

@frodsan

frodsan commented Mar 1, 2013

Copy link
Copy Markdown
Contributor

1.0.0 is released.

@rafaelfranca

Copy link
Copy Markdown
Member

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

@frodsan

frodsan commented Mar 1, 2013

Copy link
Copy Markdown
Contributor

@rafaelfranca Sure, but what about @carlosantoniodasilva comments?

@rafaelfranca

Copy link
Copy Markdown
Member

You can merge and apply those changes after

frodsan pushed a commit that referenced this pull request Mar 1, 2013
Allow to use non-proc object in cache_path option
@frodsan
frodsan merged commit ab2c52f into rails:master Mar 1, 2013
@frodsan

frodsan commented Mar 1, 2013

Copy link
Copy Markdown
Contributor

Ok, no problem. @LTe Thanks! 😄

frodsan pushed a commit that referenced this pull request Mar 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants