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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 420c26808e6ee7e74fbbe012b2417f175e9ebbec
4
- data.tar.gz: d3b660d302464614a81e83e8ca01f224874f6c9a
3
+ metadata.gz: 227358fd36cbff8dd8e618c8269c375f5cd2e088
4
+ data.tar.gz: f08386cfa1740cb7ab9613894663db93861ab900
5
5
  SHA512:
6
- metadata.gz: 040bc699b38ca84bf5185517c5e4bfc587672f8b1685ec95846564bcb9df3d611d9e056e2f429a70a15ee9bff4d11c204a7be990041543eeb05e5ed89f020bc7
7
- data.tar.gz: 03b950881d178c8542db3f1bae4b585ac99a9f1d8af72f99e89e98179e60082341c4db052a17fd7ee70b8a45ee8c2ebf0d2945773f3700ca4cd03260e05c1914
6
+ metadata.gz: 4c23b1fe43ac247ced6e0fed325239aefc7e4ec470541fed22190eb5bdaefe125713cd257de1ee67c6fcbb3947b2db42444b8aff0f91a84910012d62834f2a57
7
+ data.tar.gz: b03756091567bceaac45f0de10e6c1c769132352f0c04c896809780b13903f8c50dff37eeb53e81773adaf612c73459d1c7488c1522a7c5e76e329af1563a93f
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/version_tmp
16
16
  tmp
17
17
  spec/dummy
18
18
  gemfiles/*.lock
19
+ Gemfile.lock
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.1.1
9
- before_install:
10
- - bundle install --jobs=3 --retry=3
12
+ - 2.2.3
13
+ - ruby-head
14
+
11
15
  script:
12
16
  - bundle exec rake test
data/Appraisals CHANGED
@@ -5,5 +5,8 @@ appraise "rails-4.1" do
5
5
  gem "rails", "~> 4.1.0"
6
6
  end
7
7
  appraise "rails-4.2" do
8
- gem "rails", "~> 4.2.0.beta1"
8
+ gem "rails", "~> 4.2.0"
9
+ end
10
+ appraise "rails-5.0" do
11
+ gem "rails", "~> 5.0.0.beta1"
9
12
  end
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
@@ -3,6 +3,13 @@ require "bundler/gem_tasks"
3
3
  require 'rails/dummy/tasks'
4
4
 
5
5
 
6
+ class Rails::Dummy::Generator
7
+ def original_name
8
+ 'habtm_generator'
9
+ end
10
+ end
11
+
12
+
6
13
  task :clear do
7
14
  rm_rf 'spec/dummy'
8
15
  end
@@ -4,6 +4,6 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "sqlite3"
6
6
  gem "rake"
7
- gem "rails", "~> 4.2.0.beta1"
7
+ gem "rails", "~> 4.2.0"
8
8
 
9
9
  gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3"
6
+ gem "rake"
7
+ gem "rails", "~> 5.0.0.beta1"
8
+
9
+ gemspec :path => "../"
@@ -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.3"
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
- insert_into_file "app/models/#{model}.rb",
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
- sorted_models.map{|i| no_ns i.tableize}.join("_")
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).sort
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}"}.join(", ")
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.3'
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: 2014-12-03 00:00:00.000000000 Z
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.2.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