Module: Open
- Defined in:
- lib/open/base/base.rb,
lib/open/last/last.rb,
lib/open/open/open.rb,
lib/open/books/books.rb,
lib/open/project/project.rb,
lib/open/version/version.rb,
lib/open/last_url/last_url.rb,
lib/open/toplevel_methods/e.rb,
lib/open/constants/constants.rb,
lib/open/in_editor/in_editor.rb,
lib/open/nano_open/nano_open.rb,
lib/open/in_browser/in_browser.rb,
lib/open/requires/require_yaml.rb,
lib/open/toplevel_methods/misc.rb,
lib/open/with_delay/with_delay.rb,
lib/open/toplevel_methods/delay.rb,
lib/open/these_files/these_files.rb,
lib/open/toplevel_methods/editor.rb,
lib/open/toplevel_methods/browser.rb,
lib/open/toplevel_methods/host_os.rb,
lib/open/toplevel_methods/is_on_roebe.rb,
lib/open/toplevel_methods/is_on_windows.rb
Overview
#
require ‘open/toplevel_methods/is_on_windows.rb’
#
Defined Under Namespace
Classes: Base, Book, InBrowser, InEditor, Last, LastUrl, NanoOpen, Open, TheseFiles, WithDelay
Constant Summary collapse
- PROJECT_BASE_DIRECTORY =
#
Open::PROJECT_BASE_DIRECTORY
#
File.absolute_path("#{__dir__}/..")+'/'
- PROJECT_YAML_DIRECTORY =
#
Open::PROJECT_YAML_DIRECTORY
#
"#{Open.project_base_dir?}yaml/"
- VERSION =
#
VERSION
#
'0.2.21'
- LAST_UPDATE =
#
LAST_UPDATE
#
'05.12.2023'
- IN_BACKGROUND =
#
IN_BACKGROUND
#
' &'
- HOME_DIRECTORY_OF_USER_X =
#
HOME_DIRECTORY_OF_USER_X
This constant is only useful on my home system.
#
'/home/x/'
- RUBY_SRC =
#
RUBY_SRC
#
"#{HOME_DIRECTORY_OF_USER_X}programming/ruby/src/"
- PROGRAMMING_LANGUAGES_DIRECTORY_AT_HOME =
#
PROGRAMMING_LANGUAGES_DIRECTORY_AT_HOME
#
"#{HOME_DIRECTORY_OF_USER_X}programming/"
- USERFIND =
#
USERFIND
#
"find #{HOME_DIRECTORY_OF_USER_X}data -name"
- MY_DATA =
#
MY_DATA
This is functionality equivalent to the String ‘/home/x/data/’. It is only really useful for my own home setup.
#
"#{HOME_DIRECTORY_OF_USER_X}data/"
- DATA_DIRECTORY_AT_HOME =
DATA_DIRECTORY_AT_HOME
MY_DATA
- N_DELAY =
#
N_DELAY
This delay is specifically used for delaying before batch-opening files via the Open.in_editor() functionality. It does not apply to the Open.in_browser() functionality.
#
0.48
- LOCATION_OF_BROWSER_YAML_FILE =
#
Open::LOCATION_OF_BROWSER_YAML_FILE
Here we must define where we store the location for our browser.
That file will tell us which browser to use.
Most users will not have this file, so the code will have to remain flexible in this regard.
On my home system this will point towards the following file:
/home/Programs/Ruby/3.1.2/lib/ruby/site_ruby/3.1.0/open/yaml/use_this_browser.yml
#
"#{project_yaml_directory?}use_this_browser.yml"
- FILE_SHORTCUTS =
#
FILE_SHORTCUTS
#
"#{project_yaml_directory?}shortcuts.yml"
- LOCATION_OF_EDITOR_YAML_FILE =
#
LOCATION_OF_EDITOR_YAML_FILE
#
"#{project_yaml_directory?}use_this_editor.yml"
- USE_THIS_EDITOR =
else use a hardcoded default
'bluefish'
- USE_THIS_BROWSER =
else use a hardcoded default
'firefox'
- ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR =
#
ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR
All extensions that can be opened in the editor should be registered in this constant.
For example, “h” means “.h” aka a C or C++ header file.
#
%w( php rb txt yaml yml cgi md gemspec html csv py conf c sh js log css cr ascii la pl perl java json js fasta fa m3u cpp go gff gff3 gen h erb sinatra sql ).sort << ''
- ARRAY_VIDEOS =
#
ARRAY_VIDEOS
#
%w( vob avi flv mp3 mp4 )
- ARRAY_IMAGES =
#
ARRAY_IMAGES
All file-extensions for images can be registered in this Array.
#
%w( png jpg gif jpeg tiff tif bmp avif )
Class Method Summary collapse
-
.e(i = '') ⇒ Object
# === Open.e ========================================================================= #.
-
.file_browser? ⇒ Boolean
# === Open.file_browser? ========================================================================= #.
-
.host_os? ⇒ Boolean
# === Open.host_os?.
-
.in_browser(i = ARGV, &block) ⇒ Object
# === Open.in_browser.
-
.in_editor(i = ARGV, &block) ⇒ Object
# === Open.in_editor.
-
.is_on_roebe? ⇒ Boolean
# === Roebe.is_on_roebe? ========================================================================= #.
-
.is_on_windows?(i = host_os? ) ⇒ Boolean
# === Open.is_on_windows? ========================================================================= #.
-
.last_url(optional_arguments = ARGV) ⇒ Object
# === Open.last_url =========================================================================== #.
-
.open(i = ARGV, &block) ⇒ Object
# === Open.open =========================================================================== #.
-
.open_last(i = ARGV) ⇒ Object
# === Open.open_last =========================================================================== #.
-
.pdf_viewer? ⇒ Boolean
# === Open.pdf_viewer?.
-
.permanently_use_this_browser(this_browser = 'thorium', store_into_this_file = ::Open::LOCATION_OF_BROWSER_YAML_FILE) ⇒ Object
# === Open.permanently_use_this_browser.
-
.project_base_directory? ⇒ Boolean
# === Open.project_base_directory? ========================================================================= #.
-
.project_yaml_dir? ⇒ Boolean
# === Open.project_yaml_dir?.
-
.set_use_this_browser(i = USE_THIS_BROWSER) ⇒ Object
# === Open.set_use_this_browser.
-
.set_use_this_editor(i = USE_THIS_EDITOR) ⇒ Object
# === Open.set_use_this_editor.
-
.these_files(i = ARGV, &block) ⇒ Object
# === Open.these_files =========================================================================== #.
-
.use_which_browser? ⇒ Boolean
# === Open.use_which_browser?.
-
.use_which_delay? ⇒ Boolean
# === Open.use_which_delay? ========================================================================= #.
-
.use_which_editor? ⇒ Boolean
# === Open.use_which_editor? ========================================================================= #.
-
.with_delay(i = ARGV) ⇒ Object
# === Open.with_delay =========================================================================== #.
-
.write_what_into(what, into) ⇒ Object
# === Open.write_what_into.
Class Method Details
.e(i = '') ⇒ Object
#
Open.e
#
10 11 12 |
# File 'lib/open/toplevel_methods/e.rb', line 10 def self.e(i = '') puts i end |
.file_browser? ⇒ Boolean
#
Open.file_browser?
#
79 80 81 |
# File 'lib/open/constants/constants.rb', line 79 def self.file_browser? LOCATION_OF_BROWSER_YAML_FILE end |
.host_os? ⇒ Boolean
#
Open.host_os?
Return the host-operating system via this method.
On linux this method would yield the String “linux”.
#
16 17 18 |
# File 'lib/open/toplevel_methods/host_os.rb', line 16 def self.host_os? ::RbConfig::CONFIG['host_os'] end |
.in_browser(i = ARGV, &block) ⇒ Object
#
Open.in_browser
This method will always join the input-argument before passing it to the class.
Note that the behaviour of Open.in_browser() is in-sync with the method Open.in_editor(), in regards to joinable arguments (typically an Array as input). If you do not want this behaviour then you may have to prepare for this in your own code, such as by having an Array and iterating over it before passing the individual entries into Open.in_browser().
Note that this method needs to be somewhat flexible, as we can provide varied input such as shown in the following examples:
Open.open_in_browser(port: 8080)
Open.in_browser(remote_URL) {{ use_this_browser: :firefox }}
Open.in_browser(:default_sinatra_port)
#
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/open/in_browser/in_browser.rb', line 725 def self.in_browser( i = ARGV, &block ) if i.respond_to? :join # ======================================================================= # # This will only join entries that do not start with '--'. # ======================================================================= # entries_that_start_with_hyphens = i.select {|entry| entry.start_with?('--') } i.reject! {|entry| entry.start_with?('--') } new_array = [] new_array << i.join(' ').strip new_array << entries_that_start_with_hyphens unless entries_that_start_with_hyphens.empty? i = new_array end # ========================================================================= # # === Handle blocks next # ========================================================================= # if block_given? yielded = yield # ======================================================================= # # === Handle Hashes next # ======================================================================= # if yielded.is_a? Hash # ===================================================================== # # === :delay # ===================================================================== # if yielded.has_key? :delay _ = yielded.delete(:delay) if _.is_a? String _ = _.sub(/ seconds/,'') _ = _.sub(/ second/,'').to_f if _.include? ' second' _ = _.to_f # Need a Float. end sleep(_) end end end return ::Open::InBrowser.new(i, &block) end |
.in_editor(i = ARGV, &block) ⇒ Object
#
Open.in_editor
Note that the behaviour of Open.in_editor() is in-sync with the method Open.in_browser(), in regards to joinable arguments (typically an Array as input). If you do not want this behaviour then you may have to prepare for this in your own code, such as by having an Array and iterating over it before passing the individual entries into Open.in_editor().
Usage examples:
Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
Or the lock variant:
Open.in_editor {{
this_file: first_argument?,
use_this_editor: :nano
}}
Which may also look like this:
::Open.in_editor {{
this_file: _,
use_this_editor: :bluefish
}}
#
516 517 518 519 520 521 522 523 524 |
# File 'lib/open/in_editor/in_editor.rb', line 516 def self.in_editor( i = ARGV, &block ) if i.respond_to? :join i.join(' ').strip end ::Open::InEditor.new(i, &block) end |
.is_on_roebe? ⇒ Boolean
#
Roebe.is_on_roebe?
#
12 13 14 |
# File 'lib/open/toplevel_methods/is_on_roebe.rb', line 12 def self.is_on_roebe? ENV['IS_ROEBE'].to_s == '1' end |
.is_on_windows?(i = host_os? ) ⇒ Boolean
#
Open.is_on_windows?
#
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/open/toplevel_methods/is_on_windows.rb', line 14 def self.is_on_windows?( i = host_os? ) case i # or: RUBY_PLATFORM when /win/, /mingw/ true else false end end |
.last_url(optional_arguments = ARGV) ⇒ Object
#
Open.last_url
#
144 145 146 |
# File 'lib/open/last_url/last_url.rb', line 144 def self.last_url(optional_arguments = ARGV) ::Open::LastUrl[optional_arguments] end |
.open(i = ARGV, &block) ⇒ Object
#
Open.open
#
976 977 978 979 980 |
# File 'lib/open/open/open.rb', line 976 def self.open( i = ARGV, &block ) ::Open::Open.new(i, &block) end |
.open_last(i = ARGV) ⇒ Object
#
Open.open_last
#
137 138 139 |
# File 'lib/open/last/last.rb', line 137 def self.open_last(i = ARGV) ::Open::Last.new(i) end |
.pdf_viewer? ⇒ Boolean
#
Open.pdf_viewer?
This method can be used to query the pdf-viewer in use.
#
987 988 989 990 991 992 993 |
# File 'lib/open/open/open.rb', line 987 def self.pdf_viewer? unless (Object.const_defined?(:PdfParadise) and PdfParadise.const_defined?(:MainPdf)) require 'pdf_paradise/main_pdf/main_pdf.rb' end return ::PdfParadise.use_which_pdf_viewer? end |
.permanently_use_this_browser(this_browser = 'thorium', store_into_this_file = ::Open::LOCATION_OF_BROWSER_YAML_FILE) ⇒ Object
#
Open.permanently_use_this_browser
This method can be used to permanently store a new browser, for the open gem.
#
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/open/toplevel_methods/browser.rb', line 45 def self.permanently_use_this_browser( this_browser = 'thorium', store_into_this_file = ::Open::LOCATION_OF_BROWSER_YAML_FILE ) case this_browser # Symbols are treated a bit differently here. # ======================================================================= # # === :firefox # ======================================================================= # when :firefox this_browser = '/usr/bin/firefox' end this_browser = this_browser.to_s # We need a String. e "Storing into `#{store_into_this_file}`." write_what_into(this_browser, store_into_this_file) if is_on_roebe? store_into_this_file = "#{RUBY_SRC}open/lib/open/yaml/use_this_browser.yml" e "Storing into `#{store_into_this_file}`." write_what_into(this_browser, store_into_this_file) end end |
.project_base_directory? ⇒ Boolean
#
Open.project_base_directory?
#
19 20 21 |
# File 'lib/open/project/project.rb', line 19 def self.project_base_directory? PROJECT_BASE_DIRECTORY end |
.project_yaml_dir? ⇒ Boolean
#
Open.project_yaml_dir?
This is a query-method for the constant PROJECT_YAML_DIRECTORY.
#
36 37 38 |
# File 'lib/open/project/project.rb', line 36 def self.project_yaml_dir? PROJECT_YAML_DIRECTORY end |
.set_use_this_browser(i = USE_THIS_BROWSER) ⇒ Object
#
Open.set_use_this_browser
This method can be used to assign a different browser.
#
21 22 23 24 25 |
# File 'lib/open/toplevel_methods/browser.rb', line 21 def self.set_use_this_browser( i = USE_THIS_BROWSER ) @use_this_browser = i end |
.set_use_this_editor(i = USE_THIS_EDITOR) ⇒ Object
#
Open.set_use_this_editor
Modify the toplevel variable @use_this_editor through this method.
#
21 22 23 24 25 |
# File 'lib/open/toplevel_methods/editor.rb', line 21 def self.set_use_this_editor( i = USE_THIS_EDITOR ) @use_this_editor = i end |
.these_files(i = ARGV, &block) ⇒ Object
#
Open.these_files
#
103 104 105 106 107 |
# File 'lib/open/these_files/these_files.rb', line 103 def self.these_files( i = ARGV, &block ) ::Open::TheseFiles.new(i, &block) end |
.use_which_browser? ⇒ Boolean
#
Open.use_which_browser?
Query-method to determine which browser is currently designated to be the main browser, as far as the open-gem is concerned.
#
35 36 37 |
# File 'lib/open/toplevel_methods/browser.rb', line 35 def self.use_which_browser? @use_this_browser end |
.use_which_delay? ⇒ Boolean
#
Open.use_which_delay?
#
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/open/toplevel_methods/delay.rb', line 12 def self.use_which_delay? require 'open/project/project.rb' require 'open/requires/require_yaml.rb' _ = "#{project_base_directory?}yaml/use_this_delay.yml" if File.exist? _ YAML.load_file(_) else '1.0' end end |
.use_which_editor? ⇒ Boolean
#
Open.use_which_editor?
#
32 33 34 |
# File 'lib/open/toplevel_methods/editor.rb', line 32 def self.use_which_editor? @use_this_editor end |
.with_delay(i = ARGV) ⇒ Object
#
Open.with_delay
#
251 252 253 |
# File 'lib/open/with_delay/with_delay.rb', line 251 def self.with_delay(i = ARGV) Open::WithDelay.new(i) end |
.write_what_into(what, into) ⇒ Object
#
Open.write_what_into
Delegate towards SaveFile.
#
16 17 18 |
# File 'lib/open/toplevel_methods/misc.rb', line 16 def self.write_what_into(what, into) ::SaveFile.write_what_into(what, into) end |