Class: Gem::BuildTask

Inherits:
Anvil::Task
  • Object
show all
Defined in:
lib/tasks/gem/build_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemspec_file, options = {}) ⇒ BuildTask

Returns a new instance of BuildTask.



18
19
20
21
# File 'lib/tasks/gem/build_task.rb', line 18

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

Instance Attribute Details

#gemspec_fileObject (readonly)

Returns the value of attribute gemspec_file.



16
17
18
# File 'lib/tasks/gem/build_task.rb', line 16

def gemspec_file
  @gemspec_file
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/tasks/gem/build_task.rb', line 16

def options
  @options
end

Instance Method Details

#build_gem(gemspec_file) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/tasks/gem/build_task.rb', line 34

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

#extract_gem_file(output) ⇒ Object



44
45
46
# File 'lib/tasks/gem/build_task.rb', line 44

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

#install?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/tasks/gem/build_task.rb', line 48

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

#taskObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/tasks/gem/build_task.rb', line 23

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