class Toys::Templates::Rubocop

A template for tools that run rubocop

Constants

DEFAULT_GEM_VERSION_REQUIREMENTS

Default version requirements for the rubocop gem. @return [Array<String>]

DEFAULT_TOOL_NAME

Default tool name @return [String]

Attributes

bundler[W]

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](dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler) for information on the options that can be passed.

@param value [Boolean,Hash] @return [Boolean,Hash]

context_directory[RW]

Custom context directory for this tool.

@param value [String] @return [String]

fail_on_error[RW]

Whether to exit with a nonzero code if Rubocop fails.

@param value [Boolean] @return [Boolean]

gem_version[W]

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.

@param value [String,Array<String>,nil] @return [String,Array<String>,nil]

name[W]

Name of the tool to create.

@param value [String] @return [String]

options[W]

Additional options to pass to Rubocop

@param value [Array<String>] @return [Array<String>]

Public Class Methods

new(name: DEFAULT_TOOL_NAME, gem_version: nil, fail_on_error: true, options: [], bundler: false, context_directory: nil) click to toggle source

Create the template settings for the Rubocop template.

@param name [String] Name of the tool to create. Defaults to

{DEFAULT_TOOL_NAME}.

@param gem_version [String,Array<String>] Version requirements for

the rubocop gem. Defaults to {DEFAULT_GEM_VERSION_REQUIREMENTS}.

@param fail_on_error [Boolean] If true, exits with a nonzero code if

Rubocop fails. Defaults to true.

@param options [Array<String>] Additional options passed to the Rubocop

CLI.

@param bundler [Boolean,Hash] 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](https://dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler)
for information on available options.

@param context_directory [String] A custom context directory to use

when executing this tool.
# 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

Public Instance Methods

bundler_settings() click to toggle source

@private

# File lib/toys/templates/rubocop.rb, line 149
def bundler_settings
  if @bundler && !@bundler.is_a?(::Hash)
    {}
  else
    @bundler
  end
end
gem_version() click to toggle source

@private

# File lib/toys/templates/rubocop.rb, line 138
def gem_version
  return Array(@gem_version) if @gem_version
  @bundler ? [] : DEFAULT_GEM_VERSION_REQUIREMENTS
end
name() click to toggle source

@private

# File lib/toys/templates/rubocop.rb, line 133
def name
  @name || DEFAULT_TOOL_NAME
end
options() click to toggle source

@private

# File lib/toys/templates/rubocop.rb, line 144
def options
  Array(@options)
end
use_bundler(**opts) click to toggle source

Activate bundler for this tool.

See the documentation for the [bundler mixin](dazuma.github.io/toys/gems/toys-core/latest/Toys/StandardMixins/Bundler) for information on the options that can be passed.

@param opts [keywords] Options for bundler @return [self]

# File lib/toys/templates/rubocop.rb, line 122
def use_bundler(**opts)
  @bundler = opts
  self
end