Sha256: 35457616a794410c8d290d64792c479d28f0c890d15251e83f46eaefe63da8be

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
invoca_gems-0.1.0 lib/invoca_gems/gemspec.rb