Module: Kickstart::Scripting
- Defined in:
- lib/scripting.rb
Instance Method Summary collapse
- #after_all ⇒ Object
- #after_create_databases ⇒ Object
- #after_edit_routes ⇒ Object
- #after_kicking ⇒ Object
- #after_migrate ⇒ Object
- #after_required_plugins ⇒ Object
- #after_setup ⇒ Object
- #before_create_databases ⇒ Object
- #before_edit_routes ⇒ Object
- #before_kicking ⇒ Object
- #before_migrate ⇒ Object
- #before_required_plugins ⇒ Object
- #before_setup ⇒ Object
- #before_start_server ⇒ Object
- #condition_repository ⇒ Object
- #create_database(which) ⇒ Object
- #create_databases ⇒ Object
- #delete_rails_index ⇒ Object
- #delete_rails_index?(bool) ⇒ Boolean
- #edit_db_config ⇒ Object
- #edit_db_config?(bool = nil) ⇒ Boolean
- #edit_routes ⇒ Object
- #edit_routes?(bool) ⇒ Boolean
- #finish ⇒ Object
- #goto_project(where = nil) ⇒ Object
- #kick_it!(huh) ⇒ Object
- #migrate ⇒ Object
- #mysqladmin_user(who = nil) ⇒ Object
- #no_repository_defined ⇒ Object
- #repo_bank ⇒ Object
- #request_mysqladmin_pass?(bool = nil) ⇒ Boolean
- #separator ⇒ Object
- #setup_project(arg) ⇒ Object
- #start_server ⇒ Object
- #use_repo_first ⇒ Object
Instance Method Details
#after_all ⇒ Object
169 |
# File 'lib/scripting.rb', line 169 def after_all; end |
#after_create_databases ⇒ Object
163 |
# File 'lib/scripting.rb', line 163 def after_create_databases; end |
#after_edit_routes ⇒ Object
167 |
# File 'lib/scripting.rb', line 167 def after_edit_routes; end |
#after_kicking ⇒ Object
161 |
# File 'lib/scripting.rb', line 161 def after_kicking; end |
#after_migrate ⇒ Object
165 |
# File 'lib/scripting.rb', line 165 def after_migrate; end |
#after_required_plugins ⇒ Object
159 |
# File 'lib/scripting.rb', line 159 def after_required_plugins; end |
#after_setup ⇒ Object
157 |
# File 'lib/scripting.rb', line 157 def after_setup; end |
#before_create_databases ⇒ Object
162 |
# File 'lib/scripting.rb', line 162 def before_create_databases; end |
#before_edit_routes ⇒ Object
166 |
# File 'lib/scripting.rb', line 166 def before_edit_routes; end |
#before_kicking ⇒ Object
160 |
# File 'lib/scripting.rb', line 160 def before_kicking; end |
#before_migrate ⇒ Object
164 |
# File 'lib/scripting.rb', line 164 def before_migrate; end |
#before_required_plugins ⇒ Object
158 |
# File 'lib/scripting.rb', line 158 def before_required_plugins; end |
#before_setup ⇒ Object
156 |
# File 'lib/scripting.rb', line 156 def before_setup; end |
#before_start_server ⇒ Object
168 |
# File 'lib/scripting.rb', line 168 def before_start_server; end |
#condition_repository ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/scripting.rb', line 126 def condition_repository Repository.remove "log/*" Repository.commit "removing logs from repository" Repository.ignore "*.log", "log/" Repository.update "log/" Repository.commit "ignoring all .log files in log/" Repository.ignore "*", "tmp/sessions" Repository.ignore "*", "tmp/cache" Repository.ignore "*", "tmp/sockets" Repository.commit "ignoring all files in tmp/" Repository.remove "config/database.yml" Repository.ignore "database.yml", "config/" Repository.update "config/" Repository.commit "ignoring database.yml" puts "\ncopying database.yml back in place\n" copy "../#{@project_name}_tmp/config/database.yml", 'config/' Repository.remove "tmp/*" Repository.ignore "*", "tmp/" Repository.update "tmp/" Repository.commit "ignoring all tmp/ content" destroy '../'+@project_name+'_tmp' end |
#create_database(which) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/scripting.rb', line 93 def create_database(which) mysqladmin_user(request_value('please enter mysqladmin username [default: root]')) if @mysqladmin_user.nil? puts "creating mysql database for #{which}" puts "mysqladmin create #{@dbconfig[which]['database']} -u #{@mysqladmin_user == '' ? 'root' : @mysqladmin_user } #{'-p' if @mysqladmin_pass} " system "mysqladmin create #{@dbconfig[which]['database']} -u #{@mysqladmin_user == '' ? 'root' : @mysqladmin_user } #{'-p' if @mysqladmin_pass} " end |
#create_databases ⇒ Object
68 69 70 71 |
# File 'lib/scripting.rb', line 68 def create_databases create_database('test') create_database('development') end |
#delete_rails_index ⇒ Object
113 114 115 116 |
# File 'lib/scripting.rb', line 113 def delete_rails_index @delete_index = request_value 'delete the rails index page? [Y/n]' if @delete_index.nil? destroy 'public/index.html' unless @delete_index.to_s.downcase=='n' if @delete_index && @delete_index != 'n' end |
#delete_rails_index?(bool) ⇒ Boolean
108 109 110 111 |
# File 'lib/scripting.rb', line 108 def delete_rails_index? bool @delete_index = bool puts 'public/index.html will be deleted' end |
#edit_db_config ⇒ Object
62 63 64 65 66 |
# File 'lib/scripting.rb', line 62 def edit_db_config @edit_db = request_value "would you like to edit database.yml file? default values will be used otherwise. [Y/n]" if(@edit_db == :ask || @edit_db.nil?) system "#{ENV['HOME']} config/database.yml" if @edit_db && @edit_db != 'n' File.open('config/database.yml') { |yf| @dbconfig = YAML::load(yf) } end |
#edit_db_config?(bool = nil) ⇒ Boolean
78 79 80 81 |
# File 'lib/scripting.rb', line 78 def edit_db_config? bool = nil bool.nil? ? @edit_db : @edit_db = bool puts "@edit_db is now #{@edit_db}" end |
#edit_routes ⇒ Object
103 104 105 106 |
# File 'lib/scripting.rb', line 103 def edit_routes @edit_routes = request_value "would you like to edit routes.rb? default values will be used otherwise. [Y/n]" if(@edit_routes == :ask || @edit_routes.nil?) system "#{ENV['EDITOR']} config/routes.rb" end |
#edit_routes?(bool) ⇒ Boolean
100 101 102 |
# File 'lib/scripting.rb', line 100 def edit_routes? bool @edit_routes = bool end |
#finish ⇒ Object
123 124 125 |
# File 'lib/scripting.rb', line 123 def finish puts "\nyour project is now running at http://localhost:3000. use mongrel_rails stop to kill the server.\n\n" end |
#goto_project(where = nil) ⇒ Object
46 47 48 49 50 |
# File 'lib/scripting.rb', line 46 def goto_project(where=nil) where ||=@project_name puts "\n\n+ entering #{where} +" Dir.chdir(where) end |
#kick_it!(huh) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/scripting.rb', line 54 def kick_it!(huh) begin load("#{huh}") rescue MissingSourceFile load "../#{huh}" end end |
#migrate ⇒ Object
73 74 75 76 |
# File 'lib/scripting.rb', line 73 def migrate puts 'migrating up to start of project' system "rake db:migrate" end |
#mysqladmin_user(who = nil) ⇒ Object
83 84 85 86 |
# File 'lib/scripting.rb', line 83 def mysqladmin_user who = nil who ? @mysqladmin_user = who : @mysqladmin_user puts "@mysqladmin_user is now #{@mysqladmin_user}" end |
#no_repository_defined ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/scripting.rb', line 148 def no_repository_defined puts "moving out of the temporary directory\n\n" Dir.chdir('../') puts 'you have not defined a subversion repository' move "#{@project_name}_tmp".as_folder, @project_name.as_folder Dir.chdir @project_name end |
#repo_bank ⇒ Object
23 |
# File 'lib/scripting.rb', line 23 def repo_bank; {} end |
#request_mysqladmin_pass?(bool = nil) ⇒ Boolean
88 89 90 91 |
# File 'lib/scripting.rb', line 88 def request_mysqladmin_pass? bool = nil bool.nil? ? @mysqladmin_pass : @mysqladmin_pass = bool puts "@mysqladmin_pass is now #{@mysqladmin_pass}" end |
#separator ⇒ Object
51 52 53 |
# File 'lib/scripting.rb', line 51 def separator puts "\n#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#\n" end |
#setup_project(arg) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/scripting.rb', line 24 def setup_project(arg) if arg =~ /^(http:\/\/|svn\+ssh:\/\/|svn:\/\/|repo:\/\/|repo:)/ repo_name = arg.sub(/^.+\//, '') repo_location = arg.sub(/^repo:/, '').sub(/^\/\//, '').sub(/\/#{repo_name}/, '') if arg=~ /^repo:/ @repo_address = arg=~/^repo:/ ? "#{repo_bank[repo_location.to_sym]}/#{repo_name}" : arg @project_name ||= repo_name @kickstarter = "#{@project_name}.rails" use_repo_first write @repo_first_template.result, @kickstarter system "#{ENV['EDITOR']} #{@kickstarter}" else @kickstarter = arg @project_name ||= arg.gsub(/^.+\//, '').gsub(/\..+$/, '') end puts("rails #{@project_name}") system("rails #{@project_name}") puts "\n moving project to a temporary folder to make way for the repository \n" move @project_name, "#{@project_name}_tmp" end |
#start_server ⇒ Object
118 119 120 121 |
# File 'lib/scripting.rb', line 118 def start_server puts "\nmongrel_rails start -d" system "mongrel_rails start -d" end |
#use_repo_first ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/scripting.rb', line 8 def use_repo_first @repo_first_template = ERB.new <<-EOF Repository.define '<%=@repo_address%>',{ :user => '', :comment => 'first commit' } resource(:foo){|foo| foo.attrs :name => 'string' } EOF end |