Class: Aspera::OpenApplication
- Inherits:
-
Object
- Object
- Aspera::OpenApplication
- Includes:
- Singleton
- Defined in:
- lib/aspera/open_application.rb
Overview
Allows a user to open a Url if method is “text”, then URL is displayed on terminal if method is “graphical”, then the URL will be opened with the default browser.
Constant Summary collapse
- USER_INTERFACES =
%i[text graphical].freeze
Instance Attribute Summary collapse
-
#url_method ⇒ Object
self.
Class Method Summary collapse
- .default_gui_mode ⇒ Object
- .editor(file_path) ⇒ Object
-
.uri_graphical(uri) ⇒ Object
command must be non blocking.
-
.user_interfaces ⇒ Object
User Interfaces.
Instance Method Summary collapse
-
#initialize ⇒ OpenApplication
constructor
A new instance of OpenApplication.
-
#uri(the_url) ⇒ Object
this is non blocking.
Constructor Details
#initialize ⇒ OpenApplication
Returns a new instance of OpenApplication.
50 51 52 |
# File 'lib/aspera/open_application.rb', line 50 def initialize @url_method = self.class.default_gui_mode end |
Instance Attribute Details
#url_method ⇒ Object
self
48 49 50 |
# File 'lib/aspera/open_application.rb', line 48 def url_method @url_method end |
Class Method Details
.default_gui_mode ⇒ Object
19 20 21 22 23 24 |
# File 'lib/aspera/open_application.rb', line 19 def default_gui_mode return :graphical if [Environment::OS_WINDOWS, Environment::OS_X].include?(Environment.os) # unix family return :graphical if ENV.key?('DISPLAY') && !ENV['DISPLAY'].empty? return :text end |
.editor(file_path) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/aspera/open_application.rb', line 37 def editor(file_path) if ENV.key?('EDITOR') system(ENV['EDITOR'], file_path.to_s) elsif Environment.os.eql?(Environment::OS_WINDOWS) system('notepad.exe', %Q{"#{file_path}"}) else uri_graphical(file_path.to_s) end end |
.uri_graphical(uri) ⇒ Object
command must be non blocking
27 28 29 30 31 32 33 34 35 |
# File 'lib/aspera/open_application.rb', line 27 def uri_graphical(uri) case Environment.os when Environment::OS_X then return system('open', uri.to_s) when Environment::OS_WINDOWS then return system('start', 'explorer', %Q{"#{uri}"}) when Environment::OS_LINUX then return system('xdg-open', uri.to_s) else raise "no graphical open method for #{Environment.os}" end end |
.user_interfaces ⇒ Object
User Interfaces
17 |
# File 'lib/aspera/open_application.rb', line 17 def user_interfaces; USER_INTERFACES; end |
Instance Method Details
#uri(the_url) ⇒ Object
this is non blocking
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/aspera/open_application.rb', line 55 def uri(the_url) case @url_method when :graphical self.class.uri_graphical(the_url) when :text case the_url.to_s when /^http/ puts "USER ACTION: please enter this url in a browser:\n#{the_url.to_s.red}\n" else puts "USER ACTION: open this:\n#{the_url.to_s.red}\n" end else raise StandardError, "unsupported url open method: #{@url_method}" end end |