class Toys::Templates::GemBuild
A template for tools that build, install, and release gems
Constants
- DEFAULT_OUTPUT_FLAGS
Default output flags. If `output_flags` is set to `true`, this is the value used. @return [Array<String>]
- DEFAULT_PUSH_REMOTE
Default remote for pushing tags. @return [String]
- DEFAULT_TOOL_NAME
Default tool name. @return [String]
Attributes
Custom context directory for this tool.
@param value [String] @return [String]
Name of the gem to build. If `nil`, searches the context and current directories and uses the first gemspec file it finds.
@param value [String,nil] @return [String,nil]
Whether the tool should install the built gen locally.
@param value [Boolean] @return [Boolean]
Name of the tool to create.
@param value [String] @return [String]
Path to the gem package to generate. If `nil`, defaults to a file name based on the gem name and version, under “pkg” in the current directory.
@param value [String,nil] @return [String,nil]
Flags that set the output path on the generated tool. If `nil`, no flags are generated. If set to `true`, {DEFAULT_OUTPUT_FLAGS} is used.
@param value [Array<String>,true,nil] @return [Array<String>,true,nil]
Whether the tool should push the gem to Rubygems.
@param value [Boolean] @return [Boolean]
Whether to push the new tag to a git remote. This may be set to the name of the remote as a string, to `true` to use {DEFAULT_PUSH_REMOTE} by default, or to `false` to disable pushing.
@param value [Boolean,String] @return [Boolean,String]
Whether to tag the git repo with the gem version.
@param value [Boolean] @return [Boolean]
Public Class Methods
Create the template settings for the GemBuild
template.
@param name [String] Name of the tool to create. Defaults to
{DEFAULT_TOOL_NAME}.
@param gem_name
[String] Name of the gem to build. If not provided,
searches the context and current directories and uses the first gemspec file it finds.
@param output [String] Path to the gem package to generate. Optional.
If not provided, defaults to a file name based on the gem name and version, under "pkg" in the current directory.
@param output_flags
[Array<String>,true] Provide flags on the tool that
set the output path. Optional. If not provided, no flags are created. You may set this to an array of flags (e.g. `["-o"]`) or set to `true` to choose {DEFAULT_OUTPUT_FLAGS}.
@param push_gem
[Boolean] If true, pushes the built gem to rubygems. @param install_gem
[Boolean] If true, installs the built gem locally. @param tag [Boolean] If true, tags the git repo with the gem version. @param push_tag
[Boolean,String] If truthy, pushes the new tag to
a git remote. You may specify which remote by setting the value to a string. Otherwise, if the value is simply `true`, the "origin" remote is used by default.
@param context_directory
[String] A custom context directory to use
when executing this tool.
# File lib/toys/templates/gem_build.rb, line 55 def initialize(name: nil, gem_name: nil, output: nil, output_flags: nil, push_gem: false, install_gem: false, tag: false, push_tag: false, context_directory: nil) @name = name @gem_name = gem_name @output = output @output_flags = output_flags @push_gem = push_gem @install_gem = install_gem @tag = tag @push_tag = push_tag @context_directory = context_directory end
Public Instance Methods
@private
# File lib/toys/templates/gem_build.rb, line 169 def gem_name(context_dir = nil) return @gem_name if @gem_name glob = "*.gemspec" glob = ::File.join(context_dir, glob) if context_dir candidates = ::Dir.glob(glob) if candidates.empty? raise ToolDefinitionError, "Could not find a gemspec" end candidates.first.sub(/\.gemspec$/, "") end
@private
# File lib/toys/templates/gem_build.rb, line 164 def name @name || DEFAULT_TOOL_NAME end
@private
# File lib/toys/templates/gem_build.rb, line 181 def output_flags @output_flags == true ? DEFAULT_OUTPUT_FLAGS : Array(@output_flags) end
@private
# File lib/toys/templates/gem_build.rb, line 186 def push_tag @push_tag == true ? DEFAULT_PUSH_REMOTE : @push_tag end
@private
# File lib/toys/templates/gem_build.rb, line 191 def task_names names = [] names << "Install" if @install_gem names << "Release" if @push_gem names.empty? ? "Build" : names.join(" and ") end