class Bumpversion::Writer

Public Class Methods

new(options, reader) click to toggle source
# File lib/bumpversion/writer.rb, line 3
def initialize(options, reader)
  @options = options
  @reader = reader
end

Public Instance Methods

content_config_file() click to toggle source
# File lib/bumpversion/writer.rb, line 13
def content_config_file
  @content_config_file ||= File.read(@options[:config_file])
end
reader_files() click to toggle source
# File lib/bumpversion/writer.rb, line 8
def reader_files
  @reader.reader!
  @reader.files_to_write
end
update_config_file!() click to toggle source
# File lib/bumpversion/writer.rb, line 26
def update_config_file!
  new_content = content_config_file.gsub(@options[:current_version], @options[:new_version])
  File.write(@options[:config_file], new_content)
end
validate!() click to toggle source
# File lib/bumpversion/writer.rb, line 17
def validate!
  file_exists = File.exist? @options[:config_file]
  file_has_current_version = (file_exists && content_config_file.include?("current-version"))
  file_current_version_match = file_has_current_version && content_config_file.include?(@options[:current_version])
  valid = !file_exists || !file_has_current_version || file_current_version_match

  raise "Version File does not Match with Current Version" unless valid
end
write!() click to toggle source
# File lib/bumpversion/writer.rb, line 31
def write!
  reader_files.each do |file_to_write|
    validate!

    new_content = file_to_write[:content].gsub(@options[:current_version], @options[:new_version])
    File.write(file_to_write[:filename], new_content)

    update_config_file!
  end
end