Class: Toys::Templates::Rubocop

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

Overview

A template for tools that run rubocop

Constant Summary collapse

DEFAULT_GEM_VERSION_REQUIREMENTS =

Default version requirements for the rubocop gem.

Returns:

  • (Array<String>)
[].freeze
DEFAULT_TOOL_NAME =

Default tool name

Returns:

  • (String)
"rubocop"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: DEFAULT_TOOL_NAME, gem_version: nil, fail_on_error: true, options: [], bundler: false) ⇒ Rubocop

Create the template settings for the Rubocop template.

Parameters:

  • name (String) (defaults to: DEFAULT_TOOL_NAME)

    Name of the tool to create. Defaults to DEFAULT_TOOL_NAME.

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

    Version requirements for the rubocop gem. Defaults to DEFAULT_GEM_VERSION_REQUIREMENTS.

  • fail_on_error (Boolean) (defaults to: true)

    If true, exits with a nonzero code if Rubocop fails. Defaults to true.

  • options (Array<String>) (defaults to: [])

    Additional options passed to the Rubocop CLI.

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

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



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/toys/templates/rubocop.rb', line 40

def initialize(name: DEFAULT_TOOL_NAME,
               gem_version: nil,
               fail_on_error: true,
               options: [],
               bundler: false)
  @name = name
  @gem_version = gem_version
  @fail_on_error = fail_on_error
  @options = options
  @bundler = bundler
end

Instance Attribute Details

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

Set the bundler state and options for this tool.

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)


98
99
100
# File 'lib/toys/templates/rubocop.rb', line 98

def bundler=(value)
  @bundler = value
end

#fail_on_error=(value) ⇒ Boolean

Whether to exit with a nonzero code if Rubocop fails.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


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

def fail_on_error=(value)
  @fail_on_error = value
end

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

Version requirements for the rdoc gem. If set to nil, uses the bundled version if bundler is enabled, or defaults to DEFAULT_GEM_VERSION_REQUIREMENTS if bundler is not enabled.

Parameters:

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

Returns:

  • (String, Array<String>, nil)


69
70
71
# File 'lib/toys/templates/rubocop.rb', line 69

def gem_version=(value)
  @gem_version = value
end

#name=(value) ⇒ String

Name of the tool to create.

Parameters:

  • value (String)

Returns:

  • (String)


58
59
60
# File 'lib/toys/templates/rubocop.rb', line 58

def name=(value)
  @name = value
end

#options=(value) ⇒ Array<String>

Additional options to pass to Rubocop

Parameters:

  • value (Array<String>)

Returns:

  • (Array<String>)


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

def options=(value)
  @options = value
end

Instance Method Details

#use_bundler(**opts) ⇒ self

Activate bundler for this tool.

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

Parameters:

  • opts (keywords)

    Options for bundler

Returns:

  • (self)


110
111
112
113
# File 'lib/toys/templates/rubocop.rb', line 110

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