rails-cdn-optimizer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/rubyonrails.yml +26 -0
- data/.ruby-version +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +8 -0
- data/lib/rails_cdn_optimizer/analyzer.rb +46 -0
- data/lib/rails_cdn_optimizer/version.rb +6 -0
- data/lib/rails_cdn_optimizer.rb +15 -0
- data/lib/tasks/cdn_optimizer.rake +14 -0
- data/sig/rails/cdn/optimizer.rbs +8 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a1e82aa9167fa8f6bf4ec7b3edd9077fe8e92227c65f8446602085d3aa6e6e3
|
4
|
+
data.tar.gz: 91c6b271f5078ef1a0b3e253f0d5660fc975751fcd7855e79f3ad9eedbc159e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae28e59b35565006918fed5ff809fc37130fda599672d82ea82c541bbdd22a27e83407c4d55dadbd998ea1775e7a23f709b0955b5c375afb5cb3a622a879100c
|
7
|
+
data.tar.gz: e9fbd9e2e5803b68cd4fb1e2dc0714129e71f7a66a10dbcacd2b1fb93eabefb60d7b08dafc807a5828cfcab24eb595cf000f3911317eb8190d494a182612c12e
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@78c01b705fd9d5ad960d432d3a0cfa341d50e410 # v1.179.1
|
18
|
+
with:
|
19
|
+
ruby-version: 3.2.0
|
20
|
+
bundler-cache: true
|
21
|
+
|
22
|
+
- name: Install dependencies
|
23
|
+
run: bundle install
|
24
|
+
|
25
|
+
- name: Run RSpec tests
|
26
|
+
run: bundle exec rspec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 mrmalvi
|
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,41 @@
|
|
1
|
+
# RailsCdnOptimizer
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/rails-cdn-optimizer)
|
4
|
+
|
5
|
+
RailsCdnOptimizer analyzes your Rails app's asset pipeline, detects large files, and suggests CDN caching rules to improve performance.
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- Analyze `app/assets`, `lib/assets`, and `vendor/assets`
|
12
|
+
- Detect large files that may slow down page load
|
13
|
+
- Suggest caching headers for CDN optimization
|
14
|
+
- Generate JSON report for integration with monitoring tools
|
15
|
+
- Easy integration with Rake tasks
|
16
|
+
|
17
|
+
---
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'rails-cdn-optimizer'
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
TODO: Write usage instructions here
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
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.
|
35
|
+
|
36
|
+
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).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails-cdn-optimizer.
|
41
|
+
# rails-cdn-optimizer
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'find'
|
2
|
+
require 'pathname'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module RailsCdnOptimizer
|
6
|
+
class Analyzer
|
7
|
+
attr_reader :asset_path, :cdn_host, :max_asset_size_kb
|
8
|
+
|
9
|
+
def initialize(asset_path: "app/assets", cdn_host: nil, max_asset_size_kb: 500)
|
10
|
+
@asset_path = Pathname.new(asset_path)
|
11
|
+
@cdn_host = cdn_host
|
12
|
+
@max_asset_size_kb = max_asset_size_kb
|
13
|
+
end
|
14
|
+
|
15
|
+
# Analyze all files in asset_path
|
16
|
+
def analyze
|
17
|
+
report = []
|
18
|
+
|
19
|
+
return report unless asset_path.exist?
|
20
|
+
|
21
|
+
Find.find(asset_path.to_s) do |file|
|
22
|
+
next unless File.file?(file)
|
23
|
+
|
24
|
+
size_kb = (File.size(file).to_f / 1024).round(2)
|
25
|
+
suggestion = size_kb > max_asset_size_kb ? "Consider optimizing" : "OK"
|
26
|
+
cdn_header = cdn_host ? "Cache-Control: max-age=31536000, immutable" : "Not configured"
|
27
|
+
|
28
|
+
report << {
|
29
|
+
path: Pathname.new(file).relative_path_from(asset_path).to_s,
|
30
|
+
size_kb: size_kb,
|
31
|
+
suggestion: suggestion,
|
32
|
+
cdn_header: cdn_header
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
report
|
37
|
+
end
|
38
|
+
|
39
|
+
# Generate JSON report
|
40
|
+
def generate_json_report(file = "cdn_report.json")
|
41
|
+
report = analyze
|
42
|
+
File.write(file, JSON.pretty_generate(report))
|
43
|
+
file
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require "rails_cdn_optimizer/analyzer"
|
3
|
+
|
4
|
+
module RailsCdnOptimizer
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :config
|
9
|
+
|
10
|
+
def configure
|
11
|
+
self.config ||= OpenStruct.new
|
12
|
+
yield(config)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require_relative '../../lib/rails_cdn_optimizer/analyzer'
|
3
|
+
|
4
|
+
namespace :cdn do
|
5
|
+
desc "Analyze assets and generate CDN report"
|
6
|
+
task :analyze do
|
7
|
+
analyzer = RailsCdnOptimizer::Analyzer.new(
|
8
|
+
asset_path: "app/assets",
|
9
|
+
cdn_host: RailsCdnOptimizer.config&.cdn_host
|
10
|
+
)
|
11
|
+
file = analyzer.generate_json_report
|
12
|
+
puts "Report generated: #{file}"
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-cdn-optimizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mrmalvi
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: Rails Cdn Optimizer analyzes your Rails app's asset pipeline, detects
|
13
|
+
large files, suggests CDN caching rules, and helps improve performance automatically.
|
14
|
+
email:
|
15
|
+
- malviyak00@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".github/workflows/rubyonrails.yml"
|
21
|
+
- ".ruby-version"
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/rails_cdn_optimizer.rb
|
26
|
+
- lib/rails_cdn_optimizer/analyzer.rb
|
27
|
+
- lib/rails_cdn_optimizer/version.rb
|
28
|
+
- lib/tasks/cdn_optimizer.rake
|
29
|
+
- sig/rails/cdn/optimizer.rbs
|
30
|
+
homepage: https://github.com/mrmalvi/rails-cdn-optimizer
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
homepage_uri: https://github.com/mrmalvi/rails-cdn-optimizer
|
35
|
+
source_code_uri: https://github.com/mrmalvi/rails-cdn-optimizer
|
36
|
+
changelog_uri: https://github.com/mrmalvi/rails-cdn-optimizer/blob/main/CHANGELOG.md
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.6.0
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubygems_version: 3.6.9
|
52
|
+
specification_version: 4
|
53
|
+
summary: 'Rails CDN Optimizer: Analyze and optimize asset pipeline with CDN suggestions.'
|
54
|
+
test_files: []
|