Class: Repla::Logger
- Inherits:
-
Object
- Object
- Repla::Logger
- Defined in:
- lib/repla/logger.rb
Overview
Logger
Constant Summary collapse
- MESSAGE_PREFIX =
'MESSAGE '.freeze
- ERROR_PREFIX =
'ERROR '.freeze
- LOG_PLUGIN_NAME =
'Log'.freeze
- SHOW_LOG_SCRIPT =
Toggle
File.join(APPLESCRIPT_DIRECTORY, 'show_log.scpt')
- HIDE_LOG_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'hide_log.scpt')
- TOGGLE_LOG_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'toggle_log.scpt')
Instance Method Summary collapse
- #error(message) ⇒ Object
- #hide ⇒ Object
-
#info(message) ⇒ Object
Messages.
-
#initialize(window_id = nil) ⇒ Logger
constructor
A new instance of Logger.
- #show ⇒ Object
- #toggle ⇒ Object
- #view_id ⇒ Object
-
#window_id ⇒ Object
Properties.
Constructor Details
#initialize(window_id = nil) ⇒ Logger
Returns a new instance of Logger.
10 11 12 13 |
# File 'lib/repla/logger.rb', line 10 def initialize(window_id = nil) @window_id = window_id @mutex = Mutex.new end |
Instance Method Details
#error(message) ⇒ Object
41 42 43 44 45 |
# File 'lib/repla/logger.rb', line 41 def error() = .dup .gsub!(/^/, ERROR_PREFIX) () end |
#hide ⇒ Object
22 23 24 |
# File 'lib/repla/logger.rb', line 22 def hide Repla.run_applescript(HIDE_LOG_SCRIPT, [window_id]) end |
#info(message) ⇒ Object
Messages
33 34 35 36 37 38 39 |
# File 'lib/repla/logger.rb', line 33 def info() = .dup .gsub!(/^/, MESSAGE_PREFIX) # Prefix all lines # Strip trailing white space # Add a line break () end |
#show ⇒ Object
17 18 19 |
# File 'lib/repla/logger.rb', line 17 def show Repla.run_applescript(SHOW_LOG_SCRIPT, [window_id]) end |
#toggle ⇒ Object
27 28 29 |
# File 'lib/repla/logger.rb', line 27 def toggle Repla.run_applescript(TOGGLE_LOG_SCRIPT, [window_id]) end |
#view_id ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/repla/logger.rb', line 54 def view_id view_id = nil @mutex.synchronize do @view_id ||= Repla.split_id_in_window(window_id, LOG_PLUGIN_NAME) return @view_id unless @view_id.nil? @view_id = Repla.split_id_in_window_last(window_id) Repla.run_plugin_in_split(LOG_PLUGIN_NAME, window_id, @view_id) view_id = @view_id end view_id end |
#window_id ⇒ Object
Properties
49 50 51 52 |
# File 'lib/repla/logger.rb', line 49 def window_id key = WINDOW_ID_KEY @window_id ||= ENV.key?(key) ? ENV[key] : Repla.create_window end |