modular_migration 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +2 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +51 -0
- data/Rakefile +3 -0
- data/lib/modular_migration.rb +6 -0
- data/lib/modular_migration/active_record/generators/migration_generator.rb +32 -0
- data/lib/modular_migration/active_record/generators/model_generator.rb +13 -0
- data/lib/modular_migration/version.rb +3 -0
- data/modular_migration.gemspec +23 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dad44a44d746cf519ad87588ea91161ceaa60f2d
|
4
|
+
data.tar.gz: e32665277e66ad53fcbd03989bf5ff6dab78ba81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a80163ed27e68b871505d9a92748befaeedd9529278397ddd3b9208f79182f3c82014f412a35b83dbd1331b3adbf9d9b41a4b66a68ccc37e568d700bcc14005
|
7
|
+
data.tar.gz: 009eb782e11eb6a4707ab025683812c4bae16101ce9ebfe5a4a5f2f90d0c746c48dbfbf097e5893884aad5ac2de71857c6a2a44172d71645fb629354e7468d87
|
data/.gitignore
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
*.rbc
|
2
|
+
*.sassc
|
3
|
+
.sass-cache
|
4
|
+
capybara-*.html
|
5
|
+
.rspec
|
6
|
+
.rvmrc
|
7
|
+
/.bundle
|
8
|
+
/vendor/bundle
|
9
|
+
/log/*
|
10
|
+
/tmp/*
|
11
|
+
/db/*.sqlite3
|
12
|
+
/public/system/*
|
13
|
+
/coverage/
|
14
|
+
/spec/tmp/*
|
15
|
+
**.orig
|
16
|
+
rerun.txt
|
17
|
+
pickle-email-*.html
|
18
|
+
.project
|
19
|
+
config/initializers/secret_token.rb
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 艾小童
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# modular_migration
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/modular_migration.png)](http://badge.fury.io/rb/modular_migration) [![Build Status](https://secure.travis-ci.org/swordray/modular_migration.png?branch=master)](http://travis-ci.org/swordray/modular_migration)
|
3
|
+
[![DependencyStatus](https://gemnasium.com/swordray/modular_migration.png?travis)](https://gemnasium.com/swordray/modular_migration)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/swordray/modular_migration.png)](https://codeclimate.com/github/swordray/modular_migration)
|
5
|
+
|
6
|
+
Rails migration files generates into relevant modular directory
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
* Ruby ~> 2.0
|
11
|
+
* Rails
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Include the gem in your Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'modular_migration'
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Do nothing.
|
24
|
+
|
25
|
+
## Example
|
26
|
+
|
27
|
+
- Generate model
|
28
|
+
|
29
|
+
```bash
|
30
|
+
$ rails g model core/user name:string
|
31
|
+
invoke active_record
|
32
|
+
create app/models/core/user.rb
|
33
|
+
create app/models/core.rb
|
34
|
+
create db/migrate/core/user/20140324105328_create_core_users.rb
|
35
|
+
```
|
36
|
+
|
37
|
+
- Generate migration
|
38
|
+
|
39
|
+
```bash
|
40
|
+
$ rails g migration AddGenderToCoreUser gender:integer
|
41
|
+
invoke active_record
|
42
|
+
create db/migrate/core/user/20140324105719_add_gender_to_core_user.rb
|
43
|
+
```
|
44
|
+
|
45
|
+
## Credits
|
46
|
+
|
47
|
+
- [LiJia.Tong](https://github.com/user-tony/) @[Ihaveu](https://www.ihaveu.com/home)
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
Copyright © 2014 Lijia Tong <user_tony@163.com> under The [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
require 'rails/generators/active_record/model/model_generator'
|
4
|
+
require 'rails/generators/active_record/migration/migration_generator'
|
5
|
+
require 'modular_migration/active_record/generators/model_generator'
|
6
|
+
require 'modular_migration/active_record/generators/migration_generator'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Generators # :nodoc:
|
3
|
+
class MigrationGenerator < Base # :nodoc:
|
4
|
+
|
5
|
+
def create_migration_file
|
6
|
+
set_local_assigns!
|
7
|
+
validate_file_name!
|
8
|
+
if migration_action.match(/(add|remove)/)
|
9
|
+
table = table_name.singularize
|
10
|
+
modular = table.gsub(/_/, '/').camelize.safe_constantize
|
11
|
+
table = table.split('_')
|
12
|
+
(table.size-1).times do |i|
|
13
|
+
result = []
|
14
|
+
table.each_with_index do |m, index|
|
15
|
+
result << m
|
16
|
+
result << (index == i ? '_' : '/') if index < table.size-1
|
17
|
+
modular = result.join.camelize.safe_constantize if index == table.size-1
|
18
|
+
end
|
19
|
+
break if modular
|
20
|
+
end unless modular
|
21
|
+
migration = modular ? modular.to_s.underscore : []
|
22
|
+
end
|
23
|
+
migration = join_tables.map(&:singularize).join('_') if migration_action.match(/join/)
|
24
|
+
migration = FileUtils.mkdir_p("db/migrate/#{migration}") if migration
|
25
|
+
migration_file = File.join(migration.join('/'), "#{file_name}.rb")
|
26
|
+
migration_template @migration_template, migration_file
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Generators # :nodoc:
|
3
|
+
class ModelGenerator < Base # :nodoc:
|
4
|
+
|
5
|
+
def create_modular_migration_file
|
6
|
+
template_file = Rails.version.to_i < 4 ? 'migration.rb' : '../../migration/templates/create_table_migration.rb'
|
7
|
+
migration_file = File.join(FileUtils.mkdir_p(File.join('db/migrate', class_path.join('/'), file_name)), "/create_#{table_name}.rb")
|
8
|
+
migration_template template_file, migration_file
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'modular_migration/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "modular_migration"
|
6
|
+
s.version = ModularMigration::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = ['Lijia Tong']
|
9
|
+
s.email = ["user_tony@163.com"]
|
10
|
+
s.homepage = "https://github.com/user-tony/modular_migration"
|
11
|
+
s.summary = "Rails migration files generates into relevant modular directory"
|
12
|
+
s.description = "Rails migration files generates into relevant modular directory."
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = %w[lib]
|
19
|
+
|
20
|
+
s.required_ruby_version = "~> 2.0"
|
21
|
+
s.add_dependency 'rails'
|
22
|
+
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: modular_migration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lijia Tong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Rails migration files generates into relevant modular directory.
|
28
|
+
email:
|
29
|
+
- user_tony@163.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".travis.yml"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/modular_migration.rb
|
41
|
+
- lib/modular_migration/active_record/generators/migration_generator.rb
|
42
|
+
- lib/modular_migration/active_record/generators/model_generator.rb
|
43
|
+
- lib/modular_migration/version.rb
|
44
|
+
- modular_migration.gemspec
|
45
|
+
homepage: https://github.com/user-tony/modular_migration
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.2.2
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Rails migration files generates into relevant modular directory
|
69
|
+
test_files: []
|