Class: Reviewer::Tool::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/tool/settings.rb

Overview

Converts/casts tool configuration values and provides appropriate default values if not set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_key, config: nil) ⇒ self

Creates an instance of settings for retrieving values from the configuration file.

Parameters:

  • tool_key (Symbol)

    the unique identifier for the tool in the config file

  • config: (defaults to: nil)

    nil [Hash] the configuration values to examine for the settings



16
17
18
19
# File 'lib/reviewer/tool/settings.rb', line 16

def initialize(tool_key, config: nil)
  @tool_key = tool_key.to_sym
  @config = config || load_config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/reviewer/tool/settings.rb', line 7

def config
  @config
end

#tool_keyObject (readonly) Also known as: key

Returns the value of attribute tool_key.



7
8
9
# File 'lib/reviewer/tool/settings.rb', line 7

def tool_key
  @tool_key
end

Instance Method Details

#commandsHash

The collection of configured commands for the tool

Returns:

  • (Hash)

    all of the commands configured for the tool



66
67
68
# File 'lib/reviewer/tool/settings.rb', line 66

def commands
  config.fetch(:commands) { {} }
end

#descriptionObject



43
44
45
# File 'lib/reviewer/tool/settings.rb', line 43

def description
  config.fetch(:description) { "(No description provided for '#{name}')" }
end

#disabled?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/reviewer/tool/settings.rb', line 31

def disabled?
  config.fetch(:disabled, false)
end

#enabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/reviewer/tool/settings.rb', line 35

def enabled?
  !disabled?
end

#envObject



55
56
57
# File 'lib/reviewer/tool/settings.rb', line 55

def env
  config.fetch(:env) { {} }
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/reviewer/tool/settings.rb', line 25

def eql?(other)
  self.class == other.class &&
    state == other.state
end

#flagsObject



59
60
61
# File 'lib/reviewer/tool/settings.rb', line 59

def flags
  config.fetch(:flags) { {} }
end

#hashObject



21
22
23
# File 'lib/reviewer/tool/settings.rb', line 21

def hash
  state.hash
end


51
52
53
# File 'lib/reviewer/tool/settings.rb', line 51

def links
  config.fetch(:links) { {} }
end

#max_exit_statusInteger

The largest exit status that can still be considered a success for the command

Returns:

  • (Integer)

    the configured ‘max_exit_status` for the tool or 0 if one isn’t configured



73
74
75
# File 'lib/reviewer/tool/settings.rb', line 73

def max_exit_status
  commands.fetch(:max_exit_status, 0)
end

#nameObject



39
40
41
# File 'lib/reviewer/tool/settings.rb', line 39

def name
  config.fetch(:name) { tool_key.to_s.capitalize }
end

#tagsObject



47
48
49
# File 'lib/reviewer/tool/settings.rb', line 47

def tags
  config.fetch(:tags) { [] }
end