Class: HeartInspector
- Inherits:
-
Object
- Object
- HeartInspector
- Defined in:
- lib/tdd_heart.rb
Constant Summary collapse
- DEFAULTS =
{ tmux_location: ENV['HOME'] + "/.tmux.conf", target_setting: "set -g status-right", result_file: "/.guard_result" }
Instance Attribute Summary collapse
-
#existing_settings ⇒ Object
readonly
Returns the value of attribute existing_settings.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize ⇒ HeartInspector
constructor
A new instance of HeartInspector.
- #load_existing_settings(setting: nil, file_path: nil) ⇒ Object
- #new_status ⇒ Object
- #output(color) ⇒ Object
- #read_test_status(file_path = nil) ⇒ Object
- #refresh_status ⇒ Object
- #result_color ⇒ Object
- #success? ⇒ Boolean
- #update_status_command ⇒ Object
Constructor Details
#initialize ⇒ HeartInspector
10 11 12 |
# File 'lib/tdd_heart.rb', line 10 def initialize @existing_settings = load_existing_settings end |
Instance Attribute Details
#existing_settings ⇒ Object (readonly)
Returns the value of attribute existing_settings.
8 9 10 |
# File 'lib/tdd_heart.rb', line 8 def existing_settings @existing_settings end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
8 9 10 |
# File 'lib/tdd_heart.rb', line 8 def result @result end |
Instance Method Details
#load_existing_settings(setting: nil, file_path: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tdd_heart.rb', line 14 def load_existing_settings(setting: nil, file_path: nil) setting ||= DEFAULTS[:target_setting] file_path ||= DEFAULTS[:tmux_location] file = File.open file_path config = nil file.each { |line| config = line if /#{setting}/ =~ line } file.close config.chomp.split('"').last end |
#new_status ⇒ Object
37 38 39 |
# File 'lib/tdd_heart.rb', line 37 def new_status output(result_color) + " " + existing_settings end |
#output(color) ⇒ Object
59 60 61 |
# File 'lib/tdd_heart.rb', line 59 def output(color) "#[fg=#{color}]♥" end |
#read_test_status(file_path = nil) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/tdd_heart.rb', line 41 def read_test_status(file_path = nil) file_path ||= Dir.pwd + DEFAULTS[:result_file] return unless File.exists? file_path @result = File.read(file_path).chomp end |
#refresh_status ⇒ Object
27 28 29 30 |
# File 'lib/tdd_heart.rb', line 27 def refresh_status return unless read_test_status system(update_status_command) end |
#result_color ⇒ Object
55 56 57 |
# File 'lib/tdd_heart.rb', line 55 def result_color success? ? "green" : "red" end |
#success? ⇒ Boolean
49 50 51 52 53 |
# File 'lib/tdd_heart.rb', line 49 def success? return unless result !!(/success/ =~ result) end |
#update_status_command ⇒ Object
32 33 34 |
# File 'lib/tdd_heart.rb', line 32 def update_status_command "tmux set -g status-right '#{new_status}'" end |