rails-diff 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b0a335992f7491133b576710e538fd0adc5d3bde79919e2fa60d145ae3e6055
4
- data.tar.gz: f429b3d0d895f23bbda625a29172e3528bc86db2cb1e74fc6803aa7d2105c65e
3
+ metadata.gz: f41070619ee42e4f9de3554fc4510a4801a65bc70c2a223a1547a2f46f6df746
4
+ data.tar.gz: c320a4ea5aaa7bb0a90894c721d4ff72cc83ae19aab47ddf9dce209bfc5be867
5
5
  SHA512:
6
- metadata.gz: abe0d4f2ae2cf533aefa251726547b2eda321758edbf14882fc5948314d0e72eab78c054b238661f127df065fa6da0956b3469b07e2d219e35a199442443908e
7
- data.tar.gz: 3bba7f7a5c9711601f7dcb11163947913103185f60a31dc3bd7f9e79c0b055fee8fad650a8abbb65c36b69deccec780f36b821c646216363f8a6286fcacb5318
6
+ metadata.gz: 7ed84dbd16eb5310e4d04c5a6cfa770c3dcbf4c217eb4647e8bde45108b8ffb32a2846e964a1d68ab74b85ee8132006f05d0b6e0bbf1bcf8bec1a5dddeb39ca6
7
+ data.tar.gz: 6b876207ceb2d4f40c7a02439ff50f127b0d81bf740816f71c00c253400c062170c6ccf99230fd213817c7871045c50f89a8ad70d24eea6bd8068e06bea2b51b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.0] - 2026-03-26
4
+
5
+ - `--ref` now accepts `rails --version` output (e.g., `--ref "Rails 7.2.3"` is converted to `v7.2.3`).
6
+
3
7
  ## [0.7.0] - 2026-03-17
4
8
 
5
9
  - Replace `diffy` with `difftastic` for better diff output with syntax highlighting.
@@ -76,6 +80,7 @@ M## [0.1.1] - 2025-02-21
76
80
 
77
81
  - Initial release
78
82
 
83
+ [0.8.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.8.0
79
84
  [0.7.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.7.0
80
85
  [0.6.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.6.0
81
86
  [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.0"
6
6
  end
7
7
  end
data/lib/rails/diff.rb CHANGED
@@ -16,27 +16,24 @@ module Rails
16
16
  CACHE_DIR = File.expand_path("#{ENV["HOME"]}/.rails-diff/cache")
17
17
 
18
18
  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:)
19
+ 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
20
  app_generator.create_template_app
22
21
 
23
22
  files
24
- .filter_map { |it| diff_with_header(it, app_generator.template_app_path) }
23
+ .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
25
24
  .join("\n")
26
25
  end
27
26
 
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:)
27
+ 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
28
  app_generator.create_template_app
31
29
  app_generator.install_app_dependencies
32
30
 
33
31
  app_generator.run_generator(generator_name, *args, skip, only)
34
- .filter_map { |it| diff_with_header(it, app_generator.template_app_path) }
32
+ .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
35
33
  .join("\n\n")
36
34
  end
37
35
 
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:)
36
+ 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
37
  app_generator.create_template_app
41
38
 
42
39
  default_skip = %w[app lib]
@@ -44,28 +41,28 @@ module Rails
44
41
 
45
42
  FileTracker.list_files(app_generator.template_app_path, skip: effective_skip, only:)
46
43
  .map { |f| f.delete_prefix("#{app_generator.template_app_path}/") }
47
- .filter_map { |it| diff_with_header(it, app_generator.template_app_path) }
44
+ .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
48
45
  .join("\n\n")
49
46
  end
50
47
 
51
48
  private
52
49
 
53
- def diff_with_header(file, template_app_path)
54
- diff = diff_file(file, template_app_path)
50
+ def diff_with_header(file, template_app_path, differ_class:)
51
+ diff = diff_file(file, template_app_path, differ_class:)
55
52
  return if diff.empty?
56
53
 
57
54
  header = "#{file} diff:"
58
55
  [header, "=" * header.size, diff].join("\n")
59
56
  end
60
57
 
61
- def diff_file(file, template_app_path)
58
+ def diff_file(file, template_app_path, differ_class:)
62
59
  rails_file = File.join(template_app_path, file)
63
60
  repo_file = File.join(Dir.pwd, file)
64
61
 
65
62
  return "File not found in the Rails template" unless File.exist?(rails_file)
66
63
  return "File not found in your repository" unless File.exist?(repo_file)
67
64
 
68
- differ = Difftastic::Differ.new(
65
+ differ = differ_class.new(
69
66
  color: :always,
70
67
  left_label: "Rails File (#{file})",
71
68
  right_label: "Repo File (#{file})"
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard