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
#

initialize

The first argument should be the full URL to the target program in question.

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 95
def initialize(
    input       = nil,
    run_already = true
  )
  reset
  set_commandline_input(input)
  run if run_already
end

Public Instance Methods

add_hint_for_dependencies() click to toggle source
#

#add_hint_for_dependencies

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 148
def add_hint_for_dependencies
  if is_on_roebe?
    ''
  else # Add this to help newbies.
    '# The dependencies go in here.'+N
  end
end
assign_to_main_string()
Alias for: create_main_string
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_not_open_in_editor

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 124
def do_not_open_in_editor
  @open_in_editor_after_creation = false
end
do_open_in_editor() click to toggle source
#

#do_open_in_editor

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 131
def do_open_in_editor
  @open_in_editor_after_creation = false
end
edit_this_file(this_file = file?)
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
#

file?

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 218
def file?
  @file
end
menu(i = nil) click to toggle source
#

menu

#
open_in_editor?() click to toggle source
#

open_in_editor?

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 243
def open_in_editor?
  @open_in_editor_after_creation
end
opnn() click to toggle source
#

opnn

#
Calls superclass method Cookbooks::Base#opnn
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 369
def opnn
  super(NAMESPACE)
end
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
#

#return_program_information

Simple wrapper over class ProgramInformation.

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 280
def return_program_information(i, be_verbose = false)
  ::ProgramInformation.return_real_name(i)
end
run() click to toggle source
#

run (run tag)

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 478
def run
  run_everything
end
run_everything() click to toggle source
#

#run_everything

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 468
def run_everything
  update unless @interactive_mode
  consider_creating_a_new_cookbook_file # This will create the file in question.
  report_to_user
  consider_opening_in_editor
end
save()
Alias for: store
set_base_dir(i) click to toggle source
#

#set_base_dir

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 196
def set_base_dir(i)
  i = i.to_s # We require a String here.
  @base_dir = ' base_dir: '+i+N
  update
end
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_description

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 138
def set_description(
    i = 'Default description of the program.'
  )
  i = i.to_s
  @description = i
end
set_file(i) click to toggle source
#

#set_file

This method is not allowed to do any modifications - it will simply assign towards the @file variable.

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 271
def set_file(i)
  @file = i
end
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_real_name(i)
Alias for: set_filename
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_url( i = '' )
Alias for: set_url1
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
store() click to toggle source
#

store (store tag)

This method stores the dataset into a .yml file finally.

#
# File lib/cookbooks/utility_scripts/create_new_cookbook.rb, line 362
def store
  write_what_into(@_, file?)
end
Also aliased as: save
ums()
Alias for: create_main_string
update()
Alias for: create_main_string
update_main_string()
Alias for: create_main_string