class Cookbooks::CreateNewCookbook
Constants
- ALL_NEWLY_CREATED_YAML_FILES_MUST_RESIDE_IN_INDIVIDUAL_COOKBOOKS_DIRECTORY
#¶ ↑
ALL_NEWLY_CREATED_YAML_FILES_MUST_RESIDE_IN_INDIVIDUAL_COOKBOOKS_DIRECTORY¶ ↑
If the following constant is true, then we will move newly created .yml files into the INDIVIDUAL_COOKBOOKS directory - unless they already reside there.
Note that in order for this to work, the constant INDIVIDUAL_COOKBOOKS must exist.
#¶ ↑
- CURRENT_DAY_AND_MONTH
#¶ ↑
CURRENT_DAY_AND_MONTH¶ ↑
#¶ ↑
- CURRENT_MONTH
#¶ ↑
CURRENT_MONTH¶ ↑
#¶ ↑
- DEFAULT_NAME_FOR_THE_YAML_FILE
#¶ ↑
DEFAULT_NAME_FOR_THE_YAML_FILE¶ ↑
#¶ ↑
- NAMESPACE
#¶ ↑
NAMESPACE¶ ↑
#¶ ↑
- OPEN_IN_EDITOR_AFTER_CREATION
#¶ ↑
OPEN_IN_EDITOR_AFTER_CREATION¶ ↑
#¶ ↑
- ROEBE_INDIVIDUAL_COOKBOOKS_DIRECTORY
#¶ ↑
ROEBE_INDIVIDUAL_COOKBOOKS_DIRECTORY¶ ↑
#¶ ↑
- USE_THIS_EDITOR
- YAML_EXTENSION
#¶ ↑
Various constants
#¶ ↑
Public Class Methods
new( input = nil, run_already = true )
click to toggle source
Public Instance Methods
add_hint_for_dependencies()
click to toggle source
consider_creating_a_new_cookbook_file()
click to toggle source
#¶ ↑
#consider_creating_a_new_cookbook_file¶ ↑
This method is the one that will create the new cookbook.
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 289 def consider_creating_a_new_cookbook_file if File.exist? @_ if File.directory? @_ opnn; ewarn sdir(@_)+' seems to be a directory. Will not overwrite it.' else opnn; ewarn 'But '+sfile(@_)+' already exists.' opnn; ewarn 'Shall we really overwrite this file?' case $stdin.gets.chomp when 'y','yes','j','ja' opnn; ewarn 'Overwriting `'+sfile(@_)+swarn('` now.') store else opnn; ewarn 'Ok, then not.' end end else store end 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/cookbooks/utility_scripts/create_new_cookbook.rb, line 378 def consider_opening_in_editor(this_file = file?) if open_in_editor? _ = @editor+' '+this_file opnn; e 'We will next open this file in our editor, as instructed due' opnn; e 'to the ivar '+sfancy('@open_in_editor_after_creation') opnn; e 'having been set to true.' system(_) end end
Also aliased as: edit_this_file
create_main_string()
click to toggle source
#¶ ↑
#create_main_string¶ ↑
This holds our recipe-skeleton.
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 424 def create_main_string @_ = @short_name+': # binaries: configure_options: " " description: | "'+@description.to_s+'"'+@base_dir.to_s+' extra_information: | "Extra information for this program to use." url1: '+@url1+' url2: '+File.dirname(@url1.to_s)+'/'+' prefix: '+@compile_mode+' keep_extracted: f tags: # gnome xorg required_deps_on: '+add_hint_for_dependencies+' # libraries: last_update: '+CURRENT_DAY_AND_MONTH end
do_not_open_in_editor()
click to toggle source
do_open_in_editor()
click to toggle source
enter_interactive_part()
click to toggle source
#¶ ↑
#enter_interactive_part¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 408 def enter_interactive_part @interactive_mode = true e 'We will next ask which values should be added to the yaml file.' e 'Remote URL?' @url1 = $stdin.gets.chomp e 'Description of the propram?' @description = $stdin.gets.chomp e 'Done!' create_main_string end
file?()
click to toggle source
open_in_editor?()
click to toggle source
opnn()
click to toggle source
report_to_user()
click to toggle source
#¶ ↑
#report_to_user¶ ↑
Report to the user that we have finished creating the new file.
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 314 def report_to_user opnn; e 'Finished creating the file `'+sfile(file?)+'`.' # ======================================================================= # # === Move it into the cookbooks directory if the constant was set # ======================================================================= # if ALL_NEWLY_CREATED_YAML_FILES_MUST_RESIDE_IN_INDIVIDUAL_COOKBOOKS_DIRECTORY unless Dir.pwd == INDIVIDUAL_COOKBOOKS # =================================================================== # # First, we will copy that file to my home directory # if we are on roebe. # =================================================================== # if is_on_roebe? target = ROEBE_INDIVIDUAL_COOKBOOKS_DIRECTORY+File.basename(file?) opnn e 'Copying the '+sfile(file?)+' into the directory '+ sdir(ROEBE_INDIVIDUAL_COOKBOOKS_DIRECTORY) opnn e 'It is now available here:' opnn e sfile(' '+target) copy_file(file?, target) do_open_in_editor edit_this_file target do_not_open_in_editor # We only care about the main directory at home. end target_file = INDIVIDUAL_COOKBOOKS+File.basename(file?) if File.exist? target_file opnn; e 'Can not move the file to '+sfile(target_file)+' as there' opnn; e 'already is a file at that location.' else opnn; e 'Moving '+sfile(file?)+' into the directory '+sdir(INDIVIDUAL_COOKBOOKS) opnn; e 'as we have set the constant '+ simp( 'ALL_NEWLY_CREATED_YAML_FILES_MUST_RESIDE_IN_INDIVIDUAL_COOKBOOKS_DIRECTORY' ) target = INDIVIDUAL_COOKBOOKS+File.basename(file?) move_file(file?, target) set_file(target) end end end end
reset()
click to toggle source
#¶ ↑
reset¶ ↑
#¶ ↑
Calls superclass method
Cookbooks::Base#reset
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 107 def reset super() set_compile_mode @interactive_mode = true @_ = '' @base_dir = '' @editor = USE_THIS_EDITOR @open_in_editor_after_creation = OPEN_IN_EDITOR_AFTER_CREATION @short_name = '' set_description set_file DEFAULT_NAME_FOR_THE_YAML_FILE # Default name. set_url1 end
return_program_information(i, be_verbose = false)
click to toggle source
run()
click to toggle source
run_everything()
click to toggle source
set_base_dir(i)
click to toggle source
set_commandline_input( i = nil )
click to toggle source
#¶ ↑
#set_commandline_input¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 179 def set_commandline_input( i = nil ) menu(i) @commandline_input = i if i if @commandline_input.is_a? Array set_url1(@commandline_input.first) elsif @commandline_input.is_a? String set_url1(@commandline_input) end end end
set_compile_mode(i = :traditional)
click to toggle source
#¶ ↑
#set_compile_mode¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 450 def set_compile_mode(i = :traditional) case i.to_s when 't' i = 'prefix = t' when 'f' i = 'prefix = f' end i = i.to_s unless i.is_a? String if i.is_a?(String) and i.frozen? i = i.dup end i << N unless i.end_with? N @compile_mode = i 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 will give us the filename, i.e. where to store the file.
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 252 def set_filename(i) i = i.to_s.dup i = return_program_information(i, false) 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_short_name(i = '')
click to toggle source
#¶ ↑
#set_short_name¶ ↑
This sets the short name of the program in question.
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 227 def set_short_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.gsub!(/#{File.extname(i)}/,'') end i = return_program_information(i) i = i.delete('_') if i.include? '_' i = i.downcase @short_name = i # This variable can be inferred from the url. create_main_string end
set_url1( i = '' )
click to toggle source
#¶ ↑
#set_url1¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 205 def set_url1( i = '' ) @url1 = i unless i.empty? set_filename(@url1) set_short_name(@url1) end end
Also aliased as: set_url
show_help()
click to toggle source
#¶ ↑
#show_help (help tag)¶ ↑
#¶ ↑
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 391 def show_help 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' end