Class: Toys::Templates::GemBuild

Inherits:
Object
  • Object
show all
Includes:
Template
Defined in:
lib/toys/templates/gem_build.rb

Overview

A template for tools that build, install, and release gems

Constant Summary collapse

DEFAULT_TOOL_NAME =

Default tool name.

Returns:

  • (String)
"build"
DEFAULT_OUTPUT_FLAGS =

Default output flags. If output_flags is set to true, this is the value used.

Returns:

  • (Array<String>)
["-o", "--output"].freeze
DEFAULT_PUSH_REMOTE =

Default remote for pushing tags.

Returns:

  • (String)
"origin"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, gem_name: nil, output: nil, output_flags: nil, push_gem: false, install_gem: false, tag: false, push_tag: false) ⇒ GemBuild

Create the template settings for the GemBuild template.

Parameters:

  • name (String) (defaults to: nil)

    Name of the tool to create. Defaults to DEFAULT_TOOL_NAME.

  • gem_name (String) (defaults to: nil)

    Name of the gem to build. If not provided, searches the context and current directories and uses the first gemspec file it finds.

  • output (String) (defaults to: nil)

    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.

  • output_flags (Array<String>, true) (defaults to: nil)

    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.

  • push_gem (Boolean) (defaults to: false)

    If true, pushes the built gem to rubygems.

  • install_gem (Boolean) (defaults to: false)

    If true, installs the built gem locally.

  • tag (Boolean) (defaults to: false)

    If true, tags the git repo with the gem version.

  • push_tag (Boolean, String) (defaults to: false)

    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.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/toys/templates/gem_build.rb', line 53

def initialize(name: nil,
               gem_name: nil,
               output: nil,
               output_flags: nil,
               push_gem: false,
               install_gem: false,
               tag: false,
               push_tag: false)
  @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
end

Instance Attribute Details

#gem_name=(value) ⇒ String?

Name of the gem to build. If nil, searches the context and current directories and uses the first gemspec file it finds.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


86
87
88
# File 'lib/toys/templates/gem_build.rb', line 86

def gem_name=(value)
  @gem_name = value
end

#install_gem=(value) ⇒ Boolean

Whether the tool should install the built gen locally.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


120
121
122
# File 'lib/toys/templates/gem_build.rb', line 120

def install_gem=(value)
  @install_gem = value
end

#name=(value) ⇒ String

Name of the tool to create.

Parameters:

  • value (String)

Returns:

  • (String)


77
78
79
# File 'lib/toys/templates/gem_build.rb', line 77

def name=(value)
  @name = value
end

#output=(value) ⇒ 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.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


95
96
97
# File 'lib/toys/templates/gem_build.rb', line 95

def output=(value)
  @output = value
end

#output_flags=(value) ⇒ Array<String>, ...

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.

Parameters:

  • value (Array<String>, true, nil)

Returns:

  • (Array<String>, true, nil)


104
105
106
# File 'lib/toys/templates/gem_build.rb', line 104

def output_flags=(value)
  @output_flags = value
end

#push_gem=(value) ⇒ Boolean

Whether the tool should push the gem to Rubygems.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


112
113
114
# File 'lib/toys/templates/gem_build.rb', line 112

def push_gem=(value)
  @push_gem = value
end

#push_tag=(value) ⇒ Boolean, String

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.

Parameters:

  • value (Boolean, String)

Returns:

  • (Boolean, String)


138
139
140
# File 'lib/toys/templates/gem_build.rb', line 138

def push_tag=(value)
  @push_tag = value
end

#tag=(value) ⇒ Boolean

Whether to tag the git repo with the gem version.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


128
129
130
# File 'lib/toys/templates/gem_build.rb', line 128

def tag=(value)
  @tag = value
end