Class: DRG::Tasks::Gemfile
- Inherits:
-
Object
- Object
- DRG::Tasks::Gemfile
- Defined in:
- lib/drg/tasks/gemfile.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #find_by_name(name) ⇒ Object
-
#initialize(file = ::Bundler.default_gemfile) ⇒ Gemfile
constructor
A new instance of Gemfile.
- #lines ⇒ Object
- #remove_version(gem) ⇒ Object
- #rollback ⇒ Object
- #saved_lines ⇒ Object
-
#update(gem, version) ⇒ Object
Saves a copy of @lines before changing it (note that #dup and #clone weren’t working).
- #write ⇒ Object
Constructor Details
#initialize(file = ::Bundler.default_gemfile) ⇒ Gemfile
Returns a new instance of Gemfile.
6 7 8 |
# File 'lib/drg/tasks/gemfile.rb', line 6 def initialize(file = ::Bundler.default_gemfile) @file = file end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/drg/tasks/gemfile.rb', line 4 def file @file end |
Instance Method Details
#find_by_name(name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/drg/tasks/gemfile.rb', line 25 def find_by_name(name) lines.each_with_index.each do |line, index| next if line =~ /^\s*#/ next if line =~ /:?path:?\s*(=>)?\s*/ next if line =~ /:?git(hub)?:?\s*(=>)?\s*/ next if line =~ /@drg\s+(frozen|ignore|skip)/ return GemfileLine.new line, index, name if line =~ /gem\s*['"]#{name}["']/ end nil end |
#lines ⇒ Object
54 55 56 |
# File 'lib/drg/tasks/gemfile.rb', line 54 def lines @lines ||= File.readlines file end |
#remove_version(gem) ⇒ Object
19 20 21 22 23 |
# File 'lib/drg/tasks/gemfile.rb', line 19 def remove_version(gem) saved_lines << Marshal.load(Marshal.dump(lines)) lines[gem] = gem.remove_version write end |
#rollback ⇒ Object
44 45 46 47 48 |
# File 'lib/drg/tasks/gemfile.rb', line 44 def rollback return if saved_lines.empty? lines.replace saved_lines.pop write end |
#saved_lines ⇒ Object
50 51 52 |
# File 'lib/drg/tasks/gemfile.rb', line 50 def saved_lines @saved_lines ||= [] end |
#update(gem, version) ⇒ Object
Saves a copy of @lines before changing it (note that #dup and #clone weren’t working)
14 15 16 17 |
# File 'lib/drg/tasks/gemfile.rb', line 14 def update(gem, version) saved_lines << Marshal.load(Marshal.dump(lines)) lines[gem] = gem.update version end |
#write ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/drg/tasks/gemfile.rb', line 36 def write File.open file, 'wb' do |f| lines.each do |line| f << line end end end |