mi 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -0
- data/lib/generators/mi.rb +25 -4
- data/lib/generators/mi/create_generator.rb +2 -0
- data/lib/generators/mi/mi_generator.rb +2 -0
- data/lib/mi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de27288fe514834c187cfe245745fd890f117b1
|
4
|
+
data.tar.gz: 512d891179f0ae8e2c3582c1b15bb889ce1d9fd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e04e24948c240f8a564020499e8ba2f9f54bf9c2ba7b8c60992cb2aed940a598811a0cb4be77a9509fa06b6a32f472883b684bc64cb01c504dd4d84f96a3fb75
|
7
|
+
data.tar.gz: fa147966d9f03257db7078d734fbf2c79cf06e014bf5b5e7e1010719ec66511dd10ebe5dc194909634771bb2ee1fcd5915039dd335959017b4d971f2754e2626
|
data/README.md
CHANGED
@@ -82,6 +82,37 @@ class ChangeEmailToUsers < ActiveRecord::Migration
|
|
82
82
|
end
|
83
83
|
```
|
84
84
|
|
85
|
+
### create_table
|
86
|
+
|
87
|
+
```sh
|
88
|
+
$ bin/rails g mi:create users +email:string:{null:false} +name:string
|
89
|
+
create db/migrate/20160704144601_create_users_table.rb
|
90
|
+
```
|
91
|
+
|
92
|
+
`db/migrate/20160704144601_create_users_table.rb`
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
class CreateUsersTable < ActiveRecord::Migration
|
96
|
+
def change
|
97
|
+
create_table :users do |t|
|
98
|
+
t.string :email, null: false
|
99
|
+
t.string :name
|
100
|
+
|
101
|
+
t.timestamps null: false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
### Open with editor
|
109
|
+
|
110
|
+
Put a `--edit` option, mi opens the migration file after generated.
|
111
|
+
|
112
|
+
```sh
|
113
|
+
$ bin/rails g mi users +email:string --edit
|
114
|
+
```
|
115
|
+
|
85
116
|
## Dependencies
|
86
117
|
|
87
118
|
- Ruby 2.2 or higher
|
data/lib/generators/mi.rb
CHANGED
@@ -9,19 +9,43 @@ module Mi
|
|
9
9
|
class Base < Rails::Generators::Base
|
10
10
|
include Rails::Generators::Migration
|
11
11
|
|
12
|
+
attr_reader :arguments
|
13
|
+
|
12
14
|
def self.next_migration_number(dirname)
|
13
15
|
next_migration_number = current_migration_number(dirname) + 1
|
14
16
|
ActiveRecord::Migration.next_migration_number(next_migration_number)
|
15
17
|
end
|
16
18
|
|
19
|
+
def self.editable
|
20
|
+
define_method :edit do
|
21
|
+
if @edit
|
22
|
+
editor = ENV['EDITOR'] || 'vim'
|
23
|
+
fname = File.join('db/migrate', "#{@migration_number}_#{destination}.rb")
|
24
|
+
system(editor, fname)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
17
29
|
Methods = {
|
18
30
|
'+' => 'add_column',
|
19
31
|
'-' => 'remove_column',
|
20
32
|
'%' => 'change_column',
|
21
33
|
}.freeze
|
22
34
|
|
35
|
+
def parse_args
|
36
|
+
@arguments = @_initializer[0..1].flatten
|
37
|
+
|
38
|
+
if @arguments.delete('--version')
|
39
|
+
@version = true
|
40
|
+
end
|
41
|
+
|
42
|
+
if @arguments.delete('--edit')
|
43
|
+
@edit = true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
23
47
|
def version
|
24
|
-
if
|
48
|
+
if @version
|
25
49
|
puts Mi::VERSION
|
26
50
|
exit 0 # XXX:
|
27
51
|
end
|
@@ -30,9 +54,6 @@ module Mi
|
|
30
54
|
|
31
55
|
private
|
32
56
|
|
33
|
-
def arguments
|
34
|
-
@_initializer[0..1].flatten
|
35
|
-
end
|
36
57
|
|
37
58
|
def arg_groups
|
38
59
|
@arg_groups ||= (
|
data/lib/mi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|