Class: Ruby::Reforge::VersionUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/reforge/version_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ VersionUpdater

Returns a new instance of VersionUpdater.



8
9
10
# File 'lib/ruby/reforge/version_updater.rb', line 8

def initialize(root_path)
  @root_path = root_path
end

Instance Method Details

#detect_current_versionObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby/reforge/version_updater.rb', line 38

def detect_current_version
  # Try .ruby-version first
  ruby_version_path = File.join(@root_path, ".ruby-version")
  if File.exist?(ruby_version_path)
    version = File.read(ruby_version_path).strip
    return version if version.match?(/^\d+\.\d+\.\d+/)
  end

  # Try Gemfile
  gemfile_path = File.join(@root_path, "Gemfile")
  if File.exist?(gemfile_path)
    content = File.read(gemfile_path)
    if match = content.match(/ruby\s+['"]([\d.]+)['"]/)
      return normalize_version(match[1])
    end
  end

  # Try gemspec
  Dir.glob(File.join(@root_path, "**/*.gemspec")).each do |gemspec_path|
    content = File.read(gemspec_path)
    if match = content.match(/required_ruby_version\s*[>=<]+\s*['"]([\d.]+)['"]/)
      return normalize_version(match[1])
    end
  end

  nil
end

#update(target_version) ⇒ Object



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
# File 'lib/ruby/reforge/version_updater.rb', line 12

def update(target_version)
  updated_files = []

  # Update .ruby-version
  ruby_version_path = File.join(@root_path, ".ruby-version")
  if File.exist?(ruby_version_path)
    File.write(ruby_version_path, "#{target_version}\n")
    updated_files << ".ruby-version"
  end

  # Update Gemfile
  gemfile_path = File.join(@root_path, "Gemfile")
  if File.exist?(gemfile_path)
    update_gemfile(gemfile_path, target_version)
    updated_files << "Gemfile"
  end

  # Update gemspec files
  Dir.glob(File.join(@root_path, "**/*.gemspec")).each do |gemspec_path|
    update_gemspec(gemspec_path, target_version)
    updated_files << gemspec_path
  end

  updated_files
end