Class: Breaktime::Command
- Inherits:
-
Object
- Object
- Breaktime::Command
- Defined in:
- lib/breaktime/command.rb
Overview
Used to determine and run the screensaver command.
Defined Under Namespace
Classes: OSUnknown
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Class Method Summary collapse
-
.system_default(log) ⇒ Object
Determine the default screensaver command based on the user’s OS.
Instance Method Summary collapse
-
#execute ⇒ Object
Execute the command with Kernel#exec.
-
#initialize(command, log) ⇒ Command
constructor
Store the command if specified, or determine the system default.
Constructor Details
#initialize(command, log) ⇒ Command
Store the command if specified, or determine the system default.
33 34 35 36 37 38 39 40 |
# File 'lib/breaktime/command.rb', line 33 def initialize(command, log) @command = if command.nil? self.class.system_default(log) else log.debug { "User defined command: #{command}" } command end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/breaktime/command.rb', line 7 def command @command end |
Class Method Details
.system_default(log) ⇒ Object
Determine the default screensaver command based on the user’s OS.
If Linux, use the LinuxWinManager class to determine the appropriate command.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/breaktime/command.rb', line 13 def self.system_default(log) case RbConfig::CONFIG['target_os'] when 'linux' log.debug { "Using Linux, detecting window manager and appropriate command" } Breaktime::LinuxWinManager.detect_command(log) when 'darwin10' log.debug { "Using Mac OSX10" } 'open -a /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app' when /(mswin|mingw).*$/ log.debug { "Using Windows" } 'rundll32.exe user32.dll,LockWorkStation' else raise OSUnknown, 'Unknown OS' end end |
Instance Method Details
#execute ⇒ Object
Execute the command with Kernel#exec.
This replaces the current process, exiting when the command exits.
45 46 47 |
# File 'lib/breaktime/command.rb', line 45 def execute exec @command end |