Class: Kamaze::Project::Tools::Gemspec::Builder
- Inherits:
-
Packager
- Object
- Observable
- BaseTool
- Packager
- Packager
- Kamaze::Project::Tools::Gemspec::Builder
- Defined in:
- lib/kamaze/project/tools/gemspec/builder.rb,
lib/kamaze/project/tools/gemspec.rb
Overview
Package a gem
from its own gemspec
file
The build command allows you to create a gem
from a ruby gemspec
.
The best way to build a gem is to use a Rakefile and the Gem::PackageTask which ships with RubyGems. But, you can also use this class ;).
Sample of use:
builder = Kamaze.project.tools.fetch(:gemspec_builder)
builder.build if builder.ready?
Instance Attribute Summary collapse
- #observer_peers ⇒ Hash|nil included from Concern::Observable readonly protected
Instance Method Summary collapse
-
#build ⇒ self
Build
.gem
file. -
#build_args ⇒ Array<String>
protected
Get args used by
gem
command. -
#buildable ⇒ Pathname
Get buildable (relative path).
-
#gemspec_srcfile ⇒ Pathname
Get path do gemspec present in
src
dir. - #ready? ⇒ Boolean (also: #buildable?)
- #setup ⇒ Object protected
Constructor Details
This class inherits a constructor from Kamaze::Project::Tools::Packager
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Kamaze::Project::Tools::Packager
Instance Attribute Details
#observer_peers ⇒ Hash|nil (readonly, protected) Originally defined in module Concern::Observable
Instance Method Details
#build ⇒ self
Build .gem
file
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kamaze/project/tools/gemspec/builder.rb', line 32 def build prepare buildable_dir = self.buildable.dirname.realpath # dive into ``src`` file Dir.chdir(gemspec_srcfile.dirname) do Gem::GemRunner.new.run(build_args).yield_self do |file| FileUtils.mv(file, buildable_dir) buildable_dir.join(file) end end self end |
#build_args ⇒ Array<String> (protected)
Get args used by gem
command
94 95 96 97 98 |
# File 'lib/kamaze/project/tools/gemspec/builder.rb', line 94 def build_args Dir.chdir(pwd) do [:build, gemspec_srcfile, '--norc'].map(&:to_s) end end |
#buildable ⇒ Pathname
Get buildable (relative path)
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kamaze/project/tools/gemspec/builder.rb', line 52 def buildable full_name = gemspec_reader.read(Hash).fetch(:full_name) file_path = fs.package_dirs .fetch(:gem) .join("#{full_name}.gem") .to_s .gsub(%r{^\./}, '') ::Pathname.new(file_path) end |
#gemspec_srcfile ⇒ Pathname
Get path do gemspec present in src
dir
72 73 74 75 76 77 78 79 |
# File 'lib/kamaze/project/tools/gemspec/builder.rb', line 72 def gemspec_srcfile (package_dirs.fetch(:src) .realpath .join(buildable.basename('.*')).to_s .gsub(/-([0-9 \.])+$/, '') + '.gemspec').yield_self do |s| Pathname.new(s) end end |
#ready? ⇒ Boolean Also known as: buildable?
63 64 65 |
# File 'lib/kamaze/project/tools/gemspec/builder.rb', line 63 def ready? gemspec_reader.read(Hash)[:full_name].nil? ? false : super end |
#setup ⇒ Object (protected)
83 84 85 86 87 88 89 |
# File 'lib/kamaze/project/tools/gemspec/builder.rb', line 83 def setup super self.package_labels = [:src, :gem] self.purgeables = [:gem] self.package_name = "ruby/gem-#{Gem::VERSION}" end |