Class: Toys::Templates::Rubocop

Inherits:
Object
  • Object
show all
Includes:
Toys::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

Methods included from Toys::Template

create

Constructor Details

#initialize(name: DEFAULT_TOOL_NAME, gem_version: nil, fail_on_error: true, options: [], bundler: false, context_directory: nil) ⇒ 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.

  • context_directory (String) (defaults to: nil)

    A custom context directory to use when executing this tool.



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/toys/templates/rubocop.rb', line 42

def initialize(name: DEFAULT_TOOL_NAME,
               gem_version: nil,
               fail_on_error: true,
               options: [],
               bundler: false,
               context_directory: nil)
  @name = name
  @gem_version = gem_version
  @fail_on_error = fail_on_error
  @options = options
  @bundler = bundler
  @context_directory = context_directory
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)


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

def bundler=(value)
  @bundler = value
end

#context_directory=(value) ⇒ String

Custom context directory for this tool.

Parameters:

  • value (String)

Returns:

  • (String)


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

def context_directory=(value)
  @context_directory = value
end

#fail_on_error=(value) ⇒ Boolean

Whether to exit with a nonzero code if Rubocop fails.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


81
82
83
# File 'lib/toys/templates/rubocop.rb', line 81

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)


73
74
75
# File 'lib/toys/templates/rubocop.rb', line 73

def gem_version=(value)
  @gem_version = value
end

#name=(value) ⇒ String

Name of the tool to create.

Parameters:

  • value (String)

Returns:

  • (String)


62
63
64
# File 'lib/toys/templates/rubocop.rb', line 62

def name=(value)
  @name = value
end

#options=(value) ⇒ Array<String>

Additional options to pass to Rubocop

Parameters:

  • value (Array<String>)

Returns:

  • (Array<String>)


89
90
91
# File 'lib/toys/templates/rubocop.rb', line 89

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)


122
123
124
125
# File 'lib/toys/templates/rubocop.rb', line 122

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