Sha256: 9f19d90f444428302af70ffc18fa1507594a961f9ff778bf05b334bf56753d0e

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

class InvocaGems::GemfileLine
  attr_reader :gemfile, :line, :index
  attr_reader :gem_name, :gem_version, :gem_ref, :gem_git, :gem_github, :gem_options, :gem_options

  def initialize(gemfile, line, index)
    @gemfile = gemfile
    @line = line
    @index = index
    @prefix = @line.match(/\A(\s*)gem/)[1]

    instance_eval(line)
  end

  def save!
    gemfile.save!(self)
  end

  def gem(name, *args)
    @gem_name    = name
    @gem_options = args.last.is_a?(Hash) ? args.pop.dup : {}
    @gem_version = args.first || ">= 0"
    @gem_branch  = @gem_options[:branch] || 'master'
    @gem_ref     = @gem_options.delete(:ref)
    @gem_git     = @gem_options.delete(:git)
    @gem_github  = @gem_options.delete(:github)
  end

  def update_as_path(path)
    @line = [
      "#{@prefix}gem ",
      "'#{gem_name}',".ljust(24),
      " path: '#{path}'"
    ].join('')
  end

  # TODO - Perfer branch before ref.
  # TODO - handle local branch...
  def update_as_github(gem_version, uri, sha)
    @line = [
      "#{@prefix}gem ",
      "'#{gem_name}',".ljust(24),
      " '#{gem_version}', ".ljust(11),
      "git: '#{uri}',".ljust(56),
      "ref: '#{sha}'"
    ].join('')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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