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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5533081b911650aae4e4bf66883993171d4e7d1
4
- data.tar.gz: 73392df3edede1d9cdf83352cddc404fc5c5cad0
3
+ metadata.gz: 1de27288fe514834c187cfe245745fd890f117b1
4
+ data.tar.gz: 512d891179f0ae8e2c3582c1b15bb889ce1d9fd1
5
5
  SHA512:
6
- metadata.gz: b3e48cdf0545ea2e6f3f6c6869068819c94a59604f0b568cae34b79441fb282810f0b18bd3bafff297c375df813ba607a73b8043a8e9febedfe55d0a7ed5ab61
7
- data.tar.gz: ae694398b415e948f5accf23f7f7e4c7a4a8030db5f0019951611aca4f90cc14dc27b3016273bd5d23197b2022f4c2acae3c89aa772d20bb5fed0806194a6191
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
@@ -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 arguments.include?('--version')
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 ||= (
@@ -12,6 +12,8 @@ module Mi
12
12
  migration_template('create.rb.erb', "db/migrate/#{destination}.rb")
13
13
  end
14
14
 
15
+ editable
16
+
15
17
 
16
18
  private
17
19
 
@@ -10,6 +10,8 @@ module Mi
10
10
  migration_template('migration.rb.erb', "db/migrate/#{destination}.rb")
11
11
  end
12
12
 
13
+ editable
14
+
13
15
 
14
16
  private
15
17
 
@@ -1,3 +1,3 @@
1
1
  module Mi
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.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-03 00:00:00.000000000 Z
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails