Class: Lolcommits::Platform
- Inherits:
-
Object
- Object
- Lolcommits::Platform
- Defined in:
- lib/lolcommits/platform.rb
Class Method Summary collapse
-
.can_animate? ⇒ Boolean
Is the platform capable of capturing animated GIFs from webcam?.
-
.capturer_class(animate: false) ⇒ Object
The capturer class constant to use.
-
.command_which(cmd, only_path: false) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
-
.device_list ⇒ Object
Returns a list of system camera devices in a format suitable to display to the user.
-
.git_config_color_always? ⇒ Boolean
Is ‘git config color.ui` set to ’always’?.
-
.host_os ⇒ Object
return host_os identifier from the RbConfig::CONFIG constant.
-
.platform_cygwin? ⇒ Boolean
Are we on a Cygwin platform?.
-
.platform_linux? ⇒ Boolean
Are we on a Linux platform?.
-
.platform_mac? ⇒ Boolean
Are we on a Mac platform?.
-
.platform_windows? ⇒ Boolean
Are we on a Windows platform?.
-
.valid_ffmpeg_installed? ⇒ Boolean
Is a valid install of ffmpeg present on the system?.
-
.valid_imagemagick_installed? ⇒ Boolean
Is a valid install of imagemagick present on the system?.
Class Method Details
.can_animate? ⇒ Boolean
Is the platform capable of capturing animated GIFs from webcam?
58 59 60 |
# File 'lib/lolcommits/platform.rb', line 58 def self.can_animate? platform_linux? || platform_mac? || platform_windows? end |
.capturer_class(animate: false) ⇒ Object
The capturer class constant to use
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lolcommits/platform.rb', line 10 def self.capturer_class(animate: false) if ENV['LOLCOMMITS_CAPTURER'] const_get(ENV['LOLCOMMITS_CAPTURER']) elsif platform_mac? animate ? CaptureMacVideo : CaptureMac elsif platform_linux? animate ? CaptureLinuxVideo : CaptureLinux elsif platform_windows? animate ? CaptureWindowsVideo : CaptureWindows elsif platform_cygwin? CaptureCygwin else raise 'Unknown / Unsupported Platform.' end end |
.command_which(cmd, only_path: false) ⇒ Object
Cross-platform way of finding an executable in the $PATH.
Idea taken from bit.ly/qDaTbY, if only_path is true, only the path is returned (not the path and command)
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/lolcommits/platform.rb', line 93 def self.command_which(cmd, only_path: false) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = "#{path}/#{cmd}#{ext}" return only_path ? path : exe if File.executable? exe end end nil end |
.device_list ⇒ Object
Currently only functions on Mac.
Returns a list of system camera devices in a format suitable to display to the user.
122 123 124 125 126 127 128 |
# File 'lib/lolcommits/platform.rb', line 122 def self.device_list # TODO: handle other platforms here (linux/windows) e.g with ffmpeg -list_devices return unless Platform.platform_mac? videosnap = File.join(Configuration::LOLCOMMITS_ROOT, 'vendor', 'ext', 'videosnap', 'videosnap') `#{videosnap} -l` end |
.git_config_color_always? ⇒ Boolean
Is ‘git config color.ui` set to ’always’?
Due to a bug in the ruby-git library, git config for color.ui cannot be set to ‘always’ or it won’t read properly.
This helper method let’s us check for that error condition so we can alert the user in the CLI tool.
113 114 115 |
# File 'lib/lolcommits/platform.rb', line 113 def self.git_config_color_always? `git config color.ui`.chomp =~ /always/ end |
.host_os ⇒ Object
return host_os identifier from the RbConfig::CONFIG constant
52 53 54 |
# File 'lib/lolcommits/platform.rb', line 52 def self.host_os ENV['LOLCOMMITS_FAKE_HOST_OS'] || RbConfig::CONFIG['host_os'].downcase end |
.platform_cygwin? ⇒ Boolean
Are we on a Cygwin platform?
46 47 48 |
# File 'lib/lolcommits/platform.rb', line 46 def self.platform_cygwin? host_os.include?('cygwin') end |
.platform_linux? ⇒ Boolean
Are we on a Linux platform?
34 35 36 |
# File 'lib/lolcommits/platform.rb', line 34 def self.platform_linux? host_os.include?('linux') end |
.platform_mac? ⇒ Boolean
Are we on a Mac platform?
28 29 30 |
# File 'lib/lolcommits/platform.rb', line 28 def self.platform_mac? host_os.include?('darwin') end |
.platform_windows? ⇒ Boolean
Are we on a Windows platform?
40 41 42 |
# File 'lib/lolcommits/platform.rb', line 40 def self.platform_windows? !host_os.match(/(win|w)32/).nil? end |
.valid_ffmpeg_installed? ⇒ Boolean
For now, this just checks for presence, any version should work.
Is a valid install of ffmpeg present on the system?
80 81 82 |
# File 'lib/lolcommits/platform.rb', line 80 def self.valid_ffmpeg_installed? command_which('ffmpeg') end |
.valid_imagemagick_installed? ⇒ Boolean
Is a valid install of imagemagick present on the system?
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lolcommits/platform.rb', line 64 def self.valid_imagemagick_installed? return false unless command_which('identify') return false unless command_which('mogrify') # cli_version check will throw a MiniMagick::Error exception if IM is not # installed in PATH, since it attempts to parse output from `identify` !MiniMagick.cli_version.nil? rescue MiniMagick::Error false end |