class InvocaGems::Gemspec def initialize(path) @path = path @lines = File.readlines(path).map(&:chomp) end def find(gem_name) index = @lines.find_index { |l| l =~ /\A\s*\S+\s+[\'\"]#{gem_name}[\'\"]/ } or InvocaGems::Presenter.stop_with_message "could not find gem #{gem_name} in #{@path}" InvocaGems::GemspecLine.new(self, gem_name, @lines[index], index) end def save!(gemspec) update_gemspec(gemspec) File.open(@path, "w") { |f| f.write(@lines.join("\n") + "\n") } end private def update_gemspec(gemspec) @lines = @lines[0, gemspec.index] + [gemspec.line] + @lines[gemspec.index+1..-1] end end