Class: Railyard::Gemfile
- Inherits:
-
Object
- Object
- Railyard::Gemfile
- Defined in:
- lib/railyard/gemfile.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ Gemfile
constructor
A new instance of Gemfile.
- #update_version(number) ⇒ Object
Constructor Details
#initialize(path) ⇒ Gemfile
Returns a new instance of Gemfile.
4 5 6 |
# File 'lib/railyard/gemfile.rb', line 4 def initialize(path) @path = path end |
Instance Method Details
#update_version(number) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |