slim_migrations 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Jan Lelis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,59 @@
1
+ === SlimMigrations
2
+
3
+ Turns
4
+
5
+ class AddWebsiteToUser < ActiveRecord::Migration
6
+ def self.up
7
+ add_column :users, :website, :string
8
+ end
9
+
10
+ def self.down
11
+ remove_column :users, :website
12
+ end
13
+ end
14
+
15
+ into:
16
+
17
+ migration do
18
+ def up
19
+ add_column :users, :website, :string
20
+ end
21
+
22
+ def down
23
+ remove_column :users, :website
24
+ end
25
+ end
26
+
27
+ === Extras
28
+
29
+ * Modifies the rails generator to use the slim syntax
30
+ * Helper task for converting existing migrations: rake slim_migrations:update_syntax
31
+
32
+ === Install
33
+
34
+ ==== Rails 3.1
35
+
36
+ # as plugin:
37
+ rails plugin install git://github.com/janlelis/slim_migrations.git -r 3.1
38
+ # or in Gemfile:
39
+ gem 'slim_migrations', '~> 3.1.0'
40
+
41
+ ==== Rails 3.0
42
+
43
+ # as plugin:
44
+ rails plugin install git://github.com/janlelis/slim_migrations.git -r 3.0
45
+ # or in Gemfile:
46
+ gem 'slim_migrations', '~> 3.0.0'
47
+
48
+ ==== Rails 2.3
49
+
50
+ # as plugin:
51
+ script/plugin install git://github.com/janlelis/slim_migrations.git -r 2.3
52
+ # or in config/environment.rb
53
+ config.gem 'slim_migrations', :version => '~> 2.3.0'
54
+
55
+ === Credits
56
+
57
+ Blog post: http://rbjl.net
58
+
59
+ J-_-L
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ # gem stuff
9
+ GEMSPEC = 'slim_migrations.gemspec'
10
+
11
+ def gemspec
12
+ @gemspec ||= eval(File.read(GEMSPEC), binding, GEMSPEC)
13
+ end
14
+
15
+ desc "Build the gem"
16
+ task :gem => :gemspec do
17
+ sh "gem build #{GEMSPEC}"
18
+ FileUtils.mkdir_p 'pkg'
19
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
20
+ end
21
+
22
+ desc "Install the gem locally"
23
+ task :install => :gem do
24
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
25
+ end
26
+
27
+ desc "Generate the gemspec"
28
+ task :generate do
29
+ puts gemspec.to_ruby
30
+ end
31
+
32
+ desc "Validate the gemspec"
33
+ task :gemspec do
34
+ gemspec.validate
35
+ end
@@ -0,0 +1,20 @@
1
+ class MigrationGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template "migration.rb", 'db/migrate', :assigns => get_local_assigns
5
+ end
6
+ end
7
+
8
+
9
+ private
10
+ def get_local_assigns
11
+ {}.tap do |assigns|
12
+ if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/
13
+ assigns[:migration_action] = $1
14
+ assigns[:table_name] = $2.pluralize
15
+ else
16
+ assigns[:attributes] = []
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ migration do
2
+ def up<% attributes.each do |attribute| %>
3
+ <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end -%>
4
+ <%- end %>
5
+ end
6
+
7
+ def down<% attributes.reverse.each do |attribute| %>
8
+ <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%>
9
+ <%- end %>
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'slim_migrations/version'
2
+
3
+ module SlimMigrations
4
+ end
5
+
6
+ module Kernel
7
+ private
8
+
9
+ # initialize migrations with <tt>migration do</tt> instead of <tt>class SomeMigration < ActiveRecord::Migration</tt>
10
+ def migration(&block)
11
+ if caller[0].rindex(/(?:[0-9]+)_([_a-z0-9]*).rb:\d+(?::in `.*')?$/)
12
+ m = Object.const_set $1.camelize, Class.new(ActiveRecord::Migration)
13
+ m.instance_eval(&block) # 3.0 / 2.3
14
+ else
15
+ raise ArgumentError, "Could not create migration at: #{caller[0]}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module SlimMigrations
2
+ VERSION = '2.3.0'
3
+ end
@@ -0,0 +1,14 @@
1
+ namespace :slim_migrations do
2
+ desc "Update all current old-style migrations to slim migration syntax"
3
+ task :update_syntax do
4
+ Dir["db/migrate/[0-9]*_*.rb"].each{ |migration_path|
5
+ migration_content = File.read migration_path
6
+ if migration_content =~ /^[^#]*class\s+[A-Za-z0-9_]+\s*<\s*ActiveRecord::Migration/
7
+ puts "Upgrading: #{migration_path}"
8
+ migration_content.gsub! /class\s+[A-Za-z0-9_]+\s*<\s*ActiveRecord::Migration/, 'migration do'
9
+ migration_content.gsub! /self\.(up|down)/, '\1'
10
+ File.open(migration_path, 'w') do |file| file.write migration_content end
11
+ end
12
+ }
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slim_migrations
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 2.3.0
6
+ platform: ruby
7
+ authors:
8
+ - Jan Lelis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-15 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ description: Let's you write even slimmer migrations.
28
+ email: mail@janlelis.de
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - lib/slim_migrations.rb
37
+ - lib/slim_migrations/version.rb
38
+ - lib/generators/migration/migration_generator.rb
39
+ - lib/generators/migration/templates/migration.rb
40
+ - lib/tasks/slim_migrations_tasks.rake
41
+ - MIT-LICENSE
42
+ - Rakefile
43
+ - README.rdoc
44
+ has_rdoc: true
45
+ homepage: https://github.com/janlelis/slim_migrations
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: -999369327
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: -999369327
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.6.2
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Let's you write even slimmer migrations.
78
+ test_files: []
79
+