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
Returns a new instance of 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
43 44 45 46 |
# File 'lib/tdd_heart.rb', line 43 def new_status return existing_settings if result.nil? output(result_color) + ' ' + existing_settings end |
#output(color) ⇒ Object
58 59 60 |
# File 'lib/tdd_heart.rb', line 58 def output(color) "#[fg=#{color}]♥" end |
#read_test_status(file_path = nil) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/tdd_heart.rb', line 32 def read_test_status(file_path = nil) file_path ||= Dir.pwd + DEFAULTS[:result_file] return unless File.exist? 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 read_test_status system(update_status_command) end |
#result_color ⇒ Object
48 49 50 |
# File 'lib/tdd_heart.rb', line 48 def result_color success? ? 'green' : 'red' end |
#success? ⇒ Boolean
52 53 54 55 56 |
# File 'lib/tdd_heart.rb', line 52 def success? return unless result !!(/success/ =~ result) end |
#update_status_command ⇒ Object
39 40 41 |
# File 'lib/tdd_heart.rb', line 39 def update_status_command "tmux set -g status-right '#{new_status}'" end |