class Reviewer::Tool

Provides an instance of a specific tool for accessing its settings and run history

Constants

SIX_HOURS_IN_SECONDS

In general, Reviewer tries to save time where it can. In the case of the “prepare” command used by some tools to retrieve data, it only runs it occasionally in order to save time. This is the default window that it uses to determine if the tool's preparation step should be considered stale and needs to be rerun. Frequent enough that it shouldn't get stale, but infrequent enough that it's not cumbersome.

Attributes

history[R]
settings[R]

Public Class Methods

new(tool_key) click to toggle source

Create an instance of a tool @param tool_key [Symbol] the key to the tool from the configuration file

@return [Tool] an instance of tool for accessing settings information and facts about the tool

# File lib/reviewer/tool.rb, line 39
def initialize(tool_key)
  @settings = Settings.new(tool_key)
end

Public Instance Methods

==(other)
Alias for: eql?
command?(command_type) click to toggle source

Determines whether a tool has a specific command type configured @param command_type [Symbol] one of the available command types defined in Command::TYPES

@return [Boolean] true if the command type is configured and not blank

# File lib/reviewer/tool.rb, line 56
def command?(command_type)
  commands.key?(command_type) && !commands[command_type].nil?
end
eql?(other) click to toggle source

Determines if two tools are equal @param other [Tool] the tool to compare to the current instance

@return [Boolean] true if the settings match

# File lib/reviewer/tool.rb, line 131
def eql?(other)
  settings == other.settings
end
Also aliased as: ==
formattable?() click to toggle source

Determines if the tool can run a `format` command

@return [Boolean] true if there is a non-blank `format` command configured

# File lib/reviewer/tool.rb, line 84
def formattable?
  command?(:format)
end
installable?() click to toggle source

Determines if the tool can run a `install` command

@return [Boolean] true if there is a non-blank `install` command configured

# File lib/reviewer/tool.rb, line 63
def installable?
  command?(:install)
end
last_prepared_at() click to toggle source

Specifies when the tool last had it's `prepare` command run

@return [DateTime] timestamp of when the `prepare` command was last run

# File lib/reviewer/tool.rb, line 91
def last_prepared_at
  Reviewer.history.get(key, :last_prepared_at)
end
last_prepared_at=(last_prepared_at) click to toggle source

Sets the timestamp for when the tool last ran its `prepare` command @param last_prepared_at [DateTime] the value to record for when the `prepare` command last ran

@return [DateTime] timestamp of when the `prepare` command was last run

# File lib/reviewer/tool.rb, line 99
def last_prepared_at=(last_prepared_at)
  Reviewer.history.set(key, :last_prepared_at, last_prepared_at)
end
preparable?() click to toggle source

Determines if the tool can run a `prepare` command

@return [Boolean] true if there is a non-blank `prepare` command configured

# File lib/reviewer/tool.rb, line 70
def preparable?
  command?(:prepare)
end
prepare?() click to toggle source

For determining if the tool should run it's prepration command. It will only be run both if the tool has a preparation command, and the command hasn't been run 6 hours

@return [Boolean] true if the tool has a configured `prepare` command that hasn't been run in

the last 6 hours
# File lib/reviewer/tool.rb, line 48
def prepare?
  preparable? && stale?
end
reviewable?() click to toggle source

Determines if the tool can run a `review` command

@return [Boolean] true if there is a non-blank `review` command configured

# File lib/reviewer/tool.rb, line 77
def reviewable?
  command?(:review)
end
stale?() click to toggle source

Determines whether the `prepare` command was run recently enough

@return [Boolean] true if a prepare command exists, a timestamp exists, and it was run more

than six hours ago
# File lib/reviewer/tool.rb, line 107
def stale?
  return false unless preparable?

  last_prepared_at.nil? || last_prepared_at < Time.now - SIX_HOURS_IN_SECONDS
end