asset_ram 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/asset_ram.gemspec +35 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/asset_ram/version.rb +5 -0
- data/lib/asset_ram.rb +54 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 201c96bf0cd23662ec2b7b3f68ebc17935a38a2ade97c1d3c025e7efe1492f28
|
4
|
+
data.tar.gz: 0640c99917e1d5bd6d064f34ecffee34d34e9459ae529c787c89ea02c1b1d449
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e259782f7f9b0bbc2129cf453b43d7e3889f35fe0ca6f5b98ed737977ccd21a46f773fdfaf8abdab62f67b2218557ee211038c22aca08454e9b378fcf4e0482
|
7
|
+
data.tar.gz: a7a2c855608200a56146ab8aed9f8c0994e01a452c41b72e45073bfa0bcd9b955bb2f6d32e748aa41632c58d61c29ee6c6765e5cc9826ea6c09c750421023aaf
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Robb Shecter
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# AssetRam
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/asset_ram`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'asset_ram'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install asset_ram
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/asset_ram.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/asset_ram.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/asset_ram/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "asset_ram"
|
7
|
+
spec.version = AssetRam::VERSION
|
8
|
+
spec.authors = ["Robb Shecter"]
|
9
|
+
spec.email = ["robb@public.law"]
|
10
|
+
|
11
|
+
spec.summary = "Improves Rails performance by caching asset path calculations"
|
12
|
+
spec.homepage = "https://github.com/dogweather/asset_ram"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.4.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/dogweather/asset_ram"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
32
|
+
|
33
|
+
# For more information and examples about making a new gem, checkout our
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "asset_ram"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/asset_ram.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "asset_ram/version"
|
4
|
+
|
5
|
+
#
|
6
|
+
# Use in views to cache the asset path computation.
|
7
|
+
#
|
8
|
+
# For example, in an ERB file:
|
9
|
+
#
|
10
|
+
# = AssetRam::Helper.cache { favicon_link_tag('favicon/favicon.ico', rel: 'icon') }
|
11
|
+
#
|
12
|
+
# The calculated asset paths are keyed by source file name and line number.
|
13
|
+
# The results are stored in RAM.
|
14
|
+
#
|
15
|
+
# Sometimes, a key is needed if the code is run in different contexts, like
|
16
|
+
# a multi-tenant site:
|
17
|
+
#
|
18
|
+
# = AssetRam::Helper.cache(key: site) { stylesheet_link_tag("themes/#{site}", media: nil) }
|
19
|
+
#
|
20
|
+
#
|
21
|
+
module AssetRam
|
22
|
+
class Error < StandardError; end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Our own asset helper which memoizes Rails' asset helper calls.
|
26
|
+
class Helper
|
27
|
+
|
28
|
+
##
|
29
|
+
# For testing the gains from caching with this library.
|
30
|
+
# Set to true to disable caching.
|
31
|
+
NO_CACHE = false
|
32
|
+
|
33
|
+
@@_cache = {}
|
34
|
+
|
35
|
+
|
36
|
+
def self.cache(key: '', &blk)
|
37
|
+
return yield if NO_CACHE
|
38
|
+
|
39
|
+
cache_key = blk.source_location
|
40
|
+
cache_key << key if key.present?
|
41
|
+
|
42
|
+
if !@@_cache.has_key?(cache_key)
|
43
|
+
# Using WARN level because it should only be output
|
44
|
+
# once during any Rails run. If its output multiple
|
45
|
+
# times, then caching isn't working correctly.
|
46
|
+
Rails.logger.warn("Caching #{cache_key}")
|
47
|
+
@@_cache[cache_key] = yield
|
48
|
+
end
|
49
|
+
|
50
|
+
@@_cache.fetch(cache_key)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asset_ram
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robb Shecter
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- robb@public.law
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- asset_ram.gemspec
|
27
|
+
- bin/console
|
28
|
+
- bin/setup
|
29
|
+
- lib/asset_ram.rb
|
30
|
+
- lib/asset_ram/version.rb
|
31
|
+
homepage: https://github.com/dogweather/asset_ram
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata:
|
35
|
+
homepage_uri: https://github.com/dogweather/asset_ram
|
36
|
+
source_code_uri: https://github.com/dogweather/asset_ram
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.4.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.2.28
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Improves Rails performance by caching asset path calculations
|
56
|
+
test_files: []
|