class Bake::Gem::Helper
Constants
- VERSION_PATTERN
Attributes
gemspec[R]
Public Class Methods
new(root = Dir.pwd, gemspec: nil)
click to toggle source
# File lib/bake/gem/helper.rb, line 34 def initialize(root = Dir.pwd, gemspec: nil) @root = root @gemspec = gemspec || self.find_gemspec end
Public Instance Methods
build_gem(root: "pkg")
click to toggle source
@parameter root [String] The root path for package files. @returns [String] The path to the built gem package.
# File lib/bake/gem/helper.rb, line 87 def build_gem(root: "pkg") # Ensure the output directory exists: FileUtils.mkdir_p("pkg") output_path = File.join('pkg', @gemspec.file_name) ::Gem::Package.build(@gemspec, false, false, output_path) end
guard_clean()
click to toggle source
# File lib/bake/gem/helper.rb, line 77 def guard_clean lines = readlines("git", "status", "--porcelain") if lines.any? raise "Repository has uncommited changes!\n#{lines.join('')}" end end
install_gem(*arguments, path: @gemspec.file_name)
click to toggle source
# File lib/bake/gem/helper.rb, line 96 def install_gem(*arguments, path: @gemspec.file_name) system("gem", "install", path, *arguments) end
push_gem(*arguments, path: @gemspec.file_name)
click to toggle source
# File lib/bake/gem/helper.rb, line 100 def push_gem(*arguments, path: @gemspec.file_name) system("gem", "push", path, *arguments) end
update_version(bump) { |version| ... }
click to toggle source
# File lib/bake/gem/helper.rb, line 47 def update_version(bump) return unless version_path = self.version_path lines = File.readlines(version_path) version = nil lines.each do |line| if match = line.match(VERSION_PATTERN) version = match[:value].split(/\./).map(&:to_i) bump.each_with_index do |increment, index| if increment == 1 version[index] += 1 elsif increment == 0 version[index] = 0 end end line.sub!(match[:value], version.join('.')) end end if version yield version if block_given? File.write(version_path, lines.join) return version_path end end
version_path()
click to toggle source
# File lib/bake/gem/helper.rb, line 41 def version_path @gemspec&.files.grep(/lib(.*?)version.rb/).first end
Private Instance Methods
find_gemspec(glob = "*.gemspec")
click to toggle source
# File lib/bake/gem/helper.rb, line 106 def find_gemspec(glob = "*.gemspec") paths = Dir.glob(glob, base: @root).sort if paths.size > 1 raise "Multiple gemspecs found: #{paths}, please specify one!" end if path = paths.first return ::Gem::Specification.load(path) end end