Last active
November 15, 2017 06:34
-
-
Save malomalo/6dc5a2e036f7f94d188aafe4244c84ad to your computer and use it in GitHub Desktop.
This file contains 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 characters
require 'jbuilder' | |
require 'jbuilder/jbuilder_template' | |
module Rails | |
def self.cache | |
@cache ||= ActiveSupport::Cache::MemoryStore.new | |
end | |
end | |
# Fill the cache | |
JbuilderTemplate.encode FakeContext.new do |json| | |
json.cached do | |
json.cache! 'jbcached' do | |
json.array! 0..100 do |i| | |
json.a i | |
json.b i | |
json.c i | |
json.d i | |
json.e i | |
json.subitems 0..100 do |j| | |
json.f i.to_s * j | |
json.g i.to_s * j | |
json.h i.to_s * j | |
json.i i.to_s * j | |
json.j i.to_s * j | |
end | |
end | |
end | |
end | |
end | |
# Everthing before this is run once initialy, after is the test | |
__SETUP__ | |
JbuilderTemplate.encode FakeContext.new do |json| | |
json.cached do | |
json.cache! 'jbcached' do | |
json.array! 0..100 do |i| | |
json.a i | |
json.b i | |
json.c i | |
json.d i | |
json.e i | |
json.subitems 0..100 do |j| | |
json.f i.to_s * j | |
json.g i.to_s * j | |
json.h i.to_s * j | |
json.i i.to_s * j | |
json.j i.to_s * j | |
end | |
end | |
end | |
end | |
end |
This file contains 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 characters
# This is file is prepended to the test so it's run once before any | |
# of the test code | |
require "active_support" | |
require 'action_view' | |
require 'action_view/testing/resolvers' | |
class FakeController | |
def perform_caching | |
true | |
end | |
def instrument_fragment_cache(a, b) | |
yield | |
end | |
end | |
class FakeContext | |
attr_reader :controller | |
def initialize | |
@controller = FakeController.new | |
end | |
end |
This file contains 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 characters
gem install 'analyzer' | |
analyze jbuilder.rb turbostream.rb -l lib.rb |
This file contains 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 characters
require 'turbostreamer' | |
require 'turbostreamer/handler' | |
require 'turbostreamer/template' | |
module Rails | |
def self.cache | |
@cache ||= ActiveSupport::Cache::MemoryStore.new | |
end | |
end | |
# Fill the cache | |
TurboStreamer::Template.encode FakeContext.new do |json| | |
json.object! do | |
json.cached do | |
json.cache! 'tscached' do | |
json.array! 0..100 do |i| | |
json.object! do | |
json.a i | |
json.b i | |
json.c i | |
json.d i | |
json.e i | |
json.subitems 0..100 do |j| | |
json.object! do | |
json.f i.to_s * j | |
json.g i.to_s * j | |
json.h i.to_s * j | |
json.i i.to_s * j | |
json.j i.to_s * j | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
# Everthing before this is run once initialy, after is the test | |
__SETUP__ | |
TurboStreamer::Template.encode FakeContext.new do |json| | |
json.object! do | |
json.cached do | |
json.cache! 'tscached' do | |
json.array! 0..100 do |i| | |
json.object! do | |
json.a i | |
json.b i | |
json.c i | |
json.d i | |
json.e i | |
json.subitems 0..100 do |j| | |
json.object! do | |
json.f i.to_s * j | |
json.g i.to_s * j | |
json.h i.to_s * j | |
json.i i.to_s * j | |
json.j i.to_s * j | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment