Sha256: f2e64de7d790f1ebffff20d3cfe68a3e0603885ecfbf36e36014804cb4c193b5

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'fileutils'
require 'anvil/task'
require 'anvil/rubygems'

class Gem::BuildTask < Anvil::Task
  description 'Builds a gem for you and can install it on your system.'

  parser do
    arguments %w(gemspec_file)

    on('-i', '--[no-]install', 'Install gem') do |i|
      options[:install] = i
    end
  end

  attr_reader :gemspec_file, :options

  def initialize(gemspec_file, options = {})
    @gemspec_file = gemspec_file
    @options = options
  end

  def task
    path = File.dirname(gemspec_file)

    Dir.chdir(path) do
      gem_file = build_gem(gemspec_file)
      Anvil::Rubygems.install gem_file if install?

      gem_file
    end
  end

  def build_gem(gemspec_file)
    rubygems_output = Anvil::Rubygems.build(gemspec_file)
    gem_file        = extract_gem_file(rubygems_output)

    FileUtils.mkdir_p('pkg')
    FileUtils.move(gem_file, 'pkg')

    File.expand_path("pkg/#{gem_file}")
  end

  def extract_gem_file(output)
    output.match(/File: (.*)$/)[1]
  end

  def install?
    options.fetch(:install, true)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
anvil-core-0.6.0 lib/tasks/gem/build_task.rb
anvil-core-0.5.0 lib/tasks/gem/build_task.rb