Class: Freezer
- Inherits:
-
Object
- Object
- Freezer
- Defined in:
- lib/frozen_gems/freezer.rb
Instance Method Summary collapse
- #cp_gemfile ⇒ Object
-
#initialize(gemfile_path) ⇒ Freezer
constructor
A new instance of Freezer.
- #overwrite ⇒ Object
- #overwrite_gemfile ⇒ Object
- #replace_gemfile ⇒ Object
- #tmpfile_path ⇒ Object
Constructor Details
#initialize(gemfile_path) ⇒ Freezer
Returns a new instance of Freezer.
4 5 6 7 |
# File 'lib/frozen_gems/freezer.rb', line 4 def initialize(gemfile_path) @gemfile_path = gemfile_path @tmpfile_path = tmpfile_path end |
Instance Method Details
#cp_gemfile ⇒ Object
38 39 40 41 |
# File 'lib/frozen_gems/freezer.rb', line 38 def cp_gemfile return unless gemfile? FileUtils.cp(@gemfile_path, @tmpfile_path) end |
#overwrite ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/frozen_gems/freezer.rb', line 15 def overwrite return unless gemfile? && tmpfile? gemfile = File.open(@gemfile_path) tmpfile = File.open(@tmpfile_path, 'w') regex = /^\s*gem ['"]([-\w]+)['"](,.*)?/ gems_hash = Parser.new(@gemfile_path).unfrozen_gems_hash gemfile.each do |line| name = line.scan(regex).flatten.first if !name.nil? && !gems_hash[name].nil? line.chomp! << ", '#{gems_hash[name]}'\n" end tmpfile.write(line) end gemfile.close tmpfile.close end |
#overwrite_gemfile ⇒ Object
9 10 11 12 13 |
# File 'lib/frozen_gems/freezer.rb', line 9 def overwrite_gemfile cp_gemfile overwrite replace_gemfile end |
#replace_gemfile ⇒ Object
43 44 45 46 47 48 |
# File 'lib/frozen_gems/freezer.rb', line 43 def replace_gemfile if gemfile? && tmpfile? FileUtils.rm_f(@gemfile_path) FileUtils.mv(@tmpfile_path, @gemfile_path) end end |
#tmpfile_path ⇒ Object
34 35 36 |
# File 'lib/frozen_gems/freezer.rb', line 34 def tmpfile_path File.join(File.dirname(@gemfile_path), TMPFILE) end |