Module: Cyberweb::BaseModule::FileRelatedFunctionality
- Included in:
- Cyberweb::Base, Objectified::HtmlTags::Head
- Defined in:
- lib/cyberweb/base_module/file_related_functionality/file_related_functionality.rb
Overview
Cyberweb::BaseModule::FileRelatedFunctionality
Instance Method Summary collapse
-
#copy_this_file(file, to_this_target = return_pwd) ⇒ Object
(also: #copy_file)
# === copy_this_file ========================================================================= #.
-
#cpr(from, to = return_pwd) ⇒ Object
# === cpr.
-
#delete_file(i) ⇒ Object
(also: #delete_files, #remove_file)
# === delete_file.
-
#filename_without_extension? ⇒ Boolean
# === filename_without_extension?.
-
#read_file_via_utf8_encoding(i) ⇒ Object
(also: #default_read)
# === read_file_via_utf8_encoding.
Instance Method Details
#copy_this_file(file, to_this_target = return_pwd) ⇒ Object Also known as: copy_file
#
copy_this_file
#
49 50 51 52 53 54 |
# File 'lib/cyberweb/base_module/file_related_functionality/file_related_functionality.rb', line 49 def copy_this_file( file, to_this_target = return_pwd ) FileUtils.cp(file, to_this_target) end |
#cpr(from, to = return_pwd) ⇒ Object
#
cpr
This method copies files recursively.
#
39 40 41 42 43 44 |
# File 'lib/cyberweb/base_module/file_related_functionality/file_related_functionality.rb', line 39 def cpr( from, to = return_pwd ) FileUtils.cp_r(from, to) end |
#delete_file(i) ⇒ Object Also known as: delete_files, remove_file
#
delete_file
This method can be used to remove a file.
#
25 26 27 28 29 30 31 |
# File 'lib/cyberweb/base_module/file_related_functionality/file_related_functionality.rb', line 25 def delete_file(i) if i.is_a? Array i.each {|entry| delete_file(entry) } else File.delete(i) if File.file?(i) # This also checks for existance. end end |
#filename_without_extension? ⇒ Boolean
#
filename_without_extension?
This method will return the raw filename, without extension.
For instance, if the filename is “index.cgi”, then this method will return the string “index”.
#
64 65 66 67 |
# File 'lib/cyberweb/base_module/file_related_functionality/file_related_functionality.rb', line 64 def filename_without_extension? _ = filename? return _.delete_suffix(File.extname(_)) end |
#read_file_via_utf8_encoding(i) ⇒ Object Also known as: default_read
#
read_file_via_utf8_encoding
This method can be used to read the content of a file.
It currently does not check whether the file at hand exists or not - perhaps this may change at a later time, though, which is why this notice is made.
Since as of July 2022 this is aliased to default_read().
#
80 81 82 83 84 |
# File 'lib/cyberweb/base_module/file_related_functionality/file_related_functionality.rb', line 80 def read_file_via_utf8_encoding(i) if File.exist? i return File.read(i, encoding: 'UTF-8') end end |