habtm_generator 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +7 -3
- data/Appraisals +4 -1
- data/README.md +1 -0
- data/Rakefile +7 -0
- data/gemfiles/rails_4.2.gemfile +1 -1
- data/gemfiles/rails_5.0.gemfile +9 -0
- data/habtm_generator.gemspec +1 -2
- data/lib/generators/habtm/habtm_generator.rb +27 -7
- data/lib/generators/habtm/templates/habtm_migration.rb.erb +2 -1
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 227358fd36cbff8dd8e618c8269c375f5cd2e088
|
4
|
+
data.tar.gz: f08386cfa1740cb7ab9613894663db93861ab900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c23b1fe43ac247ced6e0fed325239aefc7e4ec470541fed22190eb5bdaefe125713cd257de1ee67c6fcbb3947b2db42444b8aff0f91a84910012d62834f2a57
|
7
|
+
data.tar.gz: b03756091567bceaac45f0de10e6c1c769132352f0c04c896809780b13903f8c50dff37eeb53e81773adaf612c73459d1c7488c1522a7c5e76e329af1563a93f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
|
2
5
|
gemfile:
|
3
6
|
- gemfiles/rails_4.0.gemfile
|
4
7
|
- gemfiles/rails_4.1.gemfile
|
5
8
|
- gemfiles/rails_4.2.gemfile
|
9
|
+
- gemfiles/rails_5.0.gemfile
|
6
10
|
|
7
11
|
rvm:
|
8
|
-
- 2.
|
9
|
-
|
10
|
-
|
12
|
+
- 2.2.3
|
13
|
+
- ruby-head
|
14
|
+
|
11
15
|
script:
|
12
16
|
- bundle exec rake test
|
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# HabtmGenerator
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/zealot128/ruby-habtm-generator.svg?branch=master)](https://travis-ci.org/zealot128/ruby-habtm-generator)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/habtm_generator.svg)](https://badge.fury.io/rb/habtm_generator)
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
data/Rakefile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED
data/habtm_generator.gemspec
CHANGED
@@ -12,10 +12,9 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.name = "habtm_generator"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "0.
|
15
|
+
gem.version = "0.4"
|
16
16
|
gem.add_dependency "activerecord"
|
17
17
|
gem.add_development_dependency 'appraisal'
|
18
|
-
gem.add_development_dependency 'rspec'
|
19
18
|
gem.add_development_dependency 'pry'
|
20
19
|
gem.add_development_dependency 'rails-dummy'
|
21
20
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
|
1
2
|
require 'rails/generators/migration'
|
2
3
|
require 'rails/generators/active_record'
|
3
4
|
class HabtmGenerator < ActiveRecord::Generators::Base
|
4
5
|
source_root File.expand_path('../templates', __FILE__)
|
5
6
|
argument :other_model, required: true,
|
6
7
|
type: :string, desc: "List both part of the habtm migration to generate the table"
|
8
|
+
class_option :convention, :type => :string, :aliases => "-c", :desc => "Table names convention. Available options are 'rails' and 'mysql_workbench'.", :default => "rails"
|
7
9
|
|
8
10
|
def create_migration_file
|
9
11
|
models.map!{|i|i.singularize}
|
@@ -24,10 +26,8 @@ class HabtmGenerator < ActiveRecord::Generators::Base
|
|
24
26
|
else
|
25
27
|
""
|
26
28
|
end
|
27
|
-
|
28
|
-
" has_and_belongs_to_many :#{no_ns other.pluralize}#{extra}\n"
|
29
|
-
after: "class #{model.camelize} < ActiveRecord::Base\n"
|
30
|
-
|
29
|
+
inject_into_class "app/models/#{model}.rb", model.camelcase,
|
30
|
+
" has_and_belongs_to_many :#{no_ns other.pluralize}#{extra}\n"
|
31
31
|
end
|
32
32
|
|
33
33
|
def no_ns(m)
|
@@ -37,8 +37,21 @@ class HabtmGenerator < ActiveRecord::Generators::Base
|
|
37
37
|
def join_table(model)
|
38
38
|
end
|
39
39
|
|
40
|
+
def coding_convention
|
41
|
+
options[:convention].to_s
|
42
|
+
end
|
43
|
+
|
40
44
|
def table_name
|
41
|
-
|
45
|
+
junction_string = ''
|
46
|
+
|
47
|
+
case coding_convention
|
48
|
+
when 'mysql_workbench'
|
49
|
+
junction_string = '_has_'
|
50
|
+
else
|
51
|
+
junction_string = '_'
|
52
|
+
end
|
53
|
+
|
54
|
+
sorted_models.map{|i| no_ns i.tableize}.join(junction_string)
|
42
55
|
end
|
43
56
|
|
44
57
|
def models
|
@@ -46,11 +59,18 @@ class HabtmGenerator < ActiveRecord::Generators::Base
|
|
46
59
|
end
|
47
60
|
|
48
61
|
def sorted_models
|
49
|
-
models.map(&:singularize).map(&:underscore)
|
62
|
+
ret = models.map(&:singularize).map(&:underscore)
|
63
|
+
|
64
|
+
case coding_convention
|
65
|
+
when 'mysql_workbench'
|
66
|
+
ret
|
67
|
+
else
|
68
|
+
ret.sort
|
69
|
+
end
|
50
70
|
end
|
51
71
|
|
52
72
|
def references
|
53
|
-
sorted_models.map{|i| ":#{no_ns i.singularize}"}
|
73
|
+
sorted_models.map{|i| ":#{no_ns i.singularize}"}
|
54
74
|
end
|
55
75
|
|
56
76
|
def id_columns
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :<%= table_name %>, :id => false do |t|
|
4
|
-
t.references <%= references %>
|
4
|
+
t.references <%= references[0] %>
|
5
|
+
t.references <%= references[1] %>
|
5
6
|
end
|
6
7
|
|
7
8
|
add_index :<%= table_name %>, [<%=id_columns %>],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: habtm_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Wienert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: pry
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,6 +84,7 @@ files:
|
|
98
84
|
- gemfiles/rails_4.0.gemfile
|
99
85
|
- gemfiles/rails_4.1.gemfile
|
100
86
|
- gemfiles/rails_4.2.gemfile
|
87
|
+
- gemfiles/rails_5.0.gemfile
|
101
88
|
- habtm_generator.gemspec
|
102
89
|
- lib/generators/habtm/USAGE
|
103
90
|
- lib/generators/habtm/habtm_generator.rb
|
@@ -124,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
111
|
version: '0'
|
125
112
|
requirements: []
|
126
113
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.4.8
|
128
115
|
signing_key:
|
129
116
|
specification_version: 4
|
130
117
|
summary: Generates has-and-belongs-to-many migrations. Use rails generate habtm model1
|