changeset 96:148d8c17cb79

Less monkeypatching rails, more monkeypatching tweet
author nanaya <me@myconan.net>
date Thu, 28 Jul 2016 04:25:47 +0900
parents dfd7daac110e
children ff5557f9902c
files app/views/tweets/show.atom.erb config/initializers/monkeypatch_collection_cache_key_callable.rb config/initializers/twitter_tweet_cache_key.rb
diffstat 3 files changed, 6 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/app/views/tweets/show.atom.erb	Thu Jul 28 03:56:56 2016 +0900
+++ b/app/views/tweets/show.atom.erb	Thu Jul 28 04:25:47 2016 +0900
@@ -12,5 +12,5 @@
     <%= @tweets.first.try(:created_at) || Time.at(0) %>
   </updated>
 
-  <%= render :partial => "tweet", :collection => @tweets, :cached => ->(f) { f.id } %>
+  <%= render :partial => "tweet", :collection => @tweets, :cached => true %>
 </feed>
--- a/config/initializers/monkeypatch_collection_cache_key_callable.rb	Thu Jul 28 03:56:56 2016 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-# stolen from https://github.com/rails/rails/pull/25616
-
-if Gem::Version.new(Rails.version) >= Gem::Version.new("5.1.0")
-  raise "remove this monkey patch!"
-end
-
-module ActionView::CollectionCaching
-  private def collection_by_cache_keys
-    seed =
-      if @options[:cached].respond_to?(:call)
-        @options[:cached]
-      else
-        ->(i) { i }
-      end
-
-    @collection.each_with_object({}) do |item, hash|
-      hash[expanded_cache_key(seed.call(item))] = item
-    end
-  end
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/initializers/twitter_tweet_cache_key.rb	Thu Jul 28 04:25:47 2016 +0900
@@ -0,0 +1,5 @@
+class Twitter::Tweet
+  def cache_key
+    "twitter/tweet/#{id}"
+  end
+end