class RBT::Cookbooks::CreateCookbookYamlFile

Constants

NAMESPACE
#

NAMESPACE

#
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
#

RBT::Cookbooks::CreateCookbookYamlFile[]

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 290
def self.[](i = '')
  self.new(i)
end
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 48
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Public Instance Methods

add_hint_for_dependencies() click to toggle source
#

add_hint_for_dependencies

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 80
def add_hint_for_dependencies
  if is_on_roebe?
    ''
  else # Add this line to help newbies.
    "# The dependencies go in here.#{N}"
  end
end
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 128
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
commandline_arguments?() click to toggle source
#

commandline_arguments?

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 70
def commandline_arguments?
  @commandline_arguments
end
consider_creating_a_new_cookbook_file()
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/misc.rb, line 65
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
description?() click to toggle source
#

description?

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 30
def description?
  @hash_information_about_the_program[:description]
end
do_not_open_in_editor() click to toggle source
#

do_not_open_in_editor

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 16
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/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 23
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

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/misc.rb, line 99
def enter_interactive_part
  @interactive_mode = true
  e 'A fewquestions may be asked next, about the values that should be'
  e 'added to the yaml file at hand.'
  e
  e slateblue('Remote URL?')
  set_url1($stdin.gets.chomp)
  e
  e slateblue('Description of the program?')
  set_description($stdin.gets.chomp)
  e
  e 'Done!'
end
file?() click to toggle source
#

file?

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 37
def file?
  @file
end
first_argument?() click to toggle source
#

first_argument?

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 77
def first_argument?
  @commandline_arguments.first
end
homepage?() click to toggle source
#

homepage?

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 148
def homepage?
  _ = ''.dup
  if @hash_information_about_the_program.has_key? :url1
    uri = URI(@hash_information_about_the_program[:url1])
    if uri
      _ = "#{uri.scheme}://#{uri.host}"
    end
  end
  _
end
menu( i = @commandline_arguments ) click to toggle source
#

menu

#
name?()
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 84
def name_of_the_program?
  File.basename(
    first_argument?
  )
end
Also aliased as: program_name?, name?
open_in_editor?() click to toggle source
#

open_in_editor?

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 144
def open_in_editor?
  @open_in_editor_after_creation
end
program_name?()
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/cookbooks/create_cookbook_yaml_file/reset.rb, line 16
def reset
  super()
  @namespace = NAMESPACE
  @editor = USE_THIS_EDITOR
  @template_file_to_use = FILE_BASE_TEMPLATE_FOR_COOKBOOK_YAML_FILES
  @dataset = []
  @hash_information_about_the_program = {}
  @open_in_editor_after_creation = OPEN_IN_EDITOR_AFTER_CREATION
  if is_on_roebe?
    @open_in_editor_after_creation = true
  end
  @file = nil
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/run.rb, line 16
def run
  sanitize_first_argument
  menu # Should come before
  verbose_make_use_of_the_template_file_and_then_sanitize_the_dataset
  if @dataset.empty?
    opnn; e '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 176
def sanitize_dataset
  @dataset.map! {|line|
    case line
    # ===================================================================== #
    # === 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 MMM YYYY/
      line = ' last_update: '+dd_mmm_yyy
    # ===================================================================== #
    # === description:
    # ===================================================================== #
    when /description: /
      if @hash_information_about_the_program.has_key? :description
        line = ' description: |'+N+
               '  '+description?
      end
    # ===================================================================== #
    # === 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 94
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
save()
set_commandline_arguments(i = '') click to toggle source
#

set_input

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 62
def set_commandline_arguments(i = '')
  i = [i].flatten.compact
  @commandline_arguments = i
end
set_description( i = 'Default description of the program.' ) click to toggle source
#

set_description

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 138
def set_description(
    i = 'Default description of the program.'
  )
  i = i.to_s.dup
  @hash_information_about_the_program[: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/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 137
def set_file(i)
  @file = i
end
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/misc.rb, line 118
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 112
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_real_name(i)
Alias for: set_filename
set_short_name(i = '')
Alias for: set_program_name
set_url( i = '' )
Alias for: set_url1
set_url1( i = '' ) click to toggle source
#

set_url1

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 272
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
#

short_program_name?

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/create_cookbook_yaml_file.rb, line 162
def short_program_name?
  _ = program_name?
  if @hash_information_about_the_program.has_key? :program_name
    _ = @hash_information_about_the_program[:program_name]
  end
  _
end
show_help() click to toggle source
#

show_help (help tag)

#
# File lib/rbt/cookbooks/create_cookbook_yaml_file/misc.rb, line 44
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()
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 232
def store_dataset_into_file
  what = @dataset.join(N)
  into = short_program_name?+'.yml'
  if File.exist? into
    if File.directory? into
      opnn; e sdir(into)+swarn(' seems to be a directory. Will not overwrite it.')
    else
      opnn; ewarn 'But there already is a file at '+sfile(into)+swarn('.')
      opnn; ewarn 'Shall we really overwrite this file?'
      case $stdin.gets.chomp
      when 'y','yes','j','ja'
        opnn; ewarn 'Overwriting `'+sfile(into)+swarn('` now.')
        write_what_into(what, into)
      else
        opnn; ewarn 'Ok - not overwriting.'
      end
    end
  else
    opnn; e 'Saving into the file `'+sfile(into)+'` next.'
    write_what_into(what, into)
  end
end
update()
Alias for: sanitize_dataset
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 260
def verbose_make_use_of_the_template_file_and_then_sanitize_the_dataset
  _ = @template_file_to_use
  if File.exist? _
    opnn; e "Making use of a template file (#{sfile(File.basename(_))})."
    @dataset = File.readlines(_).map(&:chomp)
    sanitize_dataset
  end
end