class RBT::QueryFileAssociation
Public Class Methods
[](i = ARGV)
click to toggle source
new( commandline_arguments = nil, run_already = true )
click to toggle source
Public Instance Methods
input_as_string?()
click to toggle source
is_it_a_binary?(i = input_as_string?)
click to toggle source
is_it_a_gir_file?(i = input_as_string?)
click to toggle source
is_it_a_header?(i = input_as_string?)
click to toggle source
#¶ ↑
is_it_a_header?¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 185 def is_it_a_header?(i = input_as_string?) i = i.first if i.is_a? Array @dataset_headers and @dataset_headers.has_key?(i) end
Also aliased as: is_it_a_header_file?
is_it_a_library?(i = input_as_string?)
click to toggle source
is_it_a_m4_file?(i = input_as_string?)
click to toggle source
is_it_a_pkgconfig_file?(i = input_as_string?)
click to toggle source
is_the_input_included?()
click to toggle source
#¶ ↑
is_the_input_included?¶ ↑
This method does the actual query-part, that is, it attempts to determine whether the input is registered.
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 263 def is_the_input_included? input = input_as_string? if @hash.has_key? input opne 'The file '+sfancy(input)+' is included.' pointer = @hash[input] opne 'It belongs to the program called '+steelblue(pointer)+'. ' # ======================================================================= # # === Library file # ======================================================================= # if is_it_a_library? report_that_this_is_a_library_file # ======================================================================= # # === Binary file # ======================================================================= # elsif is_it_a_binary? report_that_this_is_a_binary_file # ======================================================================= # # === Header file # ======================================================================= # elsif is_it_a_header? report_that_this_is_a_header_file # ======================================================================= # # === .gir file # ======================================================================= # elsif is_it_a_gir_file? report_that_this_is_a_gir_file # ======================================================================= # # === pkg-config file # ======================================================================= # elsif is_it_a_pkgconfig_file? report_that_this_is_a_pkgconfig_file # ======================================================================= # # === m4 file # ======================================================================= # elsif is_it_a_m4_file? report_that_this_is_a_m4_file else opne 'The file-type association for this program is unknown.' end the_input_is_included return pointer # We will return it here as well. end end
merge_this_dataset_onto_the_main_hash(i)
click to toggle source
merge_together_the_available_files()
click to toggle source
#¶ ↑
merge_together_the_available_files
¶ ↑
This method can be used to merge in the available dataset.
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 367 def merge_together_the_available_files # ======================================================================= # # === Merge in the libraries # ======================================================================= # _ = RBT.file_registered_libraries # Add the registered libraries here. if File.exist? _ @dataset_libraries = sanitize_the_keys_of_this_hash(load_yaml(_)) merge_this_dataset_onto_the_main_hash(@dataset_libraries) end # ======================================================================= # # === Merge in the headers # ======================================================================= # _ = RBT.file_registered_headers # Add the registered headers here. if File.exist? _ @dataset_headers = load_yaml(_) merge_this_dataset_onto_the_main_hash(@dataset_headers) end # ======================================================================= # # === Merge in the binaries # ======================================================================= # _ = RBT.file_registered_binaries # Add the registered binaries here. if File.exist? _ @dataset_binaries = sanitize_the_keys_of_this_hash(load_yaml(_)) merge_this_dataset_onto_the_main_hash(@dataset_binaries) end # ======================================================================= # # === Merge in the pkgconfig .pc files # ======================================================================= # _ = RBT.file_registered_pkgconfig_files # Add the registered pkgconfig files here. if File.exist? _ @dataset_pkgconfig_files = sanitize_the_keys_of_this_hash(load_yaml(_)) merge_this_dataset_onto_the_main_hash(@dataset_pkgconfig_files) end # ======================================================================= # # === Merge in the .m4 files # ======================================================================= # _ = RBT.file_registered_m4_files if File.exist? _ @dataset_m4_files = sanitize_the_keys_of_this_hash(load_yaml(_)) merge_this_dataset_onto_the_main_hash(@dataset_m4_files) end # ======================================================================= # # === Merge in the .gir files # ======================================================================= # _ = RBT.file_registered_gir_files # Add the registered gir files come here. if File.exist? _ @dataset_gir_files = sanitize_the_keys_of_this_hash(load_yaml(_)) merge_this_dataset_onto_the_main_hash(@dataset_gir_files) end end
report()
click to toggle source
#¶ ↑
report (report tag)¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 444 def report flat_include = is_the_input_included? if flat_include the_input_is_included else try_a_deep_included_query end unless @is_included # ===================================================================== # # Notify the user that the input was not found - it is not included. # ===================================================================== # result = "The file #{sfancy(input_as_string?)} is #{orangered('NOT')} included." if Object.const_defined?(:Roebe) and Roebe.respond_to?(:sad_smiley) result = result.dup if result.frozen? result << steelblue(" #{Roebe.sad_smiley}") end opne result end end
report_that_this_is_a_binary_file()
click to toggle source
report_that_this_is_a_gir_file()
click to toggle source
report_that_this_is_a_header_file( use_opnn = true )
click to toggle source
#¶ ↑
report_that_this_is_a_header_file
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 428 def report_that_this_is_a_header_file( use_opnn = true ) case use_opnn # ======================================================================= # # === :no_opnn # ======================================================================= # when :no_opnn use_opnn = false end opnn if use_opnn; e "It is #{olivedrab('a header file')}." end
report_that_this_is_a_library_file()
click to toggle source
report_that_this_is_a_m4_file()
click to toggle source
report_that_this_is_a_pkgconfig_file()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::LeanPrototype#reset
# File lib/rbt/utility_scripts/query_file_association.rb, line 51 def reset super() infer_the_namespace # ======================================================================= # # === @is_included # # This variable keeps track as to whether the input is included or # whether it is not. # ======================================================================= # @is_included = false # ======================================================================= # # === @dataset_libraries # ======================================================================= # @dataset_libraries = nil # ======================================================================= # # === @dataset_headers # ======================================================================= # @dataset_headers = nil # ======================================================================= # # === @dataset_binaries # ======================================================================= # @dataset_binaries = nil # ======================================================================= # # === @dataset_pkgconfig_files # ======================================================================= # @dataset_pkgconfig_files = nil # ======================================================================= # # === @dataset_m4_files # ======================================================================= # @dataset_m4_files = nil # ======================================================================= # # === @dataset_gir_files # ======================================================================= # @dataset_gir_files = nil # ======================================================================= # # === @hash # # This is the main hash. It will contain all files, and point them # to the corresponding program at hand. # # We must of course properly "initialize" it with the correct data. # ======================================================================= # @hash = {} end
run()
click to toggle source
sanitize_the_commandline_arguments()
click to toggle source
#¶ ↑
sanitize_the_commandline_arguments
¶ ↑
This method will, at the least presently, only change entries that contain a ‘/’ character. The method assumes that such an input would be invalid.
Since as of January, trailing ‘:’ will be removed too, as will trailing ‘.’.
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 116 def sanitize_the_commandline_arguments commandline_arguments?.map! {|entry| if entry.include? '/' entry = File.basename(entry) end if entry.end_with? ':' entry = entry.dup if entry.frozen? entry.chop! end if entry.end_with? '.' entry.sub!(/\.+$/,'') end entry } end
sanitize_the_keys_of_this_hash(i)
click to toggle source
#¶ ↑
sanitize_the_keys_of_this_hash
¶ ↑
This method essentially turns the keys of a Hash into the short variant, without any ‘/’ as their part. This should not be done for several of the Hashes, though - in particular not for the header files.
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 158 def sanitize_the_keys_of_this_hash(i) # ======================================================================= # # We are only interested in short keys, so let's do that: # ======================================================================= # dataset = i.transform_keys {|key| unless key.is_a? String e swarn('An error occurred: the key is not a string.') e swarn('This ought to be fixed.') pp key exit end File.basename(key) } dataset end
set_commandline_arguments(i = '')
click to toggle source
simplify_these_arguments(i)
click to toggle source
#¶ ↑
simplify_these_arguments
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 135 def simplify_these_arguments(i) i.map {|entry| if entry.is_a? Hash if entry.has_key? :of entry = entry.delete(:of) elsif entry.has_key? :of_this_file entry = entry.delete(:of_this_file) else opne "Unknown key given: #{steelblue(i)}" end end entry } end
the_input_is_included()
click to toggle source
#¶ ↑
the_input_is_included
¶ ↑
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 317 def the_input_is_included @is_included = true end
Also aliased as: input_is_included
the_input_is_not_included()
click to toggle source
try_a_deep_included_query()
click to toggle source
#¶ ↑
try_a_deep_included_query
(deep tag)¶ ↑
This method is used specifically to try a deep include.
#¶ ↑
# File lib/rbt/utility_scripts/query_file_association.rb, line 326 def try_a_deep_included_query input = input_as_string? selection = @hash.select {|key, value| key.end_with? "/#{input}" } if selection.empty? # ===================================================================== # # Do nothing. # ===================================================================== # else input_is_included e "#{rev}The following associations were found:" e selection.each_pair {|key, name_of_the_program| print ' '+steelblue(key.ljust(16))+' → belongs to '\ 'the program called `'+royalblue(name_of_the_program)+'`. '+ ''.ljust(6 - name_of_the_program.size) if key.end_with? '.h' report_that_this_is_a_header_file(:no_opnn) else e end } e end end