Class: Mutx::TaskRack

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/generators/task_rack.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject

Start install task



48
49
50
# File 'lib/generators/task_rack.rb', line 48

def self.source_root
  File.dirname(__FILE__) + "/templates/"
end

Instance Method Details

#choose_working_branchObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/task_rack.rb', line 10

def choose_working_branch

  # Gets the list of branches
  branch_list=Mutx::Support::Git.branch_list
  branch_list << "local files"

  begin
    system "clear"
    Mutx::Support::Logo.show
    puts "
  You have to choose one of the following branches to tell Mutx where to work with:"
    # Print the options
    branch_list.each_with_index do |branch_name, index|
      puts "\t(#{index + 1}) - #{branch_name}"
    end
    print "\n\t     Your option:"; option = STDIN.gets

    #Converted to Fixnum
    option = option.gsub!("\n","").to_i

  end until (1..branch_list.size).include? option


  selected_branch_name = branch_list[option-1]
  puts "
  Lets work on '#{selected_branch_name}'

  "
  
  Mutx::Support::Git.checkout_to(selected_branch_name) unless (@local = selected_branch_name == "local files")
  Mutx::Support::Git.pull
end

#copy_mutx_confObject



93
94
95
# File 'lib/generators/task_rack.rb', line 93

def copy_mutx_conf
  template "mutx.conf.tt", "#{Dir.pwd}/mutx/conf/mutx.conf" unless File.exist? "#{Dir.pwd}/mutx/conf/mutx.conf"
end

#copy_mutx_log_fileObject



106
107
108
# File 'lib/generators/task_rack.rb', line 106

def copy_mutx_log_file
  template "mutx.log.tt", "#{Dir.pwd}/mutx/logs/mutx.log" unless File.exist? "#{Dir.pwd}/mutx/logs/mutx.log"
end

#copy_server_fileObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/generators/task_rack.rb', line 78

def copy_server_file
  unless File.exist? "#{Dir.pwd}/mutx/config.ru"
	 template "config.ru.tt", "#{Dir.pwd}/mutx/config.ru"

  else

    if yes?("\n  It seems that you already have a config.ru file. DO YOU WANT TO REPLACE IT? (yes/no)", color = :green)
      template "config.ru.tt", "#{Dir.pwd}/mutx/config.ru"
    else
      raise "The existing config.ru file must be replaced with config.ru file from Mutx"
    end
  end
end

#copy_sidekiq_log_fileObject



110
111
112
# File 'lib/generators/task_rack.rb', line 110

def copy_sidekiq_log_file
  template "sidekiq.log.tt", "#{Dir.pwd}/mutx/logs/sidekiq.log" unless File.exist? "#{Dir.pwd}/mutx/logs/sidekiq.log"
end

#copy_unicorn_config_fileObject



114
115
116
117
118
119
# File 'lib/generators/task_rack.rb', line 114

def copy_unicorn_config_file
  unless File.exist? "#{Dir.pwd}/mutx/unicorn.rb"
    template "unicorn.rb.tt", "#{Dir.pwd}/mutx/unicorn.rb"
    @unicorn_created = true
  end
end

#creates_mutx_conf_dirObject



72
73
74
# File 'lib/generators/task_rack.rb', line 72

def creates_mutx_conf_dir
  empty_directory "mutx/conf"
end

#creates_mutx_folderObject



52
53
54
# File 'lib/generators/task_rack.rb', line 52

def creates_mutx_folder
  empty_directory "mutx"
end

#creates_mutx_log_dirObject



64
65
66
# File 'lib/generators/task_rack.rb', line 64

def creates_mutx_log_dir
  empty_directory "mutx/logs"
end

#creates_mutx_outObject



60
61
62
# File 'lib/generators/task_rack.rb', line 60

def creates_mutx_out
  empty_directory "mutx/out"
end

#creates_mutx_pids_dirObject



68
69
70
# File 'lib/generators/task_rack.rb', line 68

def creates_mutx_pids_dir
  empty_directory "mutx/pids"
end

#creates_mutx_temp_folderObject



56
57
58
# File 'lib/generators/task_rack.rb', line 56

def creates_mutx_temp_folder
  empty_directory "mutx/temp"
end

#push_changesObject



150
151
152
153
154
155
# File 'lib/generators/task_rack.rb', line 150

def push_changes
  unless @local
    Mutx::Support::Git.add_commit "Mutx: Commit after install command execution"
    Mutx::Support::Git.push_origin_to_actual_branch
  end
end

#update_gemfileObject



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/generators/task_rack.rb', line 136

def update_gemfile
  path = "#{Dir.pwd}/Gemfile"
  if File.exist? path
    f = File.open(path, "a+")
    content = ""
    f.each_line{|line| content += line}
    f.write "\n" unless content[-1] == "\n"
    ["gem 'mutx'"].each do |file_name|
      f.write "#{file_name}\n" unless content.include? "#{file_name}"
    end
  end

end

#update_gitignoreObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/generators/task_rack.rb', line 121

def update_gitignore
  path = "#{Dir.pwd}/.gitignore"
  if File.exist? path
    f = File.open(path, "a+")
    content = ""
    f.each_line{|line| content += line}
    f.write "\n" unless content[-1] == "\n"
    f.write "mutx/\n" unless content.include? "mutx/"
    f.write "mutx/*\n" unless content.include? "mutx/*"


    f.close
  end
end

#updating_git_usage_as_false_if_localObject



97
98
99
100
101
102
103
104
# File 'lib/generators/task_rack.rb', line 97

def updating_git_usage_as_false_if_local
  if @local
    config_file_content = JSON.parse(IO.read("#{Dir.pwd}/mutx/conf/mutx.conf"))
    config_file_content["use_git"] = false
    content_to_save = config_file_content.to_json.gsub(",",",\n").gsub("{","{\n")
    IO.write("#{Dir.pwd}/mutx/conf/mutx.conf",content_to_save)
  end
end