class Railyard::Gemfile

Public Class Methods

new(path) click to toggle source
# File lib/railyard/gemfile.rb, line 4
def initialize(path)
  @path = path
end

Public Instance Methods

update_version(number) click to toggle source
# File lib/railyard/gemfile.rb, line 8
def update_version(number)
  body  = read
  lines = body.split("\n")
  rails = lines.find { |line| line =~ /rails/ }

  if match = rails.match(/(\d[\d\.]{0,})/)
    new_rails = rails.gsub(match[1], number)
  else
    new_rails = "#{rails}, \"#{number}\""
  end

  body = lines.join("\n") + "\n"
  body.gsub!(rails, new_rails)

  write(body)
end

Private Instance Methods

read() click to toggle source
# File lib/railyard/gemfile.rb, line 27
def read
  File.read(@path)
end
write(body) click to toggle source
# File lib/railyard/gemfile.rb, line 31
def write(body)
  File.open(@path, "w") { |file| file.write(body) }
end