Sha256: a91ca504daf0ab928c0c72fee6c4dbeeec9f9c14272f3e3c3f551f0548013cd8

Contents?: true

Size: 943 Bytes

Versions: 2

Compression:

Stored size: 943 Bytes

Contents

module Pumper
  class UpdatingProject
    class UndefinedGem < StandardError; end

    attr_reader :project

    def initialize(project, is_absolute_path)
      @project = project
      @is_absolute_path = is_absolute_path
      @gemfile = gemfile_path
    end

    def bump_version!(specification)
      text = File.read(@gemfile)
      if gem_defined?(text, specification.name)
        File.open(@gemfile, 'w') do |file|
          file.puts(text.gsub(/#{ gem_name(specification.name) }.*/, specification.for_gemfile))
        end
      else
        raise UpdatingProject::UndefinedGem
      end
    end

    def path
      @is_absolute_path ?
        @project :
        File.join(Dir.pwd, "../#{ @project }")
    end

    private

    def gemfile_path
      "#{ path }/Gemfile"
    end

    def gem_defined?(gemfile_text, gem)
      gemfile_text.include?(gem_name(gem))
    end

    def gem_name(gem)
      "gem '#{ gem }'"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pumper-1.0.1 lib/pumper/updating_project.rb
pumper-0.0.1 lib/pumper/updating_project.rb