Class: Toys::Templates::Rake

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

Overview

A template that generates tools matching a rakefile.

Constant Summary collapse

DEFAULT_RAKEFILE_PATH =

Default path to the Rakefile.

Returns:

  • (String)
"Rakefile"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Toys::Template

create

Constructor Details

#initialize(gem_version: nil, rakefile_path: nil, only_described: false, use_flags: false, bundler: false, context_directory: nil) ⇒ Rake

Create the template settings for the rake template.

Parameters:

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

    Version requirements for the rake gem. Defaults to nil, indicating no version requirement.

  • rakefile_path (String) (defaults to: nil)

    Path to the Rakefile. Defaults to DEFAULT_RAKEFILE_PATH.

  • only_described (Boolean) (defaults to: false)

    If true, tools are generated only for rake tasks with descriptions. Default is false.

  • use_flags (Boolean) (defaults to: false)

    Generated tools use flags instead of positional arguments to pass arguments to rake tasks. Default is false.

  • bundler (Boolean, Hash) (defaults to: false)

    If false (the default), bundler is not enabled for Rake tools. If true or a Hash of options, bundler is enabled. See the documentation for the bundler mixin for information on available options.

  • context_directory (String) (defaults to: nil)

    A custom context directory to use when executing this tool.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/toys/templates/rake.rb', line 37

def initialize(gem_version: nil,
               rakefile_path: nil,
               only_described: false,
               use_flags: false,
               bundler: false,
               context_directory: nil)
  @gem_version = gem_version
  @rakefile_path = rakefile_path
  @only_described = only_described
  @use_flags = use_flags
  @bundler = bundler
  @context_directory = context_directory
end

Instance Attribute Details

#bundler=(value) ⇒ Boolean, Hash (writeonly)

Set the bundler state and options for all Rake tools.

Pass false to disable bundler. Pass true or a hash of options to enable bundler. See the documentation for the bundler mixin for information on the options that can be passed.

Parameters:

  • value (Boolean, Hash)

Returns:

  • (Boolean, Hash)


106
107
108
# File 'lib/toys/templates/rake.rb', line 106

def bundler=(value)
  @bundler = value
end

#context_directory=(value) ⇒ String

Custom context directory for this tool.

Parameters:

  • value (String)

Returns:

  • (String)


93
94
95
# File 'lib/toys/templates/rake.rb', line 93

def context_directory=(value)
  @context_directory = value
end

#gem_version=(value) ⇒ String, ...

Version requirements for the minitest gem. If set to nil, has no version requirement (unless one is specified in the bundle.)

Parameters:

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

Returns:

  • (String, Array<String>, nil)


59
60
61
# File 'lib/toys/templates/rake.rb', line 59

def gem_version=(value)
  @gem_version = value
end

#only_described=(value) ⇒ Boolean

Whether to generate tools only for rake tasks with descriptions.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


76
77
78
# File 'lib/toys/templates/rake.rb', line 76

def only_described=(value)
  @only_described = value
end

#rakefile_path=(value) ⇒ String?

Path to the Rakefile. If set to nil, defaults to DEFAULT_RAKEFILE_PATH.

Parameters:

  • value (String, nil)

Returns:

  • (String, nil)


68
69
70
# File 'lib/toys/templates/rake.rb', line 68

def rakefile_path=(value)
  @rakefile_path = value
end

#use_flags=(value) ⇒ Boolean

Whether generated tools should use flags instead of positional arguments to pass arguments to rake tasks.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


85
86
87
# File 'lib/toys/templates/rake.rb', line 85

def use_flags=(value)
  @use_flags = value
end

Instance Method Details

#use_bundler(**opts) ⇒ self

Use bundler for all Rake tools.

See the documentation for the bundler mixin for information on the options that can be passed.

Parameters:

  • opts (keywords)

    Options for bundler

Returns:

  • (self)


118
119
120
121
# File 'lib/toys/templates/rake.rb', line 118

def use_bundler(**opts)
  @bundler = opts
  self
end