Skip to content

Commit

Permalink
Updated readme, added comments to Rakefile, added license
Browse files Browse the repository at this point in the history
  • Loading branch information
colszowka committed Feb 20, 2009
1 parent 13770c9 commit 84b1bd6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 Christoph Olszowka

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 changes: 9 additions & 0 deletions README.textile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
h1. ActiveRecord Skeleton
A basic skeleton for ActiveRecord-backed Ruby apps, including a ready-to-go structure with YAML database config and rake tasks for migrating the database and generating migrations

h2. Usage
# TODO...

h2. Copyright

activerecord-skeleton is Copyright © 2009 Christoph Olszowka, It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
10 changes: 9 additions & 1 deletion Rakefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,26 +12,34 @@ namespace :generate do
task :migration => :environment do task :migration => :environment do
raise "Please specify desired migration name with NAME=my_migration_name" unless ENV['NAME'] raise "Please specify desired migration name with NAME=my_migration_name" unless ENV['NAME']


# Find migration name from env
migration_name = ENV['NAME'].strip.chomp migration_name = ENV['NAME'].strip.chomp


# Define migrations path (needed later)
migrations_path = File.join(File.dirname(__FILE__), 'db', 'migrate') migrations_path = File.join(File.dirname(__FILE__), 'db', 'migrate')


# Find the highest existing migration version # Find the highest existing migration version or set to 1
if (existing_migrations = Dir[File.join(migrations_path, '*.rb')]).length > 0 if (existing_migrations = Dir[File.join(migrations_path, '*.rb')]).length > 0
version = File.basename(existing_migrations.sort.reverse.first)[/^(\d+)_/,1].to_i + 1 version = File.basename(existing_migrations.sort.reverse.first)[/^(\d+)_/,1].to_i + 1
else else
version = 1 version = 1
end end


# Read the contents of the migration template into string
migrations_template = File.read(File.join(migrations_path, 'migration.template') ) migrations_template = File.read(File.join(migrations_path, 'migration.template') )


# Replace the migration name in template with the acutal one
migration_content = migrations_template.gsub('__migration_name__', migration_name.camelize) migration_content = migrations_template.gsub('__migration_name__', migration_name.camelize)

# Generate migration filename
migration_filename = "#{"%03d" % version}_#{migration_name}.rb" migration_filename = "#{"%03d" % version}_#{migration_name}.rb"


# Write the migration
File.open(File.join(migrations_path, migration_filename), "w+") do |migration| File.open(File.join(migrations_path, migration_filename), "w+") do |migration|
migration.puts migration_content migration.puts migration_content
end end


# Done!
puts "Successfully created migration #{migration_filename}" puts "Successfully created migration #{migration_filename}"
end end
end end

0 comments on commit 84b1bd6

Please sign in to comment.