Module: GamesAndRpgParadise::CommonExtensions
- Included in:
- Base::Extensions
- Defined in:
- lib/games_and_rpg_paradise/base/extensions/common_extensions.rb
Overview
GamesAndRpgParadise::CommonExtensions
Constant Summary collapse
- N =
#
N
#
"\n"
- CONTROL_C_CODE =
#
CONTROL_C_CODE
The Ctrl-c interrupt combination.
#
"\u0003"
Instance Method Summary collapse
-
#cat(i) ⇒ Object
# === cat.
-
#cd(i = Dir.pwd) ⇒ Object
# === cd (cd tag).
-
#cliner ⇒ Object
# === cliner ========================================================================= #.
-
#copy_file(a, b) ⇒ Object
# === copy_file ========================================================================= #.
-
#delete(i) ⇒ Object
# === delete ========================================================================= #.
-
#dirname_but_retains_the_trailing_slash(i) ⇒ Object
# === dirname_but_retains_the_trailing_slash ========================================================================= #.
-
#disable_colours ⇒ Object
# === disable_colours ========================================================================= #.
-
#ensure_that_the_log_directory_exists ⇒ Object
# === ensure_that_the_log_directory_exists =========================================================================== #.
-
#esystem(i = '') ⇒ Object
# === esystem ========================================================================= #.
-
#get_user_input ⇒ Object
# === get_user_input.
-
#infer_the_namespace ⇒ Object
# === infer_the_namespace.
-
#is_on_roebe? ⇒ Boolean
# === is_on_roebe? ========================================================================= #.
-
#log_dir? ⇒ Boolean
# === log_dir? ========================================================================= #.
-
#mkdir(i) ⇒ Object
(also: #create_directory)
# === mkdir (mkdir tag) ========================================================================= #.
-
#mkdir_then_cd_into_it(i) ⇒ Object
# === mkdir_then_cd_into_it ========================================================================= #.
-
#mv(old_name, new_name) ⇒ Object
(also: #move_file)
# === mv ========================================================================= #.
-
#namespace? ⇒ Boolean
# === namespace? ========================================================================= #.
-
#opne(i = '') ⇒ Object
# === opne ========================================================================= #.
-
#opnn(i = { namespace: namespace? }) ⇒ Object
# === opnn ========================================================================= #.
-
#project_base_directory? ⇒ Boolean
(also: #project_base_dir?)
# === project_base_directory? ========================================================================= #.
-
#project_image_directory? ⇒ Boolean
# === project_image_directory? =========================================================================== #.
-
#project_yaml_directory? ⇒ Boolean
(also: #project_yaml_dir?, #yaml_directory?, #yaml_dir?)
# === project_yaml_directory? ========================================================================= #.
-
#rds(i) ⇒ Object
# === rds =========================================================================== #.
-
#register_sigint ⇒ Object
# === register_sigint ========================================================================= #.
-
#remove_this_directory(i, be_verbose = false) ⇒ Object
(also: #remove_directory)
# === remove_this_directory ========================================================================= #.
-
#rename_file(old, new) ⇒ Object
# === rename_file ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#reset_the_internal_hash ⇒ Object
# === reset_the_internal_hash.
-
#return_pwd ⇒ Object
# === return_pwd ========================================================================= #.
-
#return_today ⇒ Object
# === return_today ========================================================================= #.
-
#touch_file(i) ⇒ Object
(also: #touch)
# === touch_file (touch tag) ========================================================================= #.
-
#wrap(i, use_this_as_word_wrap_delimiter = :default) ⇒ Object
(also: #word_wrap)
# === wrap (wrap tag).
-
#write_what_into(what, into) ⇒ Object
# === write_what_into ========================================================================= #.
Instance Method Details
#cat(i) ⇒ Object
#
cat
This will read and display file content.
#
180 181 182 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 180 def cat(i) GamesAndRpgParadise.cat(i) end |
#cd(i = Dir.pwd) ⇒ Object
#
cd (cd tag)
Or via:
require 'games_and_rpg_paradise/toplevel_methods/cd.rb'
::GamesAndRpgParadise.cd(i)
#
265 266 267 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 265 def cd(i = Dir.pwd) Dir.chdir(i) if File.directory? i end |
#cliner ⇒ Object
#
cliner
#
140 141 142 143 144 145 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 140 def cliner begin require 'cliner' unless Object.const_defined?(:Cliner) ::Cliner.cliner rescue LoadError; end end |
#copy_file(a, b) ⇒ Object
#
copy_file
#
133 134 135 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 133 def copy_file(a, b) GamesAndRpgParadise.copy_file(a, b) end |
#delete(i) ⇒ Object
#
delete
#
210 211 212 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 210 def delete(i) ::GamesAndRpgParadise.delete(i) end |
#dirname_but_retains_the_trailing_slash(i) ⇒ Object
#
dirname_but_retains_the_trailing_slash
#
232 233 234 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 232 def dirname_but_retains_the_trailing_slash(i) return "#{File.dirname(i)}/".squeeze('/') end |
#disable_colours ⇒ Object
#
disable_colours
#
125 126 127 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 125 def disable_colours @use_colours = false end |
#ensure_that_the_log_directory_exists ⇒ Object
#
ensure_that_the_log_directory_exists
#
310 311 312 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 310 def ensure_that_the_log_directory_exists GamesAndRpgParadise.ensure_that_the_log_directory_exists end |
#esystem(i = '') ⇒ Object
#
esystem
#
188 189 190 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 188 def esystem(i = '') GamesAndRpgParadise.esystem(i) end |
#get_user_input ⇒ Object
#
get_user_input
This method will fetch user input. It will return a String if all went fine, and false otherwise.
#
220 221 222 223 224 225 226 227 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 220 def get_user_input begin result = $stdin.gets.chomp return result.to_s rescue Interrupt # Rescue User Interrupt here. return false end end |
#infer_the_namespace ⇒ Object
#
infer_the_namespace
This will assume the true namespace from the inspectable name.
#
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 101 def infer_the_namespace _ = inspect.to_s.delete('<') if _.include? ' ' _ = _.split(' ').first.delete('#') if _.include? ':' _ = _.split(':')[0 .. -2].reject {|entry| entry.empty? }.join('::') end end if _.include?(':0') _ = _.split(':0').first.to_s end @namespace = _.delete('#') # And assign it here. end |
#is_on_roebe? ⇒ Boolean
#
is_on_roebe?
#
196 197 198 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 196 def is_on_roebe? GamesAndRpgParadise.is_on_roebe? end |
#log_dir? ⇒ Boolean
#
log_dir?
#
272 273 274 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 272 def log_dir? ::GamesAndRpgParadise.log_dir? end |
#mkdir(i) ⇒ Object Also known as: create_directory
#
mkdir (mkdir tag)
#
287 288 289 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 287 def mkdir(i) GamesAndRpgParadise.mkdir(i) end |
#mkdir_then_cd_into_it(i) ⇒ Object
#
mkdir_then_cd_into_it
#
294 295 296 297 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 294 def mkdir_then_cd_into_it(i) mkdir(i) unless File.directory?(i) cd(i) end |
#mv(old_name, new_name) ⇒ Object Also known as: move_file
#
mv
#
170 171 172 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 170 def mv(old_name, new_name) GamesAndRpgParadise.mv(old_name, new_name) end |
#namespace? ⇒ Boolean
#
namespace?
#
85 86 87 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 85 def namespace? @namespace end |
#opne(i = '') ⇒ Object
#
opne
#
92 93 94 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 92 def opne(i = '') opnn; e i end |
#opnn(i = { namespace: namespace? }) ⇒ Object
#
opnn
#
59 60 61 62 63 64 65 66 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 59 def opnn( i = { namespace: namespace? } ) if i.is_a? String i = { namespace: i } end Opn.opn(i) if Object.const_defined? :Opn end |
#project_base_directory? ⇒ Boolean Also known as: project_base_dir?
#
project_base_directory?
#
279 280 281 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 279 def project_base_directory? ::GamesAndRpgParadise.project_base_directory? end |
#project_image_directory? ⇒ Boolean
#
project_image_directory?
#
318 319 320 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 318 def project_image_directory? GamesAndRpgParadise.project_image_directory? end |
#project_yaml_directory? ⇒ Boolean Also known as: project_yaml_dir?, yaml_directory?, yaml_dir?
#
project_yaml_directory?
#
325 326 327 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 325 def project_yaml_directory? GamesAndRpgParadise.project_yaml_directory? end |
#rds(i) ⇒ Object
#
rds
#
252 253 254 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 252 def rds(i) i.squeeze '/' end |
#register_sigint ⇒ Object
#
register_sigint
#
118 119 120 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 118 def register_sigint Signal.trap('SIGINT') { exit } end |
#remove_this_directory(i, be_verbose = false) ⇒ Object Also known as: remove_directory
#
remove_this_directory
#
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 334 def remove_this_directory( i, be_verbose = false ) case be_verbose # ======================================================================= # # === :be_verbose # ======================================================================= # when :be_verbose be_verbose = true # ======================================================================= # # === :be_quiet # ======================================================================= # when :be_quiet be_verbose = false end i = i.dup i.squeeze!('/') if i and File.directory?(i) e rev+'Removing `'+sdir(i)+rev+'` next:' if be_verbose FileUtils.rm_rf(i) unless i == '/' end end |
#rename_file(old, new) ⇒ Object
#
rename_file
#
162 163 164 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 162 def rename_file(old, new) FileUtils.mv(old, new) end |
#reset ⇒ Object
#
reset (reset tag)
#
46 47 48 49 50 51 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 46 def reset # ======================================================================= # # === @use_colours # ======================================================================= # @use_colours = true end |
#reset_the_internal_hash ⇒ Object
#
reset_the_internal_hash
The method name is a misnomer though.
#
152 153 154 155 156 157 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 152 def reset_the_internal_hash # ======================================================================= # # === @internal_hash # ======================================================================= # @internal_hash = {} end |
#return_pwd ⇒ Object
#
return_pwd
#
302 303 304 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 302 def return_pwd "#{Dir.pwd}/".squeeze('/') end |
#return_today ⇒ Object
#
return_today
#
78 79 80 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 78 def return_today ::Time.now.strftime('%d.%m.%Y') end |
#touch_file(i) ⇒ Object Also known as: touch
#
touch_file (touch tag)
#
203 204 205 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 203 def touch_file(i) FileUtils.touch(i) end |
#wrap(i, use_this_as_word_wrap_delimiter = :default) ⇒ Object Also known as: word_wrap
#
wrap (wrap tag)
This is word_wrap - we break up the string into substrings separated via newlines.
#
243 244 245 246 247 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 243 def wrap( i, use_this_as_word_wrap_delimiter = :default ) return GamesAndRpgParadise.word_wrap(i, use_this_as_word_wrap_delimiter) end |
#write_what_into(what, into) ⇒ Object
#
write_what_into
#
71 72 73 |
# File 'lib/games_and_rpg_paradise/base/extensions/common_extensions.rb', line 71 def write_what_into(what, into) SaveFile.write_what_into(what, into) end |