Module: Rails::Diff

Defined in:
lib/rails/diff.rb,
lib/rails/diff/cli.rb,
lib/rails/diff/shell.rb,
lib/rails/diff/logger.rb,
lib/rails/diff/version.rb,
lib/rails/diff/rails_repo.rb,
lib/rails/diff/file_tracker.rb,
lib/rails/diff/rails_app_generator.rb

Defined Under Namespace

Modules: FileTracker, Logger, Shell Classes: CLI, RailsAppGenerator, RailsRepo

Constant Summary collapse

CACHE_DIR =
cache_dir
VERSION =
"0.8.1"

Class Method Summary collapse

Class Method Details

.cache_dirObject



17
18
19
20
21
22
# File 'lib/rails/diff.rb', line 17

def cache_dir
  xdg = ENV["XDG_CACHE_HOME"]
  base = (xdg && File.absolute_path?(xdg)) ? xdg : File.join(Dir.home, ".cache")

  File.join(base, "rails-diff")
end

.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) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/rails/diff.rb', line 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)
  app_generator.create_template_app

  files
    .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
    .join("\n")
end

.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) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rails/diff.rb', line 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)
  app_generator.create_template_app
  app_generator.install_app_dependencies

  app_generator.run_generator(generator_name, *args, skip, only)
    .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
    .join("\n\n")
end

.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) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rails/diff.rb', line 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)
  app_generator.create_template_app

  default_skip = %w[app lib]
  effective_skip = (default_skip + skip).uniq

  FileTracker.list_files(app_generator.template_app_path, skip: effective_skip, only:)
    .map { |f| f.delete_prefix("#{app_generator.template_app_path}/") }
    .filter_map { |it| diff_with_header(it, app_generator.template_app_path, differ_class:) }
    .join("\n\n")
end