Class: Gemrat::Gemfile
- Inherits:
-
Object
- Object
- Gemrat::Gemfile
- Defined in:
- lib/gemrat/gemfile.rb
Defined Under Namespace
Classes: DuplicateGemFound
Instance Attribute Summary collapse
-
#needs_bundle ⇒ Object
(also: #needs_bundle?)
Returns the value of attribute needs_bundle.
Instance Method Summary collapse
- #add(gem) ⇒ Object
-
#initialize(path) ⇒ Gemfile
constructor
A new instance of Gemfile.
Constructor Details
#initialize(path) ⇒ Gemfile
Returns a new instance of Gemfile.
8 9 10 11 |
# File 'lib/gemrat/gemfile.rb', line 8 def initialize(path) self.path = path self.needs_bundle = false end |
Instance Attribute Details
#needs_bundle ⇒ Object Also known as: needs_bundle?
Returns the value of attribute needs_bundle.
5 6 7 |
# File 'lib/gemrat/gemfile.rb', line 5 def needs_bundle @needs_bundle end |
Instance Method Details
#add(gem) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gemrat/gemfile.rb', line 13 def add(gem) file = File.open(path, "a+") check(gem, file) if gem.add? file.write "\n#{gem}" puts "#{gem} added to your Gemfile.".green needs_bundle! elsif gem.update? contents = File.read(path) File.open(path,'w') do |f| f.print contents.gsub(/^.*#{gem.name}.*$/, "#{gem}") f.close end puts "Updated '#{gem.name}' to version '#{gem.version}'.".green needs_bundle! end ensure file.close end |