Class: Roebe::ConfigGenerator

Inherits:
Base show all
Defined in:
lib/roebe/classes/config_generator.rb

Overview

Roebe::ConfigGenerator

Constant Summary

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #show_help, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow

Methods included from Base::CommandlineArguments

#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments

Constructor Details

#initialize(i = nil, run_already = true) ⇒ ConfigGenerator

#

initialize

#


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/roebe/classes/config_generator.rb', line 27

def initialize(
    i           = nil,
    run_already = true
  )
  handle_input(i) # Must come before reset().
  reset
  case run_already
  when :dont_run_yet
    run_already = false
  end
  run if run_already
end

Instance Method Details

#commentObject

#

comment

#


108
109
110
# File 'lib/roebe/classes/config_generator.rb', line 108

def comment
  return '# '+('=' * 75)+' #'+N
end

#generate_configuration_fileObject

#

generate_configuration_file

#


115
116
117
# File 'lib/roebe/classes/config_generator.rb', line 115

def generate_configuration_file
  generate_file
end

#generate_fileObject

#

generate_file

#


163
164
165
166
167
168
169
# File 'lib/roebe/classes/config_generator.rb', line 163

def generate_file
  remove_file(main_file?) if File.exist? main_file?
  opne 'Next generating the file `'+sfile(main_file?)+'`.'
  @hash.each_pair {|name, content|
    append_what_into(content, main_file?)
  }
end

#get_original_filesObject

#

get_original_files

Obtain the original files.

#


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/roebe/classes/config_generator.rb', line 124

def get_original_files
  # ======================================================================= #
  # Next obtain all input-files:
  # ======================================================================= #
  @input_files = Dir[main_dir?+'*']
  # ======================================================================= #
  # Reject .rb files and .md markdown files, for now:
  # ======================================================================= #
  @input_files.reject! {|this_file|
    this_file.end_with?('.rb') or
    this_file.end_with?('.md')
  }
  @input_files.sort.each {|file|
    file = File.basename(file)
    unless @hash.has_key? file
      dataset = ''.dup
      if @denote_which_file_was_added
        dataset << comment
        dataset << "# Taken the following from the file:#{N}"
        dataset << "#   #{file}#{N}"
        dataset << comment+N
      end
      dataset << File.read(config_dir?+file)+N+N
      @hash[file] = dataset
    end
  }
  return @input_files
end

#handle_input(i = '') ⇒ Object

#

handle_input

Here we handle the different input.

#


93
94
95
96
97
98
99
100
101
102
103
# File 'lib/roebe/classes/config_generator.rb', line 93

def handle_input(i = '')
  i = i.first if i.is_a? Array
  if i.is_a? Hash
    if i.has_key? :config_directory
      set_config_directory i[:config_directory]
    end
    if i.has_key? :store_here
      set_store_here i[:store_here]
    end
  end
end

#hash?Boolean Also known as: hash

#

hash?

#

Returns:

  • (Boolean)


189
190
191
# File 'lib/roebe/classes/config_generator.rb', line 189

def hash?
  @hash
end

#main_dir?Boolean Also known as: config_dir?

#

main_dir?

#

Returns:

  • (Boolean)


156
157
158
# File 'lib/roebe/classes/config_generator.rb', line 156

def main_dir?
  @config_directory.to_s
end

#main_file?Boolean

#

main_file?

#

Returns:

  • (Boolean)


84
85
86
# File 'lib/roebe/classes/config_generator.rb', line 84

def main_file?
  @generate_this_file
end

#merge_this_subsection_into(hash) ⇒ Object

#

merge_this_subsection_into

#


174
175
176
177
178
179
180
181
182
183
184
# File 'lib/roebe/classes/config_generator.rb', line 174

def merge_this_subsection_into(hash)
  key, value = hash.first
  # ======================================================================= #
  # The @hash at this point has both key and value as its keys.
  # ======================================================================= #
  key = File.basename(key)
  new_data = N+File.read(config_dir?+value)+N+
             @hash[key].to_s+N
  @hash.delete(key) # Remove the old key.
  @hash[value] = new_data # Set the new value here.
end

#resetObject

#

reset (reset tag)

#


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/roebe/classes/config_generator.rb', line 43

def reset
  super()
  infer_the_namespace
  # === @input_files
  @input_files = []
  # ======================================================================= #
  # === @denote_which_file_was_added
  # ======================================================================= #
  @denote_which_file_was_added = true
  # ======================================================================= #
  # === @hash
  # ======================================================================= #
  @hash = {}
  get_original_files
end

#runObject

#

run (run tag)

#


196
197
198
# File 'lib/roebe/classes/config_generator.rb', line 196

def run
  generate_configuration_file
end

#set_config_directory(i = return_pwd) ⇒ Object

#

set_config_directory

#


62
63
64
65
66
67
68
69
# File 'lib/roebe/classes/config_generator.rb', line 62

def set_config_directory(i = return_pwd)
  i = i.to_s
  i << '/' unless i.end_with? '/'
  if i.include? '$'
    i = convert_global_env(i)
  end
  @config_directory = i
end

#set_generate_this_file(i) ⇒ Object Also known as: set_store_here

#

set_generate_this_file

#


74
75
76
77
78
79
# File 'lib/roebe/classes/config_generator.rb', line 74

def set_generate_this_file(i)
  if i.include? '$'
    i = convert_global_env(i)
  end
  @generate_this_file = i
end