rails-diff 0.7.0 → 0.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b0a335992f7491133b576710e538fd0adc5d3bde79919e2fa60d145ae3e6055
4
- data.tar.gz: f429b3d0d895f23bbda625a29172e3528bc86db2cb1e74fc6803aa7d2105c65e
3
+ metadata.gz: ff8a56490563255cb68662a1f669ddaa9a0d07071c0216d24e650705f8a76f81
4
+ data.tar.gz: 8e5a5d304686fd37bdd09fb55906a407642279648ec9c7f582623bcfa6691314
5
5
  SHA512:
6
- metadata.gz: abe0d4f2ae2cf533aefa251726547b2eda321758edbf14882fc5948314d0e72eab78c054b238661f127df065fa6da0956b3469b07e2d219e35a199442443908e
7
- data.tar.gz: 3bba7f7a5c9711601f7dcb11163947913103185f60a31dc3bd7f9e79c0b055fee8fad650a8abbb65c36b69deccec780f36b821c646216363f8a6286fcacb5318
6
+ metadata.gz: 3bf5a8ac6e8e6c44141f0e7fdd510e8a5d2a34f4325731341b2311a5f01ffe37ae3983f88b5542bc5638396036bb3046269c4e8da60997e76480b0ca1aca7bc9
7
+ data.tar.gz: 46584a9a3a70f9bbbdbfc1e19727fbc5b56c7de39644d2585efe08edb420e4de89c6b75b1c2092af9af93da4be9b64916446049acb08e9515a28cdecac4514b4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.1] - 2026-06-16
4
+
5
+ - Respect the XDG Base Directory spec for the cache location. Cache now lives at `$XDG_CACHE_HOME/rails-diff` (defaulting to `~/.cache/rails-diff`) instead of `~/.rails-diff/cache`. The old cache directory is no longer used and can be removed (PR #37).
6
+
7
+ ## [0.8.0] - 2026-03-26
8
+
9
+ - `--ref` now accepts `rails --version` output (e.g., `--ref "Rails 7.2.3"` is converted to `v7.2.3`).
10
+
3
11
  ## [0.7.0] - 2026-03-17
4
12
 
5
13
  - Replace `diffy` with `difftastic` for better diff output with syntax highlighting.
@@ -76,6 +84,8 @@ M## [0.1.1] - 2025-02-21
76
84
 
77
85
  - Initial release
78
86
 
87
+ [0.8.1]: https://github.com/matheusrich/rails-diff/releases/tag/v0.8.1
88
+ [0.8.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.8.0
79
89
  [0.7.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.7.0
80
90
  [0.6.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.6.0
81
91
  [0.5.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.5.0
data/README.md CHANGED
@@ -105,6 +105,12 @@ If this option is specified, the command will exit with a non-zero status code i
105
105
  Specify a tag, branch, or commit SHA to compare against. If not provided, the
106
106
  latest commit on main will be used by default. `--commit` is kept as an alias.
107
107
 
108
+ You can also pass `rails --version` output directly:
109
+
110
+ ```bash
111
+ rails-diff file Dockerfile --ref "$(rails --version)"
112
+ ```
113
+
108
114
  > [!NOTE]
109
115
  > When using a commit SHA, the full 40-character SHA is required (short SHAs are not supported).
110
116
 
@@ -3,12 +3,10 @@ require "digest"
3
3
  module Rails
4
4
  module Diff
5
5
  class RailsAppGenerator
6
- RAILSRC_PATH = "#{ENV["HOME"]}/.railsrc"
7
-
8
- def initialize(ref: nil, new_app_options: nil, no_cache: false, logger: Logger, cache_dir: Rails::Diff::CACHE_DIR)
6
+ def initialize(ref: nil, new_app_options: nil, no_cache: false, logger: Logger, cache_dir: Rails::Diff::CACHE_DIR, rails_repo: RailsRepo.new(logger:, cache_dir:))
9
7
  @new_app_options = new_app_options.to_s.split
10
- @rails_repo = RailsRepo.new(logger:, cache_dir:)
11
- @ref = ref
8
+ @rails_repo = rails_repo
9
+ @ref = normalize_ref(ref)
12
10
  @logger = logger
13
11
  @cache_dir = cache_dir
14
12
  clear_cache if no_cache
@@ -54,12 +52,22 @@ module Rails
54
52
 
55
53
  attr_reader :new_app_options, :rails_repo, :logger, :cache_dir
56
54
 
55
+ def normalize_ref(ref)
56
+ if ref&.start_with?("Rails ")
57
+ "v#{ref.delete_prefix("Rails ")}"
58
+ else
59
+ ref
60
+ end
61
+ end
62
+
57
63
  def ref = @ref ||= rails_repo.latest_commit
58
64
 
59
65
  def rails_cache_dir_key = "rails-#{ref.first(10)}"
60
66
 
67
+ def railsrc_path = "#{ENV["HOME"]}/.railsrc"
68
+
61
69
  def railsrc_options
62
- @railsrc_options ||= File.exist?(RAILSRC_PATH) ? File.readlines(RAILSRC_PATH) : []
70
+ @railsrc_options ||= File.exist?(railsrc_path) ? File.readlines(railsrc_path) : []
63
71
  end
64
72
 
65
73
  def app_name = @app_name ||= File.basename(Dir.pwd)
@@ -76,7 +84,7 @@ module Rails
76
84
  def generate_app
77
85
  rails_repo.install_dependencies
78
86
  if railsrc_options.any?
79
- logger.info "Using default options from #{RAILSRC_PATH}:\n\t > #{railsrc_options.join(" ")}"
87
+ logger.info "Using default options from #{railsrc_path}:\n\t > #{railsrc_options.join(" ")}"
80
88
  end
81
89
  rails_repo.new_app(template_app_path, rails_new_options)
82
90
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rails
4
4
  module Diff
5
- VERSION = "0.7.0"
5
+ VERSION = "0.8.1"
6
6
  end
7
7
  end
data/lib/rails/diff.rb CHANGED
@@ -13,30 +13,32 @@ require_relative "diff/version"
13
13
 
14
14
  module Rails
15
15
  module Diff
16
- CACHE_DIR = File.expand_path("#{ENV["HOME"]}/.rails-diff/cache")
17
-
18
16
  class << self
19
- def file(*files, no_cache: false, ref: nil, new_app_options: nil)
20
- app_generator = RailsAppGenerator.new(ref:, new_app_options:, no_cache:)
17
+ def cache_dir
18
+ xdg = ENV["XDG_CACHE_HOME"]
19
+ base = (xdg && File.absolute_path?(xdg)) ? xdg : File.join(Dir.home, ".cache")
20
+
21
+ File.join(base, "rails-diff")
22
+ end
23
+
24
+ def file(*files, no_cache: false, ref: nil, new_app_options: nil, app_generator: RailsAppGenerator.new(ref:, new_app_options:, no_cache:), differ_class: Difftastic::Differ)
21
25
  app_generator.create_template_app
22
26
 
23
27
  files
24
- .filter_map { |it| diff_with_header(it, app_generator.template_app_path) }
28
+ .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
25
29
  .join("\n")
26
30
  end
27
31
 
28
- def generated(generator_name, *args, no_cache: false, skip: [], only: [], ref: nil, new_app_options: nil)
29
- app_generator = RailsAppGenerator.new(ref:, new_app_options:, no_cache:)
32
+ def generated(generator_name, *args, no_cache: false, skip: [], only: [], ref: nil, new_app_options: nil, app_generator: RailsAppGenerator.new(ref:, new_app_options:, no_cache:), differ_class: Difftastic::Differ)
30
33
  app_generator.create_template_app
31
34
  app_generator.install_app_dependencies
32
35
 
33
36
  app_generator.run_generator(generator_name, *args, skip, only)
34
- .filter_map { |it| diff_with_header(it, app_generator.template_app_path) }
37
+ .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
35
38
  .join("\n\n")
36
39
  end
37
40
 
38
- def infra(no_cache: false, skip: [], only: [], ref: nil, new_app_options: nil)
39
- app_generator = RailsAppGenerator.new(ref:, new_app_options:, no_cache:)
41
+ def infra(no_cache: false, skip: [], only: [], ref: nil, new_app_options: nil, app_generator: RailsAppGenerator.new(ref:, new_app_options:, no_cache:), differ_class: Difftastic::Differ)
40
42
  app_generator.create_template_app
41
43
 
42
44
  default_skip = %w[app lib]
@@ -44,28 +46,28 @@ module Rails
44
46
 
45
47
  FileTracker.list_files(app_generator.template_app_path, skip: effective_skip, only:)
46
48
  .map { |f| f.delete_prefix("#{app_generator.template_app_path}/") }
47
- .filter_map { |it| diff_with_header(it, app_generator.template_app_path) }
49
+ .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
48
50
  .join("\n\n")
49
51
  end
50
52
 
51
53
  private
52
54
 
53
- def diff_with_header(file, template_app_path)
54
- diff = diff_file(file, template_app_path)
55
+ def diff_with_header(file, template_app_path, differ_class:)
56
+ diff = diff_file(file, template_app_path, differ_class:)
55
57
  return if diff.empty?
56
58
 
57
59
  header = "#{file} diff:"
58
60
  [header, "=" * header.size, diff].join("\n")
59
61
  end
60
62
 
61
- def diff_file(file, template_app_path)
63
+ def diff_file(file, template_app_path, differ_class:)
62
64
  rails_file = File.join(template_app_path, file)
63
65
  repo_file = File.join(Dir.pwd, file)
64
66
 
65
67
  return "File not found in the Rails template" unless File.exist?(rails_file)
66
68
  return "File not found in your repository" unless File.exist?(repo_file)
67
69
 
68
- differ = Difftastic::Differ.new(
70
+ differ = differ_class.new(
69
71
  color: :always,
70
72
  left_label: "Rails File (#{file})",
71
73
  right_label: "Repo File (#{file})"
@@ -74,5 +76,7 @@ module Rails
74
76
  differ.diff_files(rails_file, repo_file).chomp
75
77
  end
76
78
  end
79
+
80
+ CACHE_DIR = cache_dir
77
81
  end
78
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard