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



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

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

Instance Method Details

#choose_working_branchObject



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
42
43
44
45
# File 'lib/generators/task_rack.rb', line 14

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::.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



104
105
106
# File 'lib/generators/task_rack.rb', line 104

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



125
126
127
# File 'lib/generators/task_rack.rb', line 125

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



121
122
123
# File 'lib/generators/task_rack.rb', line 121

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



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

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



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

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



129
130
131
# File 'lib/generators/task_rack.rb', line 129

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



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

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



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/generators/task_rack.rb', line 89

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



154
155
156
# File 'lib/generators/task_rack.rb', line 154

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



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

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



76
77
78
# File 'lib/generators/task_rack.rb', line 76

def creates_mutx_conf_dir
  empty_directory "mutx/conf"
end

#creates_mutx_cron_dirObject



80
81
82
# File 'lib/generators/task_rack.rb', line 80

def creates_mutx_cron_dir
  empty_directory "mutx/cron"
end

#creates_mutx_folderObject



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

def creates_mutx_folder
  empty_directory "mutx"
end

#creates_mutx_log_dirObject



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

def creates_mutx_log_dir
  empty_directory "mutx/logs"
end

#creates_mutx_outObject



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

def creates_mutx_out
  empty_directory "mutx/out"
end

#creates_mutx_pids_dirObject



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

def creates_mutx_pids_dir
  empty_directory "mutx/pids"
end

#creates_mutx_temp_folderObject



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

def creates_mutx_temp_folder
  empty_directory "mutx/temp"
end

#creates_mutx_templates_dirObject



84
85
86
# File 'lib/generators/task_rack.rb', line 84

def creates_mutx_templates_dir
  empty_directory "mutx/templates"
end

#push_changesObject



192
193
194
195
196
197
198
199
200
201
# File 'lib/generators/task_rack.rb', line 192

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



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/generators/task_rack.rb', line 178

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



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/generators/task_rack.rb', line 165

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



108
109
110
111
112
113
114
115
# File 'lib/generators/task_rack.rb', line 108

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