polymorphic_url_cache 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/polymorphic_url_cache.rb +31 -0
- data/lib/polymorphic_url_cache/version.rb +3 -0
- data/polymorphic_url_cache.gemspec +27 -0
- data/spec/polymorphic_url_cache_spec.rb +42 -0
- data/spec/spec_helper.rb +115 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 249c590f393c21424ac991b93a4233bd9313e891
|
4
|
+
data.tar.gz: 4ff53d073c88b265e88340d1290e17acfa8b9528
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e5c0a698f5738f7f8529155a075f1d3a30e5b9b96c1ebdce682c9f52af0c288d582ebb225a8fe8ac2f28b61ea0e4d6c2ea7ed1bc89faa7c24bb994c0cdbd371
|
7
|
+
data.tar.gz: c582f9f46120c8e4ffa26be49da98b0db5f3b7707d10dd0154aa035a03d0b3e8c5f93edc75b53b0063424d6a5bd1b16ebb8c24ea113cdeeb394a6a4e1f410e94
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Akira Matsuda
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# PolymorphicUrlCache
|
2
|
+
|
3
|
+
This plugin would double-speed your Rails app. In some cases.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'polymorphic_url_cache'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install polymorphic_url_cache
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Just bundle the gem.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/polymorphic_url_cache/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module PolymorphicUrlCache
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
alias_method_chain :url_for, :cache
|
5
|
+
end
|
6
|
+
|
7
|
+
URL_FOR_CACHE = {}
|
8
|
+
|
9
|
+
def url_for_with_cache(options = nil)
|
10
|
+
key = case options
|
11
|
+
when ActiveRecord::Base
|
12
|
+
[options.class, options.to_param]
|
13
|
+
when Array
|
14
|
+
return url_for_without_cache(options) if options.none? {|o| o.is_a? ActiveRecord::Base}
|
15
|
+
|
16
|
+
options.each_with_object([]) do |o, k|
|
17
|
+
if o.is_a? ActiveRecord::Base
|
18
|
+
k << [options.class, options.to_param]
|
19
|
+
else
|
20
|
+
k << o
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
return url_for_without_cache(options)
|
25
|
+
end
|
26
|
+
|
27
|
+
URL_FOR_CACHE[key] || (URL_FOR_CACHE[key] = url_for_without_cache(options))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ActionView::RoutingUrlFor.include PolymorphicUrlCache
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "polymorphic_url_cache"
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ["Akira Matsuda"]
|
9
|
+
spec.email = ["ronnie@dio.jp"]
|
10
|
+
spec.summary = 'A Rails plugin that aggressively caches the polymorphic url_for results'
|
11
|
+
spec.description = "This plugin might speed up your Rails app's slowest part, or might just break your app"
|
12
|
+
spec.homepage = 'https://github.com/amatsuda/polymorphic_url_cache'
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'rails'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency 'rspec', '< 2.9'
|
25
|
+
spec.add_development_dependency 'wrong'
|
26
|
+
spec.add_development_dependency 'sqlite3'
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PolymorphicUrlCache do
|
4
|
+
before do
|
5
|
+
@view = Class.new(ActionView::Base) { include Rails.application.routes.url_helpers }.new
|
6
|
+
PolymorphicUrlCache::URL_FOR_CACHE.clear
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'url_for' do
|
10
|
+
context 'when an AR object was given' do
|
11
|
+
describe 'conferences_path' do
|
12
|
+
before do
|
13
|
+
@view.url_for(Conference.new)
|
14
|
+
end
|
15
|
+
specify do
|
16
|
+
assert { PolymorphicUrlCache::URL_FOR_CACHE.size == 1 }
|
17
|
+
assert { PolymorphicUrlCache::URL_FOR_CACHE.first == [[Conference, nil], "/conferences"] }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'conference_path' do
|
22
|
+
before do
|
23
|
+
@conference = Conference.create!
|
24
|
+
@view.url_for(@conference)
|
25
|
+
end
|
26
|
+
specify do
|
27
|
+
assert { PolymorphicUrlCache::URL_FOR_CACHE.size == 1 }
|
28
|
+
assert { PolymorphicUrlCache::URL_FOR_CACHE.first == [[Conference, @conference.id.to_s], "/conferences/#{@conference.id.to_s}"] }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when something else than an AR object was given' do
|
34
|
+
before do
|
35
|
+
@view.url_for('/foo')
|
36
|
+
end
|
37
|
+
specify do
|
38
|
+
assert { PolymorphicUrlCache::URL_FOR_CACHE.size == 0 }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(__dir__)
|
5
|
+
|
6
|
+
require 'rails'
|
7
|
+
require 'active_record'
|
8
|
+
require 'action_controller/railtie'
|
9
|
+
require 'action_view/railtie'
|
10
|
+
require 'wrong/adapters/rspec'
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
13
|
+
|
14
|
+
module TestApp
|
15
|
+
class Application < Rails::Application
|
16
|
+
config.session_store :cookie_store, :key => '_myapp_session'
|
17
|
+
config.active_support.deprecation = :log
|
18
|
+
end
|
19
|
+
end
|
20
|
+
TestApp::Application.initialize!
|
21
|
+
|
22
|
+
class Conference < ActiveRecord::Base
|
23
|
+
end
|
24
|
+
|
25
|
+
class CreateAllTables < ActiveRecord::Migration
|
26
|
+
def self.up
|
27
|
+
create_table(:conferences) {|t| t.string :name }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.before :all do
|
33
|
+
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'conferences'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
TestApp::Application.routes.draw do
|
38
|
+
resources :conferences
|
39
|
+
end
|
40
|
+
|
41
|
+
require 'polymorphic_url_cache'
|
42
|
+
|
43
|
+
RSpec.configure do |config|
|
44
|
+
# rspec-expectations config goes here. You can use an alternate
|
45
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
46
|
+
# assertions if you prefer.
|
47
|
+
config.expect_with :rspec do |expectations|
|
48
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
49
|
+
# and `failure_message` of custom matchers include text for helper methods
|
50
|
+
# defined using `chain`, e.g.:
|
51
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
52
|
+
# # => "be bigger than 2 and smaller than 4"
|
53
|
+
# ...rather than:
|
54
|
+
# # => "be bigger than 2"
|
55
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
56
|
+
end
|
57
|
+
|
58
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
59
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
60
|
+
config.mock_with :rspec do |mocks|
|
61
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
62
|
+
# a real object. This is generally recommended, and will default to
|
63
|
+
# `true` in RSpec 4.
|
64
|
+
mocks.verify_partial_doubles = true
|
65
|
+
end
|
66
|
+
|
67
|
+
# The settings below are suggested to provide a good initial experience
|
68
|
+
# with RSpec, but feel free to customize to your heart's content.
|
69
|
+
=begin
|
70
|
+
# These two settings work together to allow you to limit a spec run
|
71
|
+
# to individual examples or groups you care about by tagging them with
|
72
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
73
|
+
# get run.
|
74
|
+
config.filter_run :focus
|
75
|
+
config.run_all_when_everything_filtered = true
|
76
|
+
|
77
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
78
|
+
# For more details, see:
|
79
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
80
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
81
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
82
|
+
config.disable_monkey_patching!
|
83
|
+
|
84
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
85
|
+
# be too noisy due to issues in dependencies.
|
86
|
+
config.warnings = true
|
87
|
+
|
88
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
89
|
+
# file, and it's useful to allow more verbose output when running an
|
90
|
+
# individual spec file.
|
91
|
+
if config.files_to_run.one?
|
92
|
+
# Use the documentation formatter for detailed output,
|
93
|
+
# unless a formatter has already been configured
|
94
|
+
# (e.g. via a command-line flag).
|
95
|
+
config.default_formatter = 'doc'
|
96
|
+
end
|
97
|
+
|
98
|
+
# Print the 10 slowest examples and example groups at the
|
99
|
+
# end of the spec run, to help surface which specs are running
|
100
|
+
# particularly slow.
|
101
|
+
config.profile_examples = 10
|
102
|
+
|
103
|
+
# Run specs in random order to surface order dependencies. If you find an
|
104
|
+
# order dependency and want to debug it, you can fix the order by providing
|
105
|
+
# the seed, which is printed after each run.
|
106
|
+
# --seed 1234
|
107
|
+
config.order = :random
|
108
|
+
|
109
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
110
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
111
|
+
# test failures related to randomization by passing the same `--seed` value
|
112
|
+
# as the one that triggered the failure.
|
113
|
+
Kernel.srand config.seed
|
114
|
+
=end
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polymorphic_url_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Matsuda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "<"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "<"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: wrong
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: This plugin might speed up your Rails app's slowest part, or might just
|
98
|
+
break your app
|
99
|
+
email:
|
100
|
+
- ronnie@dio.jp
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- MIT-LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/polymorphic_url_cache.rb
|
112
|
+
- lib/polymorphic_url_cache/version.rb
|
113
|
+
- polymorphic_url_cache.gemspec
|
114
|
+
- spec/polymorphic_url_cache_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
homepage: https://github.com/amatsuda/polymorphic_url_cache
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: A Rails plugin that aggressively caches the polymorphic url_for results
|
140
|
+
test_files:
|
141
|
+
- spec/polymorphic_url_cache_spec.rb
|
142
|
+
- spec/spec_helper.rb
|