Class: Kompo::CopyGemfile

Inherits:
Taski::Task
  • Object
show all
Defined in:
lib/kompo/tasks/copy_gemfile.rb

Overview

Copy Gemfile, Gemfile.lock, and gemspec files to working directory if they exist

Instance Method Summary collapse

Instance Method Details

#cleanObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kompo/tasks/copy_gemfile.rb', line 44

def clean
  return unless @gemfile_exists

  work_dir = WorkDir.path
  return unless work_dir && Dir.exist?(work_dir)

  gemfile = File.join(work_dir, "Gemfile")
  gemfile_lock = File.join(work_dir, "Gemfile.lock")

  FileUtils.rm_f(gemfile)
  FileUtils.rm_f(gemfile_lock)

  # Clean up copied gemspec files
  (@gemspec_paths || []).each do |gemspec|
    FileUtils.rm_f(gemspec)
  end

  puts "Cleaned up Gemfile"
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kompo/tasks/copy_gemfile.rb', line 10

def run
  work_dir = WorkDir.path
  project_dir = Taski.args.fetch(:project_dir, Taski.env.working_directory) || Taski.env.working_directory

  # Skip Gemfile processing if --no-gemfile is specified
  if Taski.args[:no_gemfile]
    puts "Skipping Gemfile (--no-gemfile specified)"
    @gemfile_exists = false
    @gemspec_paths = []
    return
  end

  gemfile_path = File.join(project_dir, "Gemfile")
  gemfile_lock_path = File.join(project_dir, "Gemfile.lock")

  @gemfile_exists = File.exist?(gemfile_path)
  @gemspec_paths = []

  if @gemfile_exists
    FileUtils.cp(gemfile_path, work_dir)
    puts "Copied: Gemfile"

    if File.exist?(gemfile_lock_path)
      FileUtils.cp(gemfile_lock_path, work_dir)
      puts "Copied: Gemfile.lock"
    end

    # Copy gemspec files if Gemfile references gemspec
    copy_gemspec_if_needed(gemfile_path, project_dir, work_dir)
  else
    puts "No Gemfile found, skipping"
  end
end