rails-diff 0.2.0 → 0.3.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: 1597a0a52bb69e722c40bdd8714a79d6ab42fcef23a844484c91ca70496d7e4b
4
- data.tar.gz: 92e9120a9d970073725b002ea0ae8a2144bfdc075b30ba02e637ce86fdcebee8
3
+ metadata.gz: 93b1be272240b33b7c9357f98d876b1816fab44a032f7f655cc3b3c65a6bc925
4
+ data.tar.gz: 8201af2847c96ac8bda63200fffcc9a45179f571f72fd695260422e383fee89e
5
5
  SHA512:
6
- metadata.gz: 55149e9e567a6a63d6f0b6af85351d29a26af4c48ca16a8053cf46768cb883bfc16c8a908ab89e8047897194802ded032145b58d185f62772d5e81ca308d5120
7
- data.tar.gz: 716c754d1e4ff11ba617007aceb4de23fdea5cae49daaeedf794f3c497ad307e02d1827c48944d3fc4621b74427e6dba76c48089d878f36141f17e15f1c7a87b
6
+ metadata.gz: 38ced646ec7b54baaed0a072be43cc2a78e7e15e6658363747611de84e403df14f1cfbebbec7d67732ee0c15e0d0fc5d1ac2bf8dcecafd1060ab15f4fab2fd51
7
+ data.tar.gz: 7e17923b6b90f24e2a8542e291862121d7f5cccd0587bf96fd28601b32d2c83234152bb98cd769a512af86076da057eaf97cdbd8fb399b7665f9123eabfc614e
data/CHANGELOG.md CHANGED
@@ -1,8 +1,23 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2025-02-23
4
+
5
+ - Allow passing options to generate the new application
6
+
7
+ ```sh
8
+ rails-diff file Gemfile --new-app-options="--database=postgresql"
9
+ ```
10
+
11
+ ## [0.2.1] - 2025-02-22
12
+
13
+ - Add missing version command
14
+ - Consistent error messages
15
+ - Ensure rails path exists and dependencies are installed
16
+
3
17
  ## [0.2.0] - 2025-02-21
4
18
 
5
19
  - Allow comparing a specific commit
20
+
6
21
  ```sh
7
22
  rails-diff file Dockerfile --commit 3e7640
8
23
  ```
@@ -23,6 +38,8 @@ M## [0.1.1] - 2025-02-21
23
38
 
24
39
  - Initial release
25
40
 
41
+ [0.3.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.3.0
42
+ [0.2.1]: https://github.com/matheusrich/rails-diff/releases/tag/v0.2.1
26
43
  [0.2.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.2.0
27
44
  [0.1.1]: https://github.com/matheusrich/rails-diff/releases/tag/v0.1.1
28
45
  [0.1.0]: https://github.com/matheusrich/rails-diff/releases/tag/v0.1.0
data/README.md CHANGED
@@ -78,6 +78,16 @@ If this option is specified, the command will exit with a non-zero status code i
78
78
  Specify the commit hash you want to compare against. If not provided, the latest
79
79
  commit on main will be used by default.
80
80
 
81
+ #### --new-app-options <options>
82
+
83
+ Specify additional options to be used with the `rails new` command. This allows you to customize the generated Rails application, for example, by specifying a different database.
84
+
85
+ Example:
86
+
87
+ ```bash
88
+ rails-diff file Dockerfile --new-app-options="--database=postgresql"
89
+ ```
90
+
81
91
  ## How it works
82
92
 
83
93
  When you run the diff, it will:
data/Rakefile CHANGED
@@ -6,4 +6,4 @@ require "rspec/core/rake_task"
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  task default: :spec
9
- task release: :spec
9
+ task build: :spec
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rails
4
4
  module Diff
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
data/lib/rails/diff.rb CHANGED
@@ -14,16 +14,16 @@ module Rails
14
14
  CACHE_DIR = File.expand_path("~/.rails-diff/cache")
15
15
 
16
16
  class << self
17
- def file(*files, no_cache: false, commit: nil)
17
+ def file(*files, no_cache: false, commit: nil, new_app_options: nil)
18
18
  clear_cache if no_cache
19
- ensure_template_app_exists(commit)
19
+ ensure_template_app_exists(commit, new_app_options)
20
20
 
21
21
  files.filter_map { |it| diff_with_header(it) }.join("\n")
22
22
  end
23
23
 
24
- def generated(generator_name, *args, no_cache: false, skip: [], commit: nil)
24
+ def generated(generator_name, *args, no_cache: false, skip: [], commit: nil, new_app_options: nil)
25
25
  clear_cache if no_cache
26
- ensure_template_app_exists(commit)
26
+ ensure_template_app_exists(commit, new_app_options)
27
27
  install_app_dependencies
28
28
 
29
29
  generated_files(generator_name, *args, skip)
@@ -33,21 +33,36 @@ module Rails
33
33
 
34
34
  private
35
35
 
36
+ def clear_cache
37
+ puts "Clearing cache"
38
+ FileUtils.rm_rf(CACHE_DIR)
39
+ end
40
+
41
+ def ensure_template_app_exists(commit, new_app_options)
42
+ FileUtils.mkdir_p(CACHE_DIR)
43
+ @new_app_options = new_app_options
44
+ @commit = commit || latest_commit
45
+ return if cached_app?
46
+
47
+ create_new_rails_app
48
+ end
49
+
36
50
  def template_app_path
37
- @template_app_path ||= File.join(CACHE_DIR, commit, app_name)
51
+ @template_app_path ||= File.join(CACHE_DIR, commit, new_app_options_hash, app_name)
38
52
  end
39
53
 
40
54
  def rails_path
41
- @rails_path ||= File.join(CACHE_DIR, "rails")
55
+ @rails_path ||= begin
56
+ File.join(CACHE_DIR, "rails").tap do |path|
57
+ unless File.exist?(path)
58
+ system("git clone --depth 1 #{RAILS_REPO} #{path} >/dev/null 2>&1")
59
+ end
60
+ end
61
+ end
42
62
  end
43
63
 
44
64
  def app_name = @app_name ||= File.basename(Dir.pwd)
45
65
 
46
- def clear_cache
47
- puts "Clearing cache..."
48
- FileUtils.rm_rf(CACHE_DIR)
49
- end
50
-
51
66
  def list_files(dir, skip = [])
52
67
  Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).reject do |it|
53
68
  File.directory?(it) ||
@@ -87,7 +102,7 @@ module Rails
87
102
  def install_app_dependencies
88
103
  Dir.chdir(template_app_path) do
89
104
  unless system("bundle check >/dev/null 2>&1")
90
- puts "Installing application dependencies..."
105
+ puts "Installing application dependencies"
91
106
  system("bundle install >/dev/null 2>&1")
92
107
  end
93
108
  end
@@ -108,21 +123,12 @@ module Rails
108
123
  ).to_s(:color).chomp
109
124
  end
110
125
 
111
- def ensure_template_app_exists(commit)
112
- FileUtils.mkdir_p(CACHE_DIR)
113
- @commit = commit || latest_commit
114
- return if cached_app?
115
-
116
- FileUtils.rm_rf(template_app_path)
117
- create_new_rails_app
118
- end
119
-
120
126
  def cached_app?
121
- File.exist?(template_app_path) && !rails_updated?
127
+ File.exist?(template_app_path) && !out_of_date_rails?
122
128
  end
123
129
 
124
- def rails_updated?
125
- return true if !File.exist?(rails_path)
130
+ def out_of_date_rails?
131
+ return true unless File.exist?(rails_path)
126
132
 
127
133
  Dir.chdir(rails_path) do
128
134
  system("git fetch origin main >/dev/null 2>&1")
@@ -139,10 +145,6 @@ module Rails
139
145
  end
140
146
 
141
147
  def create_new_rails_app
142
- unless File.exist?(rails_path)
143
- system("git clone --depth 1 #{RAILS_REPO} #{rails_path} >/dev/null 2>&1")
144
- end
145
-
146
148
  Dir.chdir(rails_path) do
147
149
  checkout_rails
148
150
  generate_app
@@ -150,9 +152,15 @@ module Rails
150
152
  end
151
153
 
152
154
  def generate_app
155
+ FileUtils.rm_rf(template_app_path)
153
156
  Dir.chdir("railties") do
154
- puts "Generating new Rails application..."
155
- system("bundle exec rails new #{template_app_path} --main --skip-bundle --force --skip-test --skip-system-test --quiet")
157
+ unless system("bundle check >/dev/null 2>&1")
158
+ puts "Installing Rails dependencies"
159
+ system("bundle install >/dev/null 2>&1")
160
+ end
161
+
162
+ puts "Generating new Rails application"
163
+ system("bundle exec rails new #{template_app_path} --main --skip-bundle --force --skip-test --skip-system-test --quiet #{new_app_options}")
156
164
  end
157
165
  end
158
166
 
@@ -163,17 +171,24 @@ module Rails
163
171
 
164
172
  def commit = @commit
165
173
 
174
+ def new_app_options = @new_app_options
175
+
166
176
  def latest_commit
167
177
  Dir.chdir(rails_path) do
168
178
  `git rev-parse origin/main`.strip
169
179
  end
170
180
  end
181
+
182
+ def new_app_options_hash
183
+ Digest::SHA256.hexdigest(new_app_options.to_s)
184
+ end
171
185
  end
172
186
 
173
187
  class CLI < Thor
174
188
  class_option :no_cache, type: :boolean, desc: "Clear cache before running", aliases: ["--clear-cache"]
175
189
  class_option :fail_on_diff, type: :boolean, desc: "Fail if there are differences"
176
190
  class_option :commit, type: :string, desc: "Compare against a specific commit"
191
+ class_option :new_app_options, type: :string, desc: "Options to pass to the rails new command"
177
192
 
178
193
  def self.exit_on_failure? = true
179
194
 
@@ -181,7 +196,7 @@ module Rails
181
196
  def file(*files)
182
197
  abort "Please provide at least one file to compare" if files.empty?
183
198
 
184
- diff = Rails::Diff.file(*files, no_cache: options[:no_cache], commit: options[:commit])
199
+ diff = Rails::Diff.file(*files, no_cache: options[:no_cache], commit: options[:commit], new_app_options: options[:new_app_options])
185
200
  return if diff.empty?
186
201
 
187
202
  options[:fail] ? abort(diff) : puts(diff)
@@ -190,11 +205,17 @@ module Rails
190
205
  desc "generated GENERATOR [args]", "Compare files that would be created by a Rails generator"
191
206
  option :skip, type: :array, desc: "Skip specific files or directories", aliases: ["-s"], default: []
192
207
  def generated(generator_name, *args)
193
- diff = Rails::Diff.generated(generator_name, *args, no_cache: options[:no_cache], skip: options[:skip], commit: options[:commit])
208
+ diff = Rails::Diff.generated(generator_name, *args, no_cache: options[:no_cache], skip: options[:skip], commit: options[:commit], new_app_options: options[:new_app_options])
194
209
  return if diff.empty?
195
210
 
196
211
  options[:fail] ? abort(diff) : puts(diff)
197
212
  end
213
+
214
+ map %w[--version -v] => :__version
215
+ desc "--version, -v", "print the version"
216
+ def __version
217
+ puts VERSION
218
+ end
198
219
  end
199
220
  end
200
221
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-22 00:00:00.000000000 Z
10
+ date: 2025-02-23 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails