Class: Rrm::Gemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/rrm/filehandlers/gemfile.rb

Constant Summary collapse

FILENAME =
'Gemfile'
PATTERN =
/^ruby ['"](\d.\d.\d)['"]/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git) ⇒ Gemfile

Returns a new instance of Gemfile.



8
9
10
11
12
13
# File 'lib/rrm/filehandlers/gemfile.rb', line 8

def initialize(git)
  @content = File.read("#{git.dir.path}/#{FILENAME}")
  @git = git
rescue
  @content = nil
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/rrm/filehandlers/gemfile.rb', line 6

def content
  @content
end

#gitObject

Returns the value of attribute git.



6
7
8
# File 'lib/rrm/filehandlers/gemfile.rb', line 6

def git
  @git
end

#new_versionObject

Returns the value of attribute new_version.



6
7
8
# File 'lib/rrm/filehandlers/gemfile.rb', line 6

def new_version
  @new_version
end

Instance Method Details

#ruby_versionObject



26
27
28
# File 'lib/rrm/filehandlers/gemfile.rb', line 26

def ruby_version
  @ruby_version ||= @content.match(PATTERN).captures.first
end

#update!(new_version) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/rrm/filehandlers/gemfile.rb', line 15

def update!(new_version)
  new_content = content.gsub(/(^ruby ['"])([\d.]{1,5})(['"])/, ('\1'+new_version+'\3'))
  file = File.open("#{git.dir.path}/#{FILENAME}", 'w')
  file.puts new_content
  file.close
  git.commit_all("Updating #{FILENAME} to Ruby #{new_version}")
rescue
  Rrm.logger.debug("Could not update #{FILENAME} because #{$!.message}")
  nil
end