Class: Reviewer::Tool
- Inherits:
-
Object
- Object
- Reviewer::Tool
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/reviewer/tool.rb,
lib/reviewer/tool/settings.rb more...
Overview
Provides an instance of a specific tool for accessing its settings and run history
Defined Under Namespace
Classes: Settings
Constant Summary collapse
- 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.
60 * 60 * 6
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #average_time(command) ⇒ Object
-
#command?(command_type) ⇒ Boolean
Determines whether a tool has a specific command type configured.
-
#eql?(other) ⇒ Boolean
(also: #==)
Determines if two tools are equal.
-
#formattable? ⇒ Boolean
Determines if the tool can run a ‘format` command.
- #get_timing(command) ⇒ Object
-
#initialize(tool_key) ⇒ Tool
constructor
Create an instance of a tool.
-
#install_link ⇒ String?
Returns the text for the install link if available.
-
#install_link? ⇒ Boolean
Convenience method for determining if a tool has a configured install link.
-
#installable? ⇒ Boolean
Determines if the tool can run a ‘install` command.
-
#last_prepared_at ⇒ Time
Specifies when the tool last had it’s ‘prepare` command run.
-
#last_prepared_at=(last_prepared_at) ⇒ DateTime
Sets the timestamp for when the tool last ran its ‘prepare` command.
-
#preparable? ⇒ Boolean
Determines if the tool can run a ‘prepare` command.
-
#prepare? ⇒ Boolean
For determining if the tool should run it’s prepration command.
- #record_timing(command, time) ⇒ Object
-
#reviewable? ⇒ Boolean
Determines if the tool can run a ‘review` command.
-
#stale? ⇒ Boolean
Determines whether the ‘prepare` command was run recently enough.
Constructor Details
permalink #initialize(tool_key) ⇒ Tool
Create an instance of a tool
41 42 43 |
# File 'lib/reviewer/tool.rb', line 41 def initialize(tool_key) @settings = Settings.new(tool_key) end |
Instance Attribute Details
permalink #history ⇒ Object (readonly)
Returns the value of attribute history.
20 21 22 |
# File 'lib/reviewer/tool.rb', line 20 def history @history end |
permalink #settings ⇒ Object (readonly)
Returns the value of attribute settings.
20 21 22 |
# File 'lib/reviewer/tool.rb', line 20 def settings @settings end |
Instance Method Details
permalink #average_time(command) ⇒ Object
[View source]
107 108 109 110 111 |
# File 'lib/reviewer/tool.rb', line 107 def average_time(command) times = get_timing(command) times.any? ? times.sum / times.size : 0 end |
permalink #command?(command_type) ⇒ Boolean
Determines whether a tool has a specific command type configured
58 59 60 |
# File 'lib/reviewer/tool.rb', line 58 def command?(command_type) commands.key?(command_type) && !commands[command_type].nil? end |
permalink #eql?(other) ⇒ Boolean Also known as: ==
Determines if two tools are equal
153 154 155 |
# File 'lib/reviewer/tool.rb', line 153 def eql?(other) settings == other.settings end |
permalink #formattable? ⇒ Boolean
Determines if the tool can run a ‘format` command
86 87 88 |
# File 'lib/reviewer/tool.rb', line 86 def formattable? command?(:format) end |
permalink #get_timing(command) ⇒ Object
[View source]
113 114 115 |
# File 'lib/reviewer/tool.rb', line 113 def get_timing(command) Reviewer.history.get(key, command.raw_string) || [] end |
permalink #install_link ⇒ String?
Returns the text for the install link if available
145 146 147 |
# File 'lib/reviewer/tool.rb', line 145 def install_link install_link? ? links.fetch(:install) : nil end |
permalink #install_link? ⇒ Boolean
Convenience method for determining if a tool has a configured install link
138 139 140 |
# File 'lib/reviewer/tool.rb', line 138 def install_link? links.key?(:install) && !links[:install].nil? end |
permalink #installable? ⇒ Boolean
Determines if the tool can run a ‘install` command
65 66 67 |
# File 'lib/reviewer/tool.rb', line 65 def installable? command?(:install) end |
permalink #last_prepared_at ⇒ Time
Specifies when the tool last had it’s ‘prepare` command run
93 94 95 96 97 |
# File 'lib/reviewer/tool.rb', line 93 def last_prepared_at date_string = Reviewer.history.get(key, :last_prepared_at) date_string == '' || date_string.nil? ? nil : DateTime.parse(date_string).to_time end |
permalink #last_prepared_at=(last_prepared_at) ⇒ DateTime
Sets the timestamp for when the tool last ran its ‘prepare` command
103 104 105 |
# File 'lib/reviewer/tool.rb', line 103 def last_prepared_at=(last_prepared_at) Reviewer.history.set(key, :last_prepared_at, last_prepared_at.to_s) end |
permalink #preparable? ⇒ Boolean
Determines if the tool can run a ‘prepare` command
72 73 74 |
# File 'lib/reviewer/tool.rb', line 72 def preparable? command?(:prepare) end |
permalink #prepare? ⇒ Boolean
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
50 51 52 |
# File 'lib/reviewer/tool.rb', line 50 def prepare? preparable? && stale? end |
permalink #record_timing(command, time) ⇒ Object
[View source]
117 118 119 120 121 122 123 |
# File 'lib/reviewer/tool.rb', line 117 def record_timing(command, time) return if time.nil? timing = get_timing(command).take(4) << time.round(2) Reviewer.history.set(key, command.raw_string, timing) end |
permalink #reviewable? ⇒ Boolean
Determines if the tool can run a ‘review` command
79 80 81 |
# File 'lib/reviewer/tool.rb', line 79 def reviewable? command?(:review) end |
permalink #stale? ⇒ Boolean
Determines whether the ‘prepare` command was run recently enough
129 130 131 132 133 |
# File 'lib/reviewer/tool.rb', line 129 def stale? return false unless preparable? last_prepared_at.nil? || last_prepared_at < Time.now - SIX_HOURS_IN_SECONDS end |