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



58
59
60
# File 'lib/generators/task_rack.rb', line 58

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

Instance Method Details

#choose_working_branchObject



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
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/task_rack.rb', line 15

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 existing branches
    branch_list.each_with_index do |branch_name, index|
      line = "\t(#{index + 1}) - #{branch_name}"
      if branch_name == "master"
        puts line.green
      else
        puts line
      end
    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



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

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_cronObject



131
132
133
# File 'lib/generators/task_rack.rb', line 131

def copy_mutx_cron
  template "cron.rb.tt", "#{Dir.pwd}/mutx/cron/cron.rb" unless File.exist? "#{Dir.pwd}/mutx/cron/cron.rb"
end

#copy_mutx_cron_aliveObject



127
128
129
# File 'lib/generators/task_rack.rb', line 127

def copy_mutx_cron_alive
  template "cron_alive.sh.tt", "#{Dir.pwd}/mutx/cron/cron_alive.sh" unless File.exist? "#{Dir.pwd}/mutx/cron/cron_alive.sh"
end

#copy_mutx_cronned_taskObject



156
157
158
# File 'lib/generators/task_rack.rb', line 156

def copy_mutx_cronned_task
  template "cronned_task.rb.tt", "#{Dir.pwd}/mutx/cron/cronned_task.rb" unless File.exist? "#{Dir.pwd}/mutx/cron/cronned_task.rb"
end

#copy_mutx_log_fileObject



123
124
125
# File 'lib/generators/task_rack.rb', line 123

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_mutx_restartObject



135
136
137
# File 'lib/generators/task_rack.rb', line 135

def copy_mutx_restart
  template "restart.rb.tt", "#{Dir.pwd}/mutx/restart.rb" unless File.exist? "#{Dir.pwd}/mutx/restart.rb"
end

#copy_mutx_templatesObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/generators/task_rack.rb', line 139

def copy_mutx_templates
  dir = "#{Dir.pwd}"
  template "mutx_template.html.erb.zip", "#{Dir.pwd}/mutx/templates/mutx_template.html.erb.zip" unless File.exist? "#{Dir.pwd}/mutx/templates/mutx_template.html.erb.zip"
  FileUtils.cd("#{Dir.pwd}/mutx/templates/")
  `unzip mutx_template.html.erb.zip`
  `rm mutx_template.html.erb.zip`

  FileUtils.cd(dir)

  template "mutx_body_template.html.erb.zip", "#{Dir.pwd}/mutx/templates/mutx_body_template.html.erb.zip" unless File.exist? "#{Dir.pwd}/mutx/templates/mutx_body_template.html.erb.zip"
  FileUtils.cd("#{Dir.pwd}/mutx/templates/")
  `unzip mutx_body_template.html.erb.zip`
  `rm mutx_body_template.html.erb.zip`

  FileUtils.cd(dir)
end

#copy_server_fileObject



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/generators/task_rack.rb', line 95

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



160
161
162
# File 'lib/generators/task_rack.rb', line 160

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



164
165
166
167
168
169
# File 'lib/generators/task_rack.rb', line 164

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



82
83
84
# File 'lib/generators/task_rack.rb', line 82

def creates_mutx_conf_dir
  empty_directory "mutx/conf"
end

#creates_mutx_cron_dirObject



86
87
88
# File 'lib/generators/task_rack.rb', line 86

def creates_mutx_cron_dir
  empty_directory "mutx/cron"
end

#creates_mutx_folderObject



62
63
64
# File 'lib/generators/task_rack.rb', line 62

def creates_mutx_folder
  empty_directory "mutx"
end

#creates_mutx_log_dirObject



74
75
76
# File 'lib/generators/task_rack.rb', line 74

def creates_mutx_log_dir
  empty_directory "mutx/logs"
end

#creates_mutx_outObject



70
71
72
# File 'lib/generators/task_rack.rb', line 70

def creates_mutx_out
  empty_directory "mutx/out"
end

#creates_mutx_pids_dirObject



78
79
80
# File 'lib/generators/task_rack.rb', line 78

def creates_mutx_pids_dir
  empty_directory "mutx/pids"
end

#creates_mutx_temp_folderObject



66
67
68
# File 'lib/generators/task_rack.rb', line 66

def creates_mutx_temp_folder
  empty_directory "mutx/temp"
end

#creates_mutx_templates_dirObject



90
91
92
# File 'lib/generators/task_rack.rb', line 90

def creates_mutx_templates_dir
  empty_directory "mutx/templates"
end

#push_changesObject



198
199
200
201
202
203
204
205
206
207
# File 'lib/generators/task_rack.rb', line 198

def push_changes
  unless @local
    if yes?("\n  Your Gemfile has been updated with mutx gem. You should push this change. Do you want mutx do it for you? (yes/no)", color = :red)
      Mutx::Support::Git.add_commit "Mutx: Gemfile updated"
      Mutx::Support::Git.push_origin_to_actual_branch
    else
      puts "Do not forget to use mutx gem on your Gemfile. Otherwise, it will not work properly"
    end
  end
end

#update_gemfileObject



184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/generators/task_rack.rb', line 184

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"
    line_to_write = "gem 'mutx'"
    f.write "#{line_to_write}\n" unless content.include? line_to_write
    f.close
  end

end

#update_gitignoreObject



171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/generators/task_rack.rb', line 171

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



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

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