slim_migrations 3.2.0 → 3.2.1

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.
@@ -1,4 +1,4 @@
1
- Copyright 2011 Jan Lelis
1
+ Copyright 2011-2012 Jan Lelis
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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,29 +31,36 @@ 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
+
34
39
  ==== Rails 3.1
35
40
 
36
41
  # as plugin:
37
42
  rails plugin install git://github.com/janlelis/slim_migrations.git -r 3.1
38
- # or in Gemfile:
39
- gem 'slim_migrations', '~> 3.1.0'
43
+ # or in your Gemfile:
44
+ gem 'slim_migrations', '~> 3.1.1'
40
45
 
41
46
  ==== Rails 3.0
42
47
 
43
48
  # as plugin:
44
49
  rails plugin install git://github.com/janlelis/slim_migrations.git -r 3.0
45
- # or in Gemfile:
46
- gem 'slim_migrations', '~> 3.0.0'
50
+ # or in your Gemfile:
51
+ gem 'slim_migrations', '~> 3.0.1'
47
52
 
48
53
  ==== Rails 2.3
49
54
 
50
55
  # as plugin:
51
56
  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'
57
+ # or in your config/environment.rb
58
+ config.gem 'slim_migrations', :version => '~> 2.3.1'
54
59
 
55
60
  === Credits
56
61
 
57
- Blog post: http://rbjl.net
62
+ Blog post: http://rbjl.net/53-three-little-tips-for-slimmer-rails-migrations
63
+
64
+ Thanks to contributions from: Manuel Meurer
58
65
 
59
- J-_-L
66
+ MIT-LICENSE, J-_-L
@@ -3,11 +3,11 @@ require 'rails/generators/active_record'
3
3
  module ActiveRecord
4
4
  module Generators
5
5
  class MigrationGenerator < Base
6
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
6
+ argument :attributes, :type => :array, :default => [], :banner => "field[:type][:index] field[:type][:index]"
7
7
 
8
8
  def create_migration_file
9
9
  set_local_assigns!
10
- migration_template File.dirname(__FILE__) + "/templates/migration.rb", "db/migrate/#{file_name}.rb"
10
+ migration_template "migration.rb", "db/migrate/#{file_name}.rb"
11
11
  end
12
12
 
13
13
  protected
@@ -16,7 +16,7 @@ module ActiveRecord
16
16
  def set_local_assigns!
17
17
  if file_name =~ /^(add|remove)_.*_(?:to|from)_(.*)/
18
18
  @migration_action = $1
19
- @table_name = $2.pluralize
19
+ @table_name = $2.pluralize
20
20
  end
21
21
  end
22
22
 
@@ -2,14 +2,20 @@ migration do
2
2
  <%- if migration_action == 'add' -%>
3
3
  def change
4
4
  <% attributes.each do |attribute| -%>
5
- add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %>
5
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
6
+ <%- if attribute.has_index? -%>
7
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
8
+ <%- end %>
6
9
  <%- end -%>
7
10
  end
8
11
  <%- else -%>
9
12
  def up
10
13
  <% attributes.each do |attribute| -%>
11
14
  <%- if migration_action -%>
12
- <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end %>
15
+ <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><%= attribute.inject_options %><% end %>
16
+ <% if attribute.has_index? && migration_action == 'add' %>
17
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
18
+ <% end -%>
13
19
  <%- end -%>
14
20
  <%- end -%>
15
21
  end
@@ -17,7 +23,7 @@ migration do
17
23
  def down
18
24
  <% attributes.reverse.each do |attribute| -%>
19
25
  <%- if migration_action -%>
20
- <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end %>
26
+ <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><%= attribute.inject_options %><% end %>
21
27
  <%- end -%>
22
28
  <%- end -%>
23
29
  end
@@ -13,7 +13,7 @@ module Kernel
13
13
 
14
14
  # initialize migrations with <tt>migration do</tt> instead of <tt>class SomeMigration < ActiveRecord::Migration</tt>
15
15
  def migration(&block)
16
- if caller[0].rindex(/(?:[0-9]+)_([_a-z0-9]*).rb:\d+(?::in `.*')?$/)
16
+ if caller[0].rindex(/\/(?:[0-9]+)_([_a-z0-9]*).rb:\d+(?::in `.*')?$/)
17
17
  m = Object.const_set $1.camelize, Class.new(ActiveRecord::Migration)
18
18
  m.class_eval(&block) # 3.1
19
19
  else
@@ -1,3 +1,3 @@
1
1
  module SlimMigrations
2
- VERSION = '3.2.0'
2
+ VERSION = '3.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-04 00:00:00.000000000Z
12
+ date: 2012-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &25448980 !ruby/object:Gem::Requirement
16
+ requirement: &8317800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.0.rc1
21
+ version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *25448980
24
+ version_requirements: *8317800
25
25
  description: Let's you write even slimmer migrations.
26
26
  email: mail@janlelis.de
27
27
  executables: []
@@ -50,7 +50,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  segments:
52
52
  - 0
53
- hash: -3511577405469603588
53
+ hash: 1305657415440073261
54
54
  required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  none: false
56
56
  requirements:
@@ -59,10 +59,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  segments:
61
61
  - 0
62
- hash: -3511577405469603588
62
+ hash: 1305657415440073261
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 1.8.12
65
+ rubygems_version: 1.8.11
66
66
  signing_key:
67
67
  specification_version: 3
68
68
  summary: Let's you write even slimmer migrations.