class RBT::Cookbooks::CreateCookbookYamlFile
Constants
- OPEN_IN_EDITOR_AFTER_CREATION
#¶ ↑
OPEN_IN_EDITOR_AFTER_CREATION
¶ ↑#¶ ↑
- USE_THIS_EDITOR
#¶ ↑
USE_THIS_EDITOR
¶ ↑#¶ ↑
- YAML_EXTENSION
#¶ ↑
YAML_EXTENSION
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
new( commandline_arguments = nil, run_already = true ) { || ... }
click to toggle source
#¶ ↑
initialize¶ ↑
The first argument to this class can be the full URL to the target program at hand.
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 64 def initialize( commandline_arguments = nil, run_already = true ) reset set_commandline_arguments( commandline_arguments ) # ======================================================================= # # === Handle blocks given to the class # ======================================================================= # if block_given? yielded = yield case yielded # ===================================================================== # # === :interactive_mode # ===================================================================== # when :interactive_mode append_to_the_commandline_arguments('--interactive'.dup) end end run if run_already end
Public Instance Methods
add_hint_for_dependencies()
click to toggle source
automatically_determine_the_program_name_based_on_the_url1_entry( i = @hash_information_about_the_program[:url1] )
click to toggle source
#¶ ↑
automatically_determine_the_program_name_based_on_the_url1_entry
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 226 def automatically_determine_the_program_name_based_on_the_url1_entry( i = @hash_information_about_the_program[:url1] ) program_information = ProgramInformation.new(File.basename(i)) @hash_information_about_the_program[:program_name] = program_information.program_name? end
consider_opening_in_editor( this_file = file? )
click to toggle source
#¶ ↑
consider_opening_in_editor
¶ ↑
We may use the newly created file in our main editor.
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 505 def consider_opening_in_editor( this_file = file? ) if this_file.nil? and !commandline_arguments?.empty? this_file = commandline_arguments?.first unless File.exist? this_file this_file = "#{this_file}.yml" end end if open_in_editor? _ = "#{@editor} #{this_file}" opne 'We will next open this file in our editor, as instructed due' opne 'to the ivar '+sfancy('@open_in_editor_after_creation') opne 'having been set to true.' system(_) end end
Also aliased as: edit_this_file
description?()
click to toggle source
do_not_open_in_editor()
click to toggle source
do_open_in_editor()
click to toggle source
enter_interactive_part( use_this_url = first_argument? )
click to toggle source
#¶ ↑
enter_interactive_part
¶ ↑
This method allows the user to specifically designate some parts of the recipe at hand, interactively.
Invocation example:
ccook --interactive
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 173 def enter_interactive_part( use_this_url = first_argument? ) @interactive_mode = true e 'A few questions may be asked next, about the values that should be' e 'added to the yaml file at hand.' e e 'Many of these can be skipped.' e if use_this_url else e slateblue('Remote URL?') set_url1($stdin.gets.chomp) end e e slateblue('Description of the program at hand? [Or just hit enter ') e slateblue('for no description at all]') set_description($stdin.gets.chomp) e e 'Done!' end
file?()
click to toggle source
homepage?()
click to toggle source
#¶ ↑
homepage?¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 465 def homepage? require 'uri' _ = ''.dup if @hash_information_about_the_program.has_key? :url1 use_this_url = @hash_information_about_the_program[:url1] if is_on_roebe? opne 'Using information from this url: ' e e " #{steelblue(use_this_url)}" e end uri = URI(use_this_url) if uri _ = "#{uri.scheme}://#{uri.host}" end end _ end
name_of_the_program?()
click to toggle source
#¶ ↑
name_of_the_program?¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 198 def name_of_the_program? File.basename( first_argument? ) end
Also aliased as: program_name?, name?
open_in_editor?()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
RBT::Base#reset
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 91 def reset super() infer_the_namespace # ======================================================================= # # === @editor # ======================================================================= # @editor = USE_THIS_EDITOR # ======================================================================= # # === @template_file_to_use # ======================================================================= # @template_file_to_use = RBT.file_base_template_for_cookbook_yaml_files # ======================================================================= # # === @dataset # ======================================================================= # @dataset = [] # ======================================================================= # # === @hash_information_about_the_program # ======================================================================= # @hash_information_about_the_program = {} # ======================================================================= # # === @open_in_editor_after_creation # ======================================================================= # @open_in_editor_after_creation = OPEN_IN_EDITOR_AFTER_CREATION if is_on_roebe? @open_in_editor_after_creation = true end # ======================================================================= # # === @file # ======================================================================= # @file = nil end
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 526 def run sanitize_first_argument menu # Should come before verbose_make_use_of_the_template_file_and_then_sanitize_the_dataset if @dataset.empty? opne 'Empty dataset - can not store anything.' else store_dataset_into_file consider_opening_in_editor end end
sanitize_dataset()
click to toggle source
#¶ ↑
sanitize_dataset
(sanitize tag)¶ ↑
This method will, in particular, replace some of the generic MACROS in the file with corresponding “sane” values.
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 250 def sanitize_dataset @dataset.map! {|line| case line # ===================================================================== # # === description: # ===================================================================== # when /description: / if @hash_information_about_the_program.has_key? :description line = ' description: |'+N+ ' '+description? end # ===================================================================== # # === NAME_OF_THE_PROGRAM # ===================================================================== # when /NAME_OF_THE_PROGRAM/ line = program_name?.dup if @hash_information_about_the_program.has_key? :url1 unless @hash_information_about_the_program.has_key? :program_name automatically_determine_the_program_name_based_on_the_url1_entry end line = @hash_information_about_the_program[:program_name].dup end line << ':' unless line.end_with? ':' # ===================================================================== # # === homepage: # ===================================================================== # when / homepage:/ line = ' homepage: '+homepage? # ===================================================================== # # === required_deps_on: # ===================================================================== # when / required_deps_on:/ line = " required_deps_on:#{add_hint_for_dependencies}" # ===================================================================== # # === last_update # ===================================================================== # when /last_update: DD MM YYYY/ line = " last_update: #{dd_mm_yyyy}" # ===================================================================== # # === url1 # ===================================================================== # when /url1:/ if @hash_information_about_the_program.has_key? :url1 line = ' url1: '+@hash_information_about_the_program[:url1] end end line } end
Also aliased as: update
sanitize_first_argument()
click to toggle source
#¶ ↑
sanitize_first_argument
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 487 def sanitize_first_argument _ = first_argument? if _.include? '-' and (_ =~ /\d+/) # ===================================================================== # # In this case assume a remote URL: # ===================================================================== # program_information = ProgramInformation.new(File.basename(_)) @hash_information_about_the_program[:program_name] = program_information.program_name? @hash_information_about_the_program[:program_version] = program_information.program_version? set_url1 _ end end
set_description( i = 'Default description of the program.' )
click to toggle source
set_file(i)
click to toggle source
set_filename(i)
click to toggle source
#¶ ↑
set_filename
¶ ↑
This method will store the filename, i.e. where to store the file.
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 432 def set_filename(i) i = i.to_s.dup i = return_program_information(i) if i i << YAML_EXTENSION unless i.end_with? '.yml' # ===================================================================== # # Since as of March 2014 we will also downcase the name. # ===================================================================== # i.downcase! end set_file(i) end
Also aliased as: set_real_name
set_program_name(i = '')
click to toggle source
#¶ ↑
set_program_name
¶ ↑
This sets the short name of the program in question.
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 210 def set_program_name(i = '') # ======================================================================= # # First, do some sanitization. # ======================================================================= # if i.include? '.' # Assume that a file extension was given. Chop it away thus. i = i.to_s.dup i.sub!(/#{File.extname(i)}/,'') end i.delete!('_') if i.include? '_' i.downcase! @hash_information_about_the_program[:program_name] = i # This variable can be inferred from the url. end
Also aliased as: set_short_name
set_url1( i = '' )
click to toggle source
#¶ ↑
set_url1
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 347 def set_url1( i = '' ) @hash_information_about_the_program[:url1] = i unless i.empty? i = return_program_information( remove_archive_stuff_at_the_end( File.basename(i) ) ) set_filename(i) set_short_name(i) end end
Also aliased as: set_url
short_program_name?()
click to toggle source
show_help()
click to toggle source
#¶ ↑
show_help
(help tag)¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 400 def show_help e e 'How to create a new cookbook:' # newcookbook --help e e 'Simply provide the name of the .yml file, such as:' e e ' newcookbook php.yml' e e 'Alternatively, provide a remote URL which we will use to '\ 'generate such a file.' e e ' --interactive # this will ask you several questions before' e ' # the new .yml file will be created' e end
store_dataset_into_file()
click to toggle source
#¶ ↑
store_dataset_into_file
(store tag)¶ ↑
This method will store the dataset describing out .yml file into a (local) .yml file finally.
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 306 def store_dataset_into_file what = @dataset.join(N) into = short_program_name?+'.yml' if File.exist? into if File.directory? into opne sdir(into)+swarn(' seems to be a directory. Will not overwrite it.') else opnwarn 'But there already is a file at '+sfile(into)+swarn('.') opnwarn 'Shall we really overwrite this file?'+ steelblue(' [y/n]') case $stdin.gets.chomp when 'y','yes','j','ja' opnwarn 'Overwriting `'+sfile(into)+swarn('` now.') write_what_into(what, into) else opnwarn 'Ok - not overwriting.' end end else opne 'Saving into the file `'+sfile(into)+'` next.' write_what_into(what, into) end end
verbose_make_use_of_the_template_file_and_then_sanitize_the_dataset()
click to toggle source
#¶ ↑
verbose_make_use_of_the_template_file_and_then_sanitize_the_dataset
¶ ↑
#¶ ↑
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 335 def verbose_make_use_of_the_template_file_and_then_sanitize_the_dataset _ = @template_file_to_use if File.exist? _ opne "Making use of a template file (#{sfile(File.basename(_))})." @dataset = File.readlines(_).map(&:chomp) sanitize_dataset end end