Class: Bundler::GemHelper
- Inherits:
-
Object
- Object
- Bundler::GemHelper
- Includes:
- Rake::DSL
- Defined in:
- lib/bundler/gem_helper.rb
Class Attribute Summary collapse
-
.instance ⇒ Object
set when install’d.
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#gemspec ⇒ Object
readonly
Returns the value of attribute gemspec.
-
#spec_path ⇒ Object
readonly
Returns the value of attribute spec_path.
-
#tag_prefix ⇒ Object
writeonly
Sets the attribute tag_prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #build_checksum(built_gem_path = nil) ⇒ Object
- #build_gem ⇒ Object
-
#initialize(base = nil, name = nil) ⇒ GemHelper
constructor
A new instance of GemHelper.
- #install ⇒ Object
- #install_gem(built_gem_path = nil, local = false) ⇒ Object
Constructor Details
#initialize(base = nil, name = nil) ⇒ GemHelper
Returns a new instance of GemHelper.
33 34 35 36 37 38 39 40 |
# File 'lib/bundler/gem_helper.rb', line 33 def initialize(base = nil, name = nil) @base = File.(base || SharedHelpers.pwd) gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.glob_files_in_dir("{,*}.gemspec", @base) raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1 @spec_path = gemspecs.first @gemspec = Bundler.load_gemspec(@spec_path) @tag_prefix = "" end |
Class Attribute Details
.instance ⇒ Object
set when install’d.
12 13 14 |
# File 'lib/bundler/gem_helper.rb', line 12 def instance @instance end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
29 30 31 |
# File 'lib/bundler/gem_helper.rb', line 29 def base @base end |
#gemspec ⇒ Object (readonly)
Returns the value of attribute gemspec.
29 30 31 |
# File 'lib/bundler/gem_helper.rb', line 29 def gemspec @gemspec end |
#spec_path ⇒ Object (readonly)
Returns the value of attribute spec_path.
29 30 31 |
# File 'lib/bundler/gem_helper.rb', line 29 def spec_path @spec_path end |
#tag_prefix=(value) ⇒ Object (writeonly)
Sets the attribute tag_prefix
31 32 33 |
# File 'lib/bundler/gem_helper.rb', line 31 def tag_prefix=(value) @tag_prefix = value end |
Class Method Details
.gemspec(&block) ⇒ Object
22 23 24 25 26 |
# File 'lib/bundler/gem_helper.rb', line 22 def gemspec(&block) gemspec = instance.gemspec block&.call(gemspec) gemspec end |
.install_tasks(opts = {}) ⇒ Object
14 15 16 |
# File 'lib/bundler/gem_helper.rb', line 14 def install_tasks(opts = {}) new(opts[:dir], opts[:name]).install end |
.tag_prefix=(prefix) ⇒ Object
18 19 20 |
# File 'lib/bundler/gem_helper.rb', line 18 def tag_prefix=(prefix) instance.tag_prefix = prefix end |
Instance Method Details
#build_checksum(built_gem_path = nil) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/bundler/gem_helper.rb', line 105 def build_checksum(built_gem_path = nil) built_gem_path ||= build_gem SharedHelpers.filesystem_access(File.join(base, "checksums")) {|p| FileUtils.mkdir_p(p) } file_name = "#{File.basename(built_gem_path)}.sha512" require "digest/sha2" checksum = ::Digest::SHA512.file(built_gem_path).hexdigest target = File.join(base, "checksums", file_name) File.write(target, checksum + "\n") Bundler.ui.confirm "#{name} #{version} checksum written to checksums/#{file_name}." end |
#build_gem ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bundler/gem_helper.rb', line 86 def build_gem file_name = nil sh([*gem_command, "build", "-V", spec_path]) do file_name = File.basename(built_gem_path) SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) } FileUtils.mv(built_gem_path, "pkg") Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}." end File.join(base, "pkg", file_name) end |
#install ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bundler/gem_helper.rb', line 42 def install built_gem_path = nil desc "Build #{name}-#{version}.gem into the pkg directory." task "build" do built_gem_path = build_gem end desc "Generate SHA512 checksum if #{name}-#{version}.gem into the checksums directory." task "build:checksum" => "build" do build_checksum(built_gem_path) end desc "Build and install #{name}-#{version}.gem into system gems." task "install" => "build" do install_gem(built_gem_path) end desc "Build and install #{name}-#{version}.gem into system gems without network access." task "install:local" => "build" do install_gem(built_gem_path, :local) end desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to #{gem_push_host}\n" \ "To prevent publishing in RubyGems use `gem_push=no rake release`" task "release", [:remote] => ["build", "release:guard_clean", "release:source_control_push", "release:rubygem_push"] do end task "release:guard_clean" do guard_clean end task "release:source_control_push", [:remote] do |_, args| tag_version { git_push(args[:remote]) } unless already_tagged? end task "release:rubygem_push" => "build" do rubygem_push(built_gem_path) if gem_push? end GemHelper.instance = self end |
#install_gem(built_gem_path = nil, local = false) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/bundler/gem_helper.rb', line 97 def install_gem(built_gem_path = nil, local = false) built_gem_path ||= build_gem cmd = [*gem_command, "install", built_gem_path.to_s] cmd << "--local" if local sh(cmd) Bundler.ui.confirm "#{name} (#{version}) installed." end |