slim_migrations 2.3.1 → 3.0.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 +1 -1
- data/README.rdoc +13 -18
- data/lib/rails/generators/active_record/migration/migration_generator.rb +25 -0
- data/lib/{generators → rails/generators/active_record}/migration/templates/migration.rb +12 -6
- data/lib/slim_migrations/version.rb +1 -1
- data/lib/slim_migrations.rb +7 -4
- metadata +39 -31
- data/lib/generators/migration/migration_generator.rb +0 -20
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ Turns
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
into
|
15
|
+
into:
|
16
16
|
|
17
17
|
migration do
|
18
18
|
def up
|
@@ -31,36 +31,31 @@ into
|
|
31
31
|
|
32
32
|
=== Install
|
33
33
|
|
34
|
-
==== Rails 3.2
|
35
|
-
|
36
|
-
# in your Gemfile
|
37
|
-
gem 'slim_migrations', '~> 3.2.1'
|
38
|
-
|
39
34
|
==== Rails 3.1
|
40
35
|
|
41
36
|
# as plugin:
|
42
|
-
rails plugin install
|
43
|
-
# or in
|
44
|
-
gem 'slim_migrations', '~> 3.1.
|
37
|
+
rails plugin install https://github.com/janlelis/slim_migrations.git, :branch => 3.1
|
38
|
+
# or in Gemfile:
|
39
|
+
gem 'slim_migrations', '~> 3.1.0'
|
45
40
|
|
46
41
|
==== Rails 3.0
|
47
42
|
|
48
43
|
# as plugin:
|
49
|
-
rails plugin install
|
50
|
-
# or in
|
51
|
-
gem 'slim_migrations', '~> 3.0.
|
44
|
+
rails plugin install https://github.com/janlelis/slim_migrations.git, :branch => 3.0
|
45
|
+
# or in Gemfile:
|
46
|
+
gem 'slim_migrations', '~> 3.0.0'
|
52
47
|
|
53
48
|
==== Rails 2.3
|
54
49
|
|
55
50
|
# as plugin:
|
56
|
-
|
57
|
-
# or in
|
58
|
-
|
51
|
+
rails plugin install https://github.com/janlelis/slim_migrations.git, :branch => 2.3
|
52
|
+
# or in Gemfile:
|
53
|
+
gem 'slim_migrations', '~> 2.3.0'
|
59
54
|
|
60
55
|
=== Credits
|
61
56
|
|
62
|
-
|
57
|
+
This project rocks and uses MIT-LICENSE.
|
63
58
|
|
64
|
-
|
59
|
+
Blog post: http://rbjl.net
|
65
60
|
|
66
|
-
|
61
|
+
J-_-L
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Generators
|
5
|
+
class MigrationGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
|
8
|
+
def create_migration_file
|
9
|
+
set_local_assigns!
|
10
|
+
migration_template File.dirname(__FILE__) + "/templates/migration.rb", "db/migrate/#{file_name}.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
attr_reader :migration_action
|
15
|
+
|
16
|
+
def set_local_assigns!
|
17
|
+
if file_name =~ /^(add|remove)_.*_(?:to|from)_(.*)/
|
18
|
+
@migration_action = $1
|
19
|
+
@table_name = $2.pluralize
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,11 +1,17 @@
|
|
1
1
|
migration do
|
2
|
-
def up
|
3
|
-
|
4
|
-
<%-
|
2
|
+
def up
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
<%- if migration_action -%>
|
5
|
+
<%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end %>
|
6
|
+
<%- end -%>
|
7
|
+
<%- end -%>
|
5
8
|
end
|
6
9
|
|
7
|
-
def down
|
8
|
-
|
9
|
-
<%-
|
10
|
+
def down
|
11
|
+
<% attributes.reverse.each do |attribute| -%>
|
12
|
+
<%- if migration_action -%>
|
13
|
+
<%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end %>
|
14
|
+
<%- end -%>
|
15
|
+
<%- end -%>
|
10
16
|
end
|
11
17
|
end
|
data/lib/slim_migrations.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
require 'slim_migrations/version'
|
2
|
-
|
3
1
|
module SlimMigrations
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
rake_tasks do
|
4
|
+
load "tasks/slim_migrations_tasks.rake"
|
5
|
+
end
|
6
|
+
end
|
4
7
|
end
|
5
8
|
|
6
9
|
module Kernel
|
@@ -8,9 +11,9 @@ module Kernel
|
|
8
11
|
|
9
12
|
# initialize migrations with <tt>migration do</tt> instead of <tt>class SomeMigration < ActiveRecord::Migration</tt>
|
10
13
|
def migration(&block)
|
11
|
-
if caller[0].rindex(
|
14
|
+
if caller[0].rindex(/(?:[0-9]+)_([_a-z0-9]*).rb:\d+(?::in `.*')?$/)
|
12
15
|
m = Object.const_set $1.camelize, Class.new(ActiveRecord::Migration)
|
13
|
-
m.instance_eval(&block) # 3.0
|
16
|
+
m.instance_eval(&block) # 3.0
|
14
17
|
else
|
15
18
|
raise ArgumentError, "Could not create migration at: #{caller[0]}"
|
16
19
|
end
|
metadata
CHANGED
@@ -1,69 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim_migrations
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.1
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 3.0.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Jan Lelis
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2011-07-15 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: rails
|
16
|
-
requirement: &
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
|
-
requirements:
|
19
|
+
requirements:
|
19
20
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
+
version_requirements: *id001
|
25
26
|
description: Let's you write even slimmer migrations.
|
26
27
|
email: mail@janlelis.de
|
27
28
|
executables: []
|
29
|
+
|
28
30
|
extensions: []
|
31
|
+
|
29
32
|
extra_rdoc_files: []
|
30
|
-
|
33
|
+
|
34
|
+
files:
|
31
35
|
- lib/slim_migrations.rb
|
32
36
|
- lib/slim_migrations/version.rb
|
37
|
+
- lib/rails/generators/active_record/migration/migration_generator.rb
|
38
|
+
- lib/rails/generators/active_record/migration/templates/migration.rb
|
33
39
|
- lib/tasks/slim_migrations_tasks.rake
|
34
|
-
- lib/generators/migration/templates/migration.rb
|
35
|
-
- lib/generators/migration/migration_generator.rb
|
36
40
|
- MIT-LICENSE
|
37
41
|
- Rakefile
|
38
42
|
- README.rdoc
|
39
43
|
homepage: https://github.com/janlelis/slim_migrations
|
40
44
|
licenses: []
|
45
|
+
|
41
46
|
post_install_message:
|
42
47
|
rdoc_options: []
|
43
|
-
|
48
|
+
|
49
|
+
require_paths:
|
44
50
|
- lib
|
45
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
52
|
none: false
|
47
|
-
requirements:
|
48
|
-
- -
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
|
51
|
-
segments:
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 647847149
|
57
|
+
segments:
|
52
58
|
- 0
|
53
|
-
|
54
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
61
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
segments:
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 647847149
|
66
|
+
segments:
|
61
67
|
- 0
|
62
|
-
|
68
|
+
version: "0"
|
63
69
|
requirements: []
|
70
|
+
|
64
71
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.1
|
66
73
|
signing_key:
|
67
74
|
specification_version: 3
|
68
75
|
summary: Let's you write even slimmer migrations.
|
69
76
|
test_files: []
|
77
|
+
|
@@ -1,20 +0,0 @@
|
|
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
|