Class: JumpStart::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/jumpstart/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Base

Sets up JumpStart::Base object with preliminary instance variables.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jumpstart/base.rb', line 18

def initialize(args)
  # setup for testing input
  @input  = $stdin
  # setup for testing output
  @output = $stdout
  # set the name of the project from the first argument passed, or from the module instance variable JumpStart.default_template_name if no argument passed.
  @project_name = args[0].dup unless args[0].nil?
  @template_name = args[1].dup unless args[1].nil?
  case
  when args.nil?
    @template_name = JumpStart.default_template_name unless JumpStart.default_template_name.nil?
    jumpstart_menu
  when !args[0].nil? && args[1].nil?
    @template_name = JumpStart.default_template_name unless JumpStart.default_template_name.nil?
  end
  # set instance variable @template_path as the directory to read templates from.
  @template_path = FileUtils.join_paths(JumpStart.templates_path, @template_name)
end

Instance Attribute Details

#inputObject

Accessor methods to make testing input or output easier.



5
6
7
# File 'lib/jumpstart/base.rb', line 5

def input
  @input
end

#outputObject

Accessor methods to make testing input or output easier.



5
6
7
# File 'lib/jumpstart/base.rb', line 5

def output
  @output
end

Class Method Details

.get_line_number(file_name) ⇒ Object

Class instance method that returns an integer to be used as the line number for line templates. Returns false if no match is found.



625
626
627
628
629
630
631
632
# File 'lib/jumpstart/base.rb', line 625

def get_line_number(file_name)
  if file_name.match(/_(\d+)\._\w*/)
    number = file_name.match(/_(\d+)\._\w*/)[1]
    number.to_i
  else
    return false
  end
end

.remove_last_line?(file_name) ⇒ Boolean

Class instance method that returns true or false for removing the last line of a file. Append templates with the l. or L. prefix will return true.

Returns:

  • (Boolean)


636
637
638
639
640
641
642
# File 'lib/jumpstart/base.rb', line 636

def remove_last_line?(file_name)
  if file_name.match(/_([lL]{1})\._{1}\w*/)
    return true
  else
    return false
  end
end

Instance Method Details

#check_replace_string_pairs_for_project_name_sub(hash) ⇒ Object

Checks replace string values for :project_name and replaces these with the value of @project_name if found. This enables PROJECT_NAME entries in projects to be dynamically populated with the current project name.



82
83
84
85
86
87
88
89
90
91
# File 'lib/jumpstart/base.rb', line 82

def check_replace_string_pairs_for_project_name_sub(hash)
  unless @project_name.nil?
    hash.each do |key, value|
      if key == :project_name
        hash[key] = @project_name
      end
    end
  end
  hash
end

#check_setupObject

Pre-install project configuration checking.



53
54
55
56
57
58
59
# File 'lib/jumpstart/base.rb', line 53

def check_setup
  set_config_file_options
  check_project_name
  check_template_name
  check_template_path
  check_install_path
end

#gets(*args) ⇒ Object

Monkeypatch gets to make testing easier.



8
9
10
# File 'lib/jumpstart/base.rb', line 8

def gets(*args)
  @input.gets(*args)
end

#puts(*args) ⇒ Object

Monkeypatch puts to make testing easier.



13
14
15
# File 'lib/jumpstart/base.rb', line 13

def puts(*args)
  @output.puts(*args)
end

#set_config_file_optionsObject

Sets up instance variables from YAML file



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jumpstart/base.rb', line 38

def set_config_file_options
  if @template_name.nil? || @template_path.nil?
    jumpstart_menu
  elsif File.exists?(FileUtils.join_paths(@template_path, '/jumpstart_config/',"#{@template_name}.yml"))
    @config_file = YAML.load_file(FileUtils.join_paths(@template_path, "/jumpstart_config/", "#{@template_name}.yml"))
    @install_command ||= @config_file[:install_command]
    @install_command_args ||= @config_file[:install_command_args]
    @replace_strings ||= @config_file[:replace_strings].each {|x| x}
    @install_path ||= @config_file[:install_path]
  else
    jumpstart_menu
  end
end

#startObject

Runs the configuration, generating the new project from the chosen template.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/jumpstart/base.rb', line 62

def start
  puts "\n******************************************************************************************************************************************\n\n"
  puts "  JumpStarting....\n".purple
  check_setup
  execute_install_command
  run_scripts_from_yaml(:run_after_install_command)
  parse_template_dir
  create_dirs
  populate_files_from_whole_templates
  populate_files_from_append_templates
  populate_files_from_line_templates
  remove_unwanted_files
  run_scripts_from_yaml(:run_after_jumpstart)
  check_for_strings_to_replace
  run_scripts_from_yaml(:run_after_string_replace)
  check_local_nginx_configuration
  exit_with_success
end