class RBT::Cookbooks::ShowLastUpdated
Constants
- DISPLAY_N_PROGRAMS
#¶ ↑
DISPLAY_N_PROGRAMS
¶ ↑How many programs to use by default. We can also use the maximum amount of programs instead.
#¶ ↑
- HEADER
#¶ ↑
HEADER
¶ ↑#¶ ↑
Public Class Methods
dataset?()
click to toggle source
#¶ ↑
RBT::Cookbooks::ShowLastUpdated.dataset?
¶ ↑
This method will return an Array that is already sorted. Most recent entries, aka the first ones in that Array, will be the programs that were updated last.
Usage example:
x = Cookbooks::ShowLastUpdated.dataset?; pp x; ''
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 398 def self.dataset? new { :do_not_output_the_result }.dataset? end
new( commandline_arguments = nil, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 46 def initialize( commandline_arguments = nil, run_already = true ) reset set_commandline_arguments( commandline_arguments ) # ======================================================================= # # === Handle blocks next # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :do_not_output_the_result # ===================================================================== # when :do_not_output_the_result do_not_output_the_result end end if first?.is_a? Hash # ===================================================================== # # === :display_n_programs # ===================================================================== # if first?.has_key? :display_n_programs set_display_n_programs(first?.fetch(:display_n_programs)) end end run if run_already end
Public Instance Methods
array_dataset?()
click to toggle source
do_not_show_the_result()
click to toggle source
#¶ ↑
do_not_show_the_result
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 110 def do_not_show_the_result @show_result = false end
Also aliased as: do_not_output_the_result
filter_the_array_dataset()
click to toggle source
#¶ ↑
filter_the_array_dataset
¶ ↑
Here we will apply the maximum threshold stored in @display_n_programs.
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 311 def filter_the_array_dataset unless @display_n_programs.is_a? Symbol # If it is :everything then we will show every program. @array_dataset = @array_dataset[0, @display_n_programs] end end
inform_the_user_what_we_will_do()
click to toggle source
n_programs?()
click to toggle source
#¶ ↑
n_programs?¶ ↑
Tell us how many programs are there.
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 272 def n_programs? @display_n_programs end
Also aliased as: show_n_programs?
obtain_last_updated_programs()
click to toggle source
#¶ ↑
obtain_last_updated_programs
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 138 def obtain_last_updated_programs if use_grep? cmd = "grep -r last_update #{individual_cookbooks_dir?}*" if show_result? opne 'The command "'+cadetblue('grep')+'" will be used, with '\ 'the following syntax:' e e " #{gold(cmd)}" # Display that particular grep command as well. e end end inform_the_user_what_we_will_do if show_result? # ======================================================================= # # This is the header. # ======================================================================= # output_header # <- This method calls a trailing cliner already. case @obtain_results_via # ======================================================================= # # === :grep # ======================================================================= # when :grep # ===================================================================== # # We still have to populate the @array_dataset variable. # So first, make use of grep: # ===================================================================== # result = `#{cmd}` array = result.split(N) use_this_regex = /last_update: (.+)/ array.each_with_index {|line, index| index += 1 line.chomp! splitted_at_colon = line.split(':') # Split at ':' colon tokens. program = File.basename(splitted_at_colon.first).sub(/\.yml$/,'') last_update = line.scan(use_this_regex).flatten.first @array_dataset << [program, last_update, index] } # ======================================================================= # # === :ruby # ======================================================================= # when :ruby programs = available_programs? programs.each_with_index { |program, index| index += 1 # =================================================================== # # @dataset.assign(program) # This is an instance of Cookbooks::Cookbook. # Note that the next line can be fairly slow. As an alternative # solution, we can also use grep. # =================================================================== # @dataset = RBT::Cookbooks::SanitizeCookbook.new(program) { :fast } begin last_update = @dataset.last_update? if last_update.empty? opne swarn('No last update was found for the program:') opne sfancy(program) else # Else append the dataset. @array_dataset << [program, last_update, index] end rescue Exception => error pp error opne "The program that failed was: `#{sfancy(program.to_s)}`" end } end cliner sort_the_array_dataset filter_the_array_dataset end
output_header()
click to toggle source
report_results( i = @array_dataset )
click to toggle source
#¶ ↑
report_results
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 288 def report_results( i = @array_dataset ) if @show_result i.each { |name, date, index| name = '%-25s' % name date = date.center(20) date = mediumspringgreen(date) if use_colours? index = index.to_s.rjust(4) if use_colours? index = seagreen(index) end e "| #{steelblue(name)} | #{date.to_s} | #{index}" } cliner end end
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/cookbooks/show_last_updated.rb, line 81 def reset super() infer_the_namespace set_display_n_programs # Set a default. # ======================================================================= # # === @dataset # ======================================================================= # @dataset = nil # ======================================================================= # # === @array_dataset # ======================================================================= # @array_dataset = [] # <- Will be an Array of: [program, last_update, index] # ======================================================================= # # === @obtain_results_via # ======================================================================= # @obtain_results_via = :grep # Can be :grep or :ruby. # ======================================================================= # # === @show_result # ======================================================================= # @show_result = true # ======================================================================= # # === @sort_by # ======================================================================= # @sort_by = :alphabet end
run()
click to toggle source
set_display_n_programs( i = RBT.n_registered_programs? )
click to toggle source
#¶ ↑
set_display_n_programs
¶ ↑
This method will also accept a regex optionally.
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 240 def set_display_n_programs( i = RBT.n_registered_programs? ) case i # ======================================================================= # # === :all_of_them # ======================================================================= # when :all_of_them, :default i = RBT.n_registered_programs? end if i.is_a? String if i.include? 'n_programs' i =~ /n_programs (\d+)/ i = $1.to_s.dup elsif i.include? 'nprograms' i =~ /nprograms (\d+)/ i = $1.to_s.dup elsif i.start_with?('--n ') or i.start_with?('-n') i =~ /n ?(\d+)/ i = $1.to_s.dup end end i = i.to_i # Must be an Integer. @display_n_programs = i end
show_help()
click to toggle source
#¶ ↑
show_help
(help tag)¶ ↑
Invocation example:
slu --n_programs 3000
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 325 def show_help e 'To display '+simp('n programs')+', where '+simp('n')+' may '\ 'be 500, do this:' e e ' slu --n_programs 500' e ' slu --nprograms 500' e ' slu --n 500' e end
show_result?()
click to toggle source
sort_the_array_dataset()
click to toggle source
#¶ ↑
sort_the_array_dataset
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/show_last_updated.rb, line 208 def sort_the_array_dataset @array_dataset = @array_dataset.sort_by {|i| begin this_date = i[1] Time.parse(this_date) rescue Exception => error pp error pp i end }.reverse # .reverse so we can keep it in a nicer layout. if @sort_by == :reversed @array_dataset.reverse! end end