Module: Kickstart::Scripting

Defined in:
lib/scripting.rb

Instance Method Summary collapse

Instance Method Details

#after_allObject



169
# File 'lib/scripting.rb', line 169

def after_all; end

#after_create_databasesObject



163
# File 'lib/scripting.rb', line 163

def after_create_databases; end

#after_edit_routesObject



167
# File 'lib/scripting.rb', line 167

def after_edit_routes; end

#after_kickingObject



161
# File 'lib/scripting.rb', line 161

def after_kicking; end

#after_migrateObject



165
# File 'lib/scripting.rb', line 165

def after_migrate; end

#after_required_pluginsObject



159
# File 'lib/scripting.rb', line 159

def after_required_plugins; end

#after_setupObject



157
# File 'lib/scripting.rb', line 157

def after_setup; end

#before_create_databasesObject



162
# File 'lib/scripting.rb', line 162

def before_create_databases; end

#before_edit_routesObject



166
# File 'lib/scripting.rb', line 166

def before_edit_routes; end

#before_kickingObject



160
# File 'lib/scripting.rb', line 160

def before_kicking; end

#before_migrateObject



164
# File 'lib/scripting.rb', line 164

def before_migrate; end

#before_required_pluginsObject



158
# File 'lib/scripting.rb', line 158

def before_required_plugins; end

#before_setupObject



156
# File 'lib/scripting.rb', line 156

def before_setup; end

#before_start_serverObject



168
# File 'lib/scripting.rb', line 168

def before_start_server; end

#condition_repositoryObject



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_databasesObject



68
69
70
71
# File 'lib/scripting.rb', line 68

def create_databases
  create_database('test')
  create_database('development')
end

#delete_rails_indexObject



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

Returns:

  • (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_configObject



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

Returns:

  • (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_routesObject



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

Returns:

  • (Boolean)


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

def edit_routes? bool
  @edit_routes = bool
end

#finishObject



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

#migrateObject



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_definedObject



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_bankObject



23
# File 'lib/scripting.rb', line 23

def repo_bank; {} end

#request_mysqladmin_pass?(bool = nil) ⇒ Boolean

Returns:

  • (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

#separatorObject



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_serverObject



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_firstObject



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