rails_modular_migration 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 076d34bfed46c020e9e98abb91378b146e386b833c0af0f31c9dd9a6c1461e90
4
+ data.tar.gz: 0edc079db7d4d9b41ff0b05caf28565d49dd8f6baec9fe71a680e38f0d487019
5
+ SHA512:
6
+ metadata.gz: 21f04b40d20c433d83b261460448da9bee1fdd7cfd21a7748ef796f0a20dbb8c808a7d13185aa6d57745dc0844fe02decfa9f25b0097f5aebf13ff4d6e2298cc
7
+ data.tar.gz: 455ef9bed89edda0bedfb4d841737c99a90c4002c1ca47a3b1dba13a3138c10972dc8e522f9e9f6dce422bf9e0517680e8b39f7d69eae8bc0e26fc8383d42b12
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sassc
4
+ .sass-cache
5
+ capybara-*.html
6
+ .rspec
7
+ .rvmrc
8
+ /.bundle
9
+ /vendor/bundle
10
+ /log/*
11
+ /tmp/*
12
+ /db/*.sqlite3
13
+ /public/system/*
14
+ /coverage/
15
+ /spec/tmp/*
16
+ **.orig
17
+ Gemfile.lock
18
+ rerun.txt
19
+ pickle-email-*.html
20
+ .project
21
+ config/initializers/secret_token.rb
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tony
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,52 @@
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 ~> 3.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
+ - [swordray](https://github.com/swordray) @[ihaveu](http://www.ihaveu.com/home) @[shuhai](http://tw.shuhai.org/) @[leaf](http://leaf.iacger.com)
49
+
50
+ ## License
51
+
52
+ Copyright © 2014 Lijia Tong <user_tony@163.com> under The [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ task :default do |t|
2
+ `gem build modular_migration.gemspec`
3
+ end
@@ -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! if self.respond_to?(:validate_file_name)
8
+ if migration_action && 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 && migration_action.match(/join/)
24
+ FileUtils.mkdir_p(File.join("db", "migrate", migration)) if migration
25
+ migration_file = File.join("db", "migrate", migration||"", "#{file_name}.rb")
26
+ template_file = Rails.version.to_i < 4 ? 'migration.rb' : @migration_template
27
+ migration_template template_file, migration_file
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ module ActiveRecord
2
+ module Generators # :nodoc:
3
+ class ModelGenerator < Base # :nodoc:
4
+
5
+ class_option :migration, type: :boolean, default: true
6
+ class_option :timestamps, type: :boolean, default: true
7
+
8
+ def create_migration_file
9
+ return unless options[:migration] && options[:parent].nil?
10
+ attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
11
+ template_file = Rails.version.to_i < 4 ? 'migration.rb' : '../../migration/templates/create_table_migration.rb'
12
+ migration_file = File.join(FileUtils.mkdir_p(File.join('db/migrate', class_path.join('/'), file_name)), "/create_#{table_name}.rb")
13
+ migration_template template_file, migration_file
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module ModularMigration
2
+ VERSION = '1.0.0'
3
+ 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 = "rails_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 = "~> 3.0"
21
+ s.add_dependency 'rails'
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_modular_migration
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Lijia Tong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-06 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: '3.0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.2.15
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Rails migration files generates into relevant modular directory
68
+ test_files: []