Class: Gemsmith::Rake::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/gemsmith/rake/builder.rb

Overview

Provides gem build functionality. Meant to be wrapped in Rake tasks.

Instance Method Summary collapse

Constructor Details

#initialize(tocer: Tocer::Writer, shell: Bundler::UI::Shell.new, kernel: Kernel) ⇒ Builder

Returns a new instance of Builder.



11
12
13
14
15
# File 'lib/gemsmith/rake/builder.rb', line 11

def initialize tocer: Tocer::Writer, shell: Bundler::UI::Shell.new, kernel: Kernel
  @tocer = tocer
  @shell = shell
  @kernel = kernel
end

Instance Method Details

#build(gem_spec) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gemsmith/rake/builder.rb', line 34

def build gem_spec
  path = package_path gem_spec

  if kernel.system("gem build #{gem_spec.name}.gemspec")
    FileUtils.mkdir_p "pkg"
    FileUtils.mv gem_spec.package_file_name, path
    shell.confirm "Built: #{path}."
  else
    shell.error "Unable to build: #{path}."
  end
end

#cleanObject



23
24
25
26
# File 'lib/gemsmith/rake/builder.rb', line 23

def clean
  FileUtils.rm_rf "pkg"
  shell.confirm "Cleaned gem artifacts."
end

#docObject



17
18
19
20
21
# File 'lib/gemsmith/rake/builder.rb', line 17

def doc
  readme = File.join Dir.pwd, "README.md"
  tocer.new(readme).write
  shell.confirm "Updated gem documentation."
end

#install(gem_spec) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/gemsmith/rake/builder.rb', line 46

def install gem_spec
  gem_name = "#{gem_spec.name} #{gem_spec.version_number}"

  if kernel.system("gem install #{package_path gem_spec}")
    shell.confirm "Installed: #{gem_name}."
  else
    shell.error "Unable to install: #{gem_name}."
  end
end

#validateObject



28
29
30
31
32
# File 'lib/gemsmith/rake/builder.rb', line 28

def validate
  return if `git status --porcelain`.empty?
  shell.error "Build failed: Gem has uncommitted changes."
  kernel.exit 1
end