Module: Open

Defined in:
lib/open/base/base.rb,
lib/open/open.rb,
lib/open/last/last.rb,
lib/open/project/project.rb,
lib/open/version/version.rb,
lib/open/last_url/last_url.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/with_delay/with_delay.rb,
lib/open/these_files/these_files.rb,
lib/open/toplevel_code/toplevel_code.rb

Overview

#

require ‘open/toplevel_code/toplevel_code.rb’

#

Defined Under Namespace

Classes: Base, 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.1.30'
LAST_UPDATE =
#

LAST_UPDATE

#
'16.05.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/’.

#
"#{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.

#
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'

Class Method Summary collapse

Class Method Details

.e(i = '') ⇒ Object

#

Open.e

#


32
33
34
# File 'lib/open/toplevel_code/toplevel_code.rb', line 32

def self.e(i = '')
  puts i
end

.file_browser?Boolean

#

Open.file_browser?

#

Returns:

  • (Boolean)


77
78
79
# File 'lib/open/constants/constants.rb', line 77

def self.file_browser?
  LOCATION_OF_BROWSER_YAML_FILE
end

.host_os?Boolean

#

Open.host_os?

Return the host-operating system via this method.

#

Returns:

  • (Boolean)


41
42
43
# File 'lib/open/toplevel_code/toplevel_code.rb', line 41

def self.host_os?
  ::RbConfig::CONFIG['host_os']
end

.in_editor(i = ARGV, &block) ⇒ Object

#

Open.in_editor

Usage examples:

Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')

Or theb lock variant:

Open.in_editor {{
  this_file:       first_argument?,
  use_this_editor: :nano
}}
#


324
325
326
327
328
# File 'lib/open/in_editor/in_editor.rb', line 324

def self.in_editor(
    i = ARGV, &block
  )
  ::Open::InEditor.new(i, &block)
end

.is_on_roebe?Boolean

#

Roebe.is_on_roebe?

#

Returns:

  • (Boolean)


153
154
155
# File 'lib/open/toplevel_code/toplevel_code.rb', line 153

def self.is_on_roebe?
  ENV['IS_ROEBE'].to_s == '1'
end

.is_on_windows?(i = host_os?) ) ⇒ Boolean

#

Open.is_on_windows?

#

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
# File 'lib/open/toplevel_code/toplevel_code.rb', line 48

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

#


143
144
145
# File 'lib/open/last_url/last_url.rb', line 143

def self.last_url(optional_arguments = ARGV)
  ::Open::LastUrl[optional_arguments]
end

.open(i = ARGV, &block) ⇒ Object

#

Open.open

#


1039
1040
1041
# File 'lib/open/open.rb', line 1039

def self.open(i = ARGV, &block)
  ::Open::Open.new(i, &block)
end

.open_in_browser(i = ARGV, &block) ⇒ Object

#

Open.open_in_browser

Note that this method needs to be somewhat flexible, as we can provide varied input such as:

Open.open_in_browser(port: 8080)
Open.in_browser(remote_URL) {{ use_this_browser: :firefox }}
#


551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/open/in_browser/in_browser.rb', line 551

def self.open_in_browser(
    i = ARGV,
    &block
  )
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    # ===================================================================== #
    # === Handle Hashes next
    # ===================================================================== #
    if yielded.is_a? Hash
      # =================================================================== #
      # === Handle Hashes past this point
      # =================================================================== #
      # =================================================================== #
      # === :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
  # else
  end
  ::Open::InBrowser.new(i, &block)
end

.open_last(i = ARGV) ⇒ Object

#

Open.open_last

#


135
136
137
# File 'lib/open/last/last.rb', line 135

def self.open_last(i = ARGV)
  ::Open::Last.new(i)
end

.pdf_viewer?Boolean

#

Open.pdf_viewer?

#

Returns:

  • (Boolean)


1046
1047
1048
1049
1050
1051
# File 'lib/open/open.rb', line 1046

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.

#


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/open/toplevel_code/toplevel_code.rb', line 163

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 = '/home/x/programming/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?

#

Returns:

  • (Boolean)


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.

#

Returns:

  • (Boolean)


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.

#


93
94
95
96
97
# File 'lib/open/toplevel_code/toplevel_code.rb', line 93

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.

#


68
69
70
71
72
# File 'lib/open/toplevel_code/toplevel_code.rb', line 68

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.

#

Returns:

  • (Boolean)


107
108
109
# File 'lib/open/toplevel_code/toplevel_code.rb', line 107

def self.use_which_browser?
  @use_this_browser
end

.use_which_delay?Boolean

#

Open.use_which_delay?

#

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/open/toplevel_code/toplevel_code.rb', line 20

def self.use_which_delay?
  _ = "#{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?

#

Returns:

  • (Boolean)


79
80
81
# File 'lib/open/toplevel_code/toplevel_code.rb', line 79

def self.use_which_editor?
  @use_this_editor
end

.with_delay(i = ARGV) ⇒ Object

#

Open.with_delay

#


252
253
254
# File 'lib/open/with_delay/with_delay.rb', line 252

def self.with_delay(i = ARGV)
  Open::WithDelay.new(i)
end

.write_what_into(what, into) ⇒ Object

#

Open.write_what_into

Delegate towards SaveFile.

#


116
117
118
# File 'lib/open/toplevel_code/toplevel_code.rb', line 116

def self.write_what_into(what, into)
  ::SaveFile.write_what_into(what, into)
end