Class: RailsSVNPrep

Inherits:
Object
  • Object
show all
Defined in:
lib/rorsvnprep.rb

Overview

This class provides all the heavy lifting methods used by the command-line utility. This class could also be implemented as part of another package to provide further automated utilities.

Constant Summary collapse

@@version =
[ 0, 1, 2 ]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(projname = nil, svnuri = nil, svnpass = nil, logfile = nil, verbose = false) ⇒ RailsSVNPrep

The new method expects up to four arguments. Only if the projname argument is missing will the method raise an error for anything other than failed validation.



76
77
78
79
80
81
82
# File 'lib/rorsvnprep.rb', line 76

def initialize(projname = nil, svnuri = nil, svnpass = nil, logfile = nil, verbose = false)
  @project = projname
  @svn = svnuri
  @password = svnpass
  @log = logfile
  @verbose = verbose
end

Class Method Details

.versionObject

A convenience method to return our version number



199
200
201
# File 'lib/rorsvnprep.rb', line 199

def RailsSVNPrep.version
  @@version
end

Instance Method Details

#create_projectObject

This method creates a new project and moves us into the new directory. The method makes direct call to the rails command and dumps the output to /dev/null.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/rorsvnprep.rb', line 111

def create_project
  #if Dir::glob(@project)
  #  puts "A folder named #{@project} already exists: exiting." if @verbose
  #  @logfile.puts "A folder named #{@project} already exists: exiting." if @logfile
  #  raise StandardError
  #end
  
  if system "rails #{@project} > /dev/null"
    puts "Rails Project Folder Successfully Created."  if @verbose
    @logfile.puts "Rails Project Folder Successfully Created."  if @logfile
    Dir::chdir @project
  else
    puts "Error creating the Rails project folder: exiting." if @verbose
    @logfile.puts "Error creating the Rails project folder: exiting." if @logfile
    raise StandardError
  end
end

#finalizeObject

This method finishes up by committing to subversion if needed and performing other house-keeping measures.



188
189
190
191
192
193
194
195
196
# File 'lib/rorsvnprep.rb', line 188

def finalize
  if @svn
    puts "Committing updates." if @verbose
    @logfile.puts "Committing updates." if @logfile
  
    system "svn commit -m \"Updated svn:ignore properties\" > /dev/null"
    Dir::chdir ".."
  end
end

#generate_cvsignoreObject

This method produces .cvsignore files for those times when you don’t want an initial subversion import done.

TODO: Actually implement this.



147
148
# File 'lib/rorsvnprep.rb', line 147

def generate_cvsignore
end

#runObject

A simple method that calls all the other individual methods as necessary to create the rails project, prep it and produce a good working copy.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rorsvnprep.rb', line 86

def run
  puts "Rails SVN Prep: Starting." if @verbose
  @logfile.puts "Rails SVN Prep: Starting." if @logfile
  
  create_project
  
  trim_project
  
  generate_cvsignore unless @svn
        
  subversion_import if @svn
  
  subversion_checkout if @svn
  
  subversion_propset if @svn
  
  finalize
  
  puts "Rails SVN Prep: Complete." if @verbose
  @logfile.puts "Rails SVN Prep: Complete." if @logfile
end

#subversion_checkoutObject

This method produces the initial working copy via a subversion checkout.



162
163
164
165
166
167
168
# File 'lib/rorsvnprep.rb', line 162

def subversion_checkout
  puts "Checking out project from subversion." if @verbose
  @logfile.puts "Checking out project from subversion." if @logfile

  system "svn co #{@svn} #{@project} > /dev/null"
  Dir::chdir @project
end

#subversion_importObject

This method performs the initial subversion import and then deletes the project folder in preparation for the initial checkout.



152
153
154
155
156
157
158
159
# File 'lib/rorsvnprep.rb', line 152

def subversion_import
  puts "Importing project to subvserion." if @verbose
  @logfile.puts "Importing project to subvserion." if @logfile

  system "svn import #{@svn} -m \"Initial import\" > /dev/null"
  Dir::chdir ".."
  system "rm -rf #{@project} > /dev/null"
end

#subversion_propsetObject

This method sets the svn:ignore property across a number of folders to make sure files that don’t belong in version control don’t end up in it.



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/rorsvnprep.rb', line 172

def subversion_propset
  puts "Configuring svn:ignore properties." if @verbose
  @logfile.puts "Configuring svn:ignore properties." if @logfile

  system "svn propset svn:ignore \"*.log\n*.pid\" log/ > /dev/null"
  system "svn update log/ > /dev/null"
  system "svn propset svn:ignore \"*\" tmp/ > /dev/null"
  system "svn update tmp/ > /dev/null"
  system "svn propset svn:ignore \"*.db\n*.sqlite\n*.sqlite3\nschema.rb\nschema.sql\" db/ > /dev/null"
  system "svn update db/ > /dev/null"
  system "svn propset svn:ignore \"database.yml\" config/ > /dev/null"
  system "svn update config/ > /dev/null"
end

#trim_projectObject

This method prunes the initial project structure by renaming config/database.yml, getting rid of the default README and README_FOR_APP files and clearing our the log/ and tmp/ folders.



132
133
134
135
136
137
138
139
140
141
# File 'lib/rorsvnprep.rb', line 132

def trim_project
  puts "Triming initial project." if @verbose
  @logfile.puts "Triming initial project." if @logfile
  
  File::rename "config/database.yml", "config/database.yml.sample"
  File::delete "doc/README_FOR_APP"
  File::delete "README"
  system "rm -rf log/* > /dev/null"
  system "rm -rf tmp/* > /dev/null"
end