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



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

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

Instance Method Details

#check_for_mongo_existanceObject

Evaluates prerequisites



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/task_rack.rb', line 12

def check_for_mongo_existance
  begin
    mongo = Kaya::Support::Console.execute "mongo --version"
    mongo_version = mongo.scan(/(\d+\.\d+\.\d+)/).flatten.first
  rescue
    raise "
MONGODB NOT INSTALLED. INSTALL MONGODB BEFORE USING KAYA
to install MongoDB go to: http://docs.mongodb.org/manual/installation/
" if mongo_version.nil?
    end
    puts "MongoDB version installed => #{mongo_version} => OK"
end

#check_redis_existanceObject



26
27
28
29
30
31
32
33
# File 'lib/generators/task_rack.rb', line 26

def check_redis_existance
  redis = Kaya::Support::Console.execute "redis-server -v"
  raise "
REDIS SERVER IS NOT INSTALLED ON YOUR SYSTEM.
INSTALL REDIS SERVER BEFORE USING KAYA
to install Redis go to:
  " unless redis =~ /Redis server v=\d+\.\d+\.\d+/
end

#choose_working_branchObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/task_rack.rb', line 36

def choose_working_branch

  # Gets the list of branches
  branch_list=Kaya::Support::Git.branch_list

  begin
    system "clear"
    Kaya::Support::Logo.show
    puts "
You have to choose one of the following branches to tell Kaya 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}'

  "


  Kaya::Support::Git.checkout_to(selected_branch_name)
end

#copy_kaya_confObject



100
101
102
# File 'lib/generators/task_rack.rb', line 100

def copy_kaya_conf
  template "kaya_conf.tt", "#{Dir.pwd}/kaya/kaya_conf" unless File.exist? "#{Dir.pwd}/kaya/kaya_conf"
end

#copy_kaya_log_fileObject



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

def copy_kaya_log_file
  template "kaya_log.tt", "#{Dir.pwd}/kaya/kaya_log" unless File.exist? "#{Dir.pwd}/kaya/kaya_log"
end

#copy_server_fileObject



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/generators/task_rack.rb', line 85

def copy_server_file
  unless File.exist? "#{Dir.pwd}/kaya/config.ru"
	 template "config.ru.tt", "#{Dir.pwd}/kaya/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}/kaya/config.ru"
    else
      raise "The existing config.ru file must be replaced with config.ru file from Kaya"
    end
  end
end

#copy_sidekiq_log_fileObject



108
109
110
# File 'lib/generators/task_rack.rb', line 108

def copy_sidekiq_log_file
  template "sidekiq_log.tt", "#{Dir.pwd}/kaya/sidekiq_log" unless File.exist? "#{Dir.pwd}/kaya/sidekiq_log"
end

#copy_unicorn_config_fileObject



112
113
114
115
116
117
# File 'lib/generators/task_rack.rb', line 112

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

#creates_kaya_folderObject



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

def creates_kaya_folder
  empty_directory "kaya"
end

#creates_kaya_temp_folderObject



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

def creates_kaya_temp_folder
  empty_directory "kaya/temp"
end

#push_changesObject



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

def push_changes
  Kaya::Support::Git.git_add_commit "Kaya: Commit after install command execution"
  Kaya::Support::Git.git_push_origin_to_actual_branch
end

#update_gemfileObject



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

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 'kaya'"].each do |file_name|
      f.write "#{file_name}\n" unless content.include? "#{file_name}"
    end
  else
    # Only cucumber projects are allowed to use Kaya (by now)
    raise "There is no Gemfile. Is this a Cucumber Ruby Project?"
  end

end

#update_gitignoreObject



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

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"
    # ['*.kaya','kaya_conf','*.html','unicorn.rb', 'config.ru','Gemfile.lock', 'kaya_pids','sidekiq_pids', 'sidekiq_log'].each do |file_name|
    #   f.write "#{file_name}\n" unless content.include? "#{file_name}"
    # end

    f.write "kaya/\n" unless content.include? "kaya/"
    f.write "kaya/*\n" unless content.include? "kaya/*"


    f.close
  end
end