Class: Roebe::ModifyShebangHeader
- Inherits:
-
Base
show all
- Defined in:
- lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb
Overview
Constant Summary
collapse
- DEFAULT_SHEBANG_TO_USE_ON_WINDOWS =
#
DEFAULT_SHEBANG_TO_USE_ON_WINDOWS
#
'#!/ruby/bin/ruby -w'
- DEFAULT_SHEBANG_TO_USE_ON_LINUX =
#
DEFAULT_SHEBANG_TO_USE_ON_LINUX
The following constant does not require of us to specify a leading ‘#!’ variant.
On windows you may want to use another shebang line, such as “#!/ruby/bin/ruby -w”.
#
DEFAULT_SHEBANG_TO_USE_ON_LINUX = ‘/System/Index/bin/ruby -w’ # The old shebang that was in use.
'#!/usr/bin/ruby -w'
- MAY_WE_OVERWRITE_EXISTING_FILES =
#
MAY_WE_OVERWRITE_EXISTING_FILES
If the following constant is true then we may overwrite existing files. This is the default behaviour.
#
true
- THIS_IS_THE_PRIMARY_ENCODING =
#
THIS_IS_THE_PRIMARY_ENCODING
The following constant will specify which encoding we have to use.
#
'# Encoding: UTF-8'
- DEFAULT_FILE_TO_USE =
'foobar.rb'
- WILL_WE_TRY_TO_CHECK_FOR_THE_CORRECT_ENCODING =
#
WILL_WE_TRY_TO_CHECK_FOR_THE_CORRECT_ENCODING
#
true
Constants inherited
from Base
Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE
Class Method Summary
collapse
Instance Method Summary
collapse
-
#append_work_on_these_files(i) ⇒ Object
# === append_work_on_these_files ========================================================================= #.
-
#do_work_on_the_files(i = work_on_these_files?, , be_verbose = be_verbose? ) ⇒ Object
(also: #do_modify_the_files)
# === do_work_on_the_files.
-
#ensure_proper_encoding? ⇒ Boolean
# === ensure_proper_encoding? ========================================================================= #.
-
#initialize(commandline_arguments = nil, run_already = true) ⇒ ModifyShebangHeader
constructor
# === initialize ========================================================================= #.
-
#is_on_windows ⇒ Object
# === is_on_windows ========================================================================= #.
-
#menu(i = commandline_arguments? ) ⇒ Object
-
#new_shebang_to_use? ⇒ Boolean
(also: #use_which_shebang?, #return_new_shebang, #we_want_to_have_this_new_shebang_lines)
# === new_shebang_to_use? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_new_shebang_to_use(i) ⇒ Object
# === set_new_shebang_to_use ========================================================================= #.
-
#set_store_into_this_file(i = DEFAULT_FILE_TO_USE) ⇒ Object
(also: #set_file_name, #set_filename)
# === set_store_into_this_file.
-
#set_work_on_these_files(i) ⇒ Object
(also: #set_modify_these_files, #set_fix_this_file)
# === set_work_on_these_files ========================================================================= #.
-
#set_work_on_this_file_type_only(i = '.rb') ⇒ Object
(also: #set_filetype, #set_use_this_filetype, #use_this_filetype=)
# === set_work_on_this_file_type_only.
-
#show_help ⇒ Object
# === show_help (help tag) ========================================================================= #.
-
#store_into_this_file? ⇒ Boolean
(also: #store_into_which_file?)
# === store_into_this_file? ========================================================================= #.
-
#store_this_file_content_into_that_file(what, into = store_into_which_file? ) ⇒ Object
(also: #store_dataset, #save_result)
# === store_this_file_content_into_that_file ========================================================================= #.
-
#work_on_these_files? ⇒ Boolean
# === work_on_these_files? ========================================================================= #.
-
#work_on_this_file_type_only? ⇒ Boolean
(also: #use_this_filetype?)
# === work_on_this_file_type_only? ========================================================================= #.
Methods inherited from Base
#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow
#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ ModifyShebangHeader
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 76
def initialize(
commandline_arguments = nil,
run_already = true
)
reset
set_commandline_arguments(
commandline_arguments
)
case commandline_arguments
when :do_not_run_yet,
:dont_run_yet
run_already = false
end
case run_already
when :do_not_run_yet
run_already = false
end
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
427
428
429
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 427
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#append_work_on_these_files(i) ⇒ Object
#
append_work_on_these_files
#
205
206
207
208
209
210
211
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 205
def append_work_on_these_files(i)
unless @internal_hash[:work_on_these_files].include?(i)
@internal_hash[:work_on_these_files] << i
@internal_hash[:work_on_these_files].flatten!
@internal_hash[:work_on_these_files].compact!
end
end
|
#do_work_on_the_files(i = work_on_these_files?,
, be_verbose = be_verbose?
) ⇒ Object
Also known as:
do_modify_the_files
#
do_work_on_the_files
This is the method-action of this class, the main powerhorse. This method will try to modify the files passed to it.
#
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 321
def do_work_on_the_files(
i = work_on_these_files?,
be_verbose = be_verbose?
)
i.each {|this_file|
if File.empty? this_file
opne "The file at #{sfile(this_file)} is empty. "\
"Skipping empty files."
next
end
set_store_into_this_file(this_file) if File.exist? this_file
if be_verbose
opne "Now working on the file `#{sfile(this_file)}`."
end
old_content = File.readlines(this_file)
if ensure_proper_encoding?
encoding_line = old_content[1] if encoding_line.start_with?('# ') and
encoding_line.include?('# Encoding: ')
unless encoding_line.include? THIS_IS_THE_PRIMARY_ENCODING
old_content[1] = THIS_IS_THE_PRIMARY_ENCODING
unless old_content[1].end_with? N
old_content[1] = old_content[1].dup if old_content[1].frozen?
old_content[1] << N
end
end
end
end
old_content[0] = "#{use_which_shebang?}\n"
into = rds(this_file)
opne "Storing into the file #{sfile(into)} next."
store_this_file_content_into_that_file(
old_content.join,
into
)
end
}
end
|
#ensure_proper_encoding? ⇒ Boolean
#
ensure_proper_encoding?
#
141
142
143
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 141
def ensure_proper_encoding?
@internal_hash[:will_we_try_to_check_for_the_correct_encoding]
end
|
#is_on_windows ⇒ Object
148
149
150
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 148
def is_on_windows
set_new_shebang_to_use(:windows)
end
|
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 235
def (
i = commandline_arguments?
)
if i.is_a? Array
i.each {|entry| (entry) }
else
if i.start_with?('--')
case i
when /^-?-?help$/
show_help
exit
when /^-?-?on(-|_)?windows$/,
/^-?-?is(-|_)?on(-|_)?windows$/
is_on_windows
when /^-?-?file(-|_)?type=(.+)$/ set_filetype(
$2.to_s.dup
)
end
elsif i and File.file?(i)
append_work_on_these_files(i)
elsif i and File.directory?(i)
_ = @internal_hash[:work_on_this_file_type_only]
append_work_on_these_files(
Dir["#{i}/**/**"].select {|entry|
entry.end_with?(_)
}
)
else
unless i.empty?
opne "Unsure what to do with #{i}."
end
end
end
end
|
#new_shebang_to_use? ⇒ Boolean
Also known as:
use_which_shebang?, return_new_shebang, we_want_to_have_this_new_shebang_lines
187
188
189
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 187
def new_shebang_to_use?
@internal_hash[:new_shebang_to_use]
end
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 105
def reset
super()
infer_the_namespace
@internal_hash = {}
@internal_hash[:work_on_these_files] = []
set_new_shebang_to_use(:infer_automatically)
@internal_hash[:work_on_this_file_type_only] = '.rb'
@internal_hash[:will_we_try_to_check_for_the_correct_encoding] =
WILL_WE_TRY_TO_CHECK_FOR_THE_CORRECT_ENCODING
set_be_verbose
end
|
419
420
421
422
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 419
def run
do_work_on_the_files
end
|
#set_new_shebang_to_use(i) ⇒ Object
#
set_new_shebang_to_use
#
#set_store_into_this_file(i = DEFAULT_FILE_TO_USE) ⇒ Object
Also known as:
set_file_name, set_filename
#
set_store_into_this_file
This method will keep track of which file we may overwrite.
#
379
380
381
382
383
384
385
386
387
388
389
390
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 379
def set_store_into_this_file(
i = DEFAULT_FILE_TO_USE
)
i = DEFAULT_FILE_TO_USE if i.nil?
i = i.dup if i.frozen?
i.chop! if i.end_with? '#'
i.chop! if i.end_with? ':'
@internal_hash[:store_into_this_file] = i
end
|
#set_work_on_these_files(i) ⇒ Object
Also known as:
set_modify_these_files, set_fix_this_file
#
set_work_on_these_files
#
196
197
198
199
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 196
def set_work_on_these_files(i)
i = [i].flatten.compact
@internal_hash[:work_on_these_files] = i
end
|
#set_work_on_this_file_type_only(i = '.rb') ⇒ Object
Also known as:
set_filetype, set_use_this_filetype, use_this_filetype=
#
set_work_on_this_file_type_only
Note that we will keep the ‘.’, thus the filetype may be ‘.rb’.
#
303
304
305
306
307
308
309
310
311
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 303
def set_work_on_this_file_type_only(
i = '.rb'
)
i = i.dup if i.frozen?
unless i.start_with?('.')
i.prepend('.')
end
@internal_hash[:work_on_this_file_type_only] = i
end
|
#show_help ⇒ Object
223
224
225
226
227
228
229
230
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 223
def show_help
e
e 'These are the documented (and thus available) options:'
e
e ' --file-type=php # specify another file type suffix'
e ' --on_windows # designate that we are on windows'
e
end
|
#store_into_this_file? ⇒ Boolean
Also known as:
store_into_which_file?
#
store_into_this_file?
#
396
397
398
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 396
def store_into_this_file?
@internal_hash[:store_into_this_file]
end
|
#store_this_file_content_into_that_file(what, into = store_into_which_file?
) ⇒ Object
Also known as:
store_dataset, save_result
#
store_this_file_content_into_that_file
#
403
404
405
406
407
408
409
410
411
412
413
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 403
def store_this_file_content_into_that_file(
what,
into = store_into_which_file?
)
if MAY_WE_OVERWRITE_EXISTING_FILES
if be_verbose?
opnn; e "Storing into the file `#{sfile(into)}`."
end
write_what_into(what, into)
end
end
|
#work_on_these_files? ⇒ Boolean
216
217
218
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 216
def work_on_these_files?
@internal_hash[:work_on_these_files]
end
|
#work_on_this_file_type_only? ⇒ Boolean
Also known as:
use_this_filetype?
#
work_on_this_file_type_only?
#
294
295
296
|
# File 'lib/roebe/classes/modify_shebang_header/modify_shebang_header.rb', line 294
def work_on_this_file_type_only?
@internal_hash[:work_on_this_file_type_only]
end
|