activerecord_column_comment 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord_column_comment.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 ac
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # ActiverecordColumnComment
2
+
3
+ このgemでRails3.2以降のmigrationにおいて、カラムのオプションから `comment` を指定できます。
4
+ 普通カラムコメントは必要ないのですが(migrationファイルにrubyコメントで残せるし)、[mroonga](https://github.com/mroonga/mroonga)を使う場合、[パーサーの指定](http://mroonga.github.com/ja/docs/userguide/storage.html#how-to-specify-the-parser-for-full-text-search)がコメント経由なのでこのgemを作りました。
5
+
6
+ mysqlでしか実際に動かしてみていません。migrationを使うテストの書き方が分からず書いていません。
7
+ fork, pull request歓迎です。
8
+
9
+ This gem will let you add comments on column through options in your migration (rails >= 3.2.0).
10
+ Although comments on column are usually not necessary (you can always leave comments in your migration files, right?), I created this gem because I had to use [mroonga](https://github.com/mroonga/mroonga) and [specify parser](http://mroonga.github.com/docs/userguide/storage.html#how-to-specify-the-parser-for-full-text-search) on column.
11
+
12
+ I only ran and saw results on mysql. Since I didn't know how to write tests using migration, there are no specs/test.
13
+ forks, pull requests are very welcomed.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'activerecord_column_comment'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install activerecord_column_comment
28
+
29
+ ## Usage
30
+
31
+
32
+ ```ruby
33
+ class CreateExamples < ActiveRecord::Migration
34
+ def change
35
+ create_table :examples do |t|
36
+ t.string :name, comment: "put your comment here"
37
+ t.timestamps
38
+ end
39
+ end
40
+ end
41
+ ```
42
+
43
+ run `rake db:migrate`, open mysql console `rails dbconsole`, then do `show create table examples;` and you will get this
44
+
45
+ CREATE TABLE `examples` (
46
+ `id` int(11) NOT NULL AUTO_INCREMENT,
47
+ `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'put your comment here',
48
+ `created_at` datetime NOT NULL,
49
+ `updated_at` datetime NOT NULL,
50
+ PRIMARY KEY (`id`)
51
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
52
+
53
+ see more in examples folder
54
+
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activerecord_column_comment/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "activerecord_column_comment"
8
+ gem.version = ActiverecordColumnComment::VERSION
9
+ gem.authors = ["ac"]
10
+ gem.email = ["ac@mba.local"]
11
+ gem.description = %q{this will add an option to add column comment in sql statement on migration}
12
+ gem.summary = %q{activerecord will have commentable columns}
13
+ gem.homepage = "https://github.com/github0013/activerecord_column_comment"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'activerecord', '>= 3.2.0'
21
+ end
@@ -0,0 +1,13 @@
1
+ class AddCommentToNameOnExamples < ActiveRecord::Migration
2
+ def up
3
+ change_table :examples do |t|
4
+ t.change :name, :string, comment: "change your comment here"
5
+ end
6
+ end
7
+
8
+ def down
9
+ change_table :examples do |t|
10
+ t.change :name, :string
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class CreateExample < ActiveRecord::Migration
2
+ def change
3
+ create_table :examples do |t|
4
+ t.string :name, :comment => "put your comment here"
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ require "active_record/connection_adapters/abstract/schema_definitions"
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ class ColumnDefinition
6
+ attr_accessor :comment
7
+
8
+ def to_sql_with_comment
9
+ column_sql = to_sql_without_comment
10
+ return column_sql if comment.nil?
11
+
12
+ "#{column_sql} COMMENT '#{base.quote_string(comment)}'"
13
+ end
14
+ alias_method_chain :to_sql, :comment
15
+ end
16
+
17
+ class TableDefinition
18
+ def column_with_comment(name, type, options = {})
19
+ column_without_comment(name, type, options)
20
+ column = self[name]
21
+ column.comment = options.fetch(:comment){nil}
22
+ self
23
+ end
24
+ alias_method_chain :column, :comment
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ require "active_record/connection_adapters/abstract_mysql_adapter"
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ class AbstractMysqlAdapter
6
+ def change_column_sql_with_comment(table_name, column_name, type, options = {})
7
+ comment = options.fetch(:comment){ nil }
8
+ change_column_sql = change_column_sql_without_comment(table_name, column_name, type, options = {})
9
+ return change_column_sql if comment.nil?
10
+
11
+ "#{change_column_sql} COMMENT '#{quote_string(comment)}'"
12
+ end
13
+ alias_method_chain :change_column_sql, :comment
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require "active_record/connection_adapters/postgresql_adapter"
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ class PostgreSQLAdapter
6
+ def change_column_with_comment(table_name, column_name, type, options = {})
7
+ comment = options.fetch(:comment){ nil }
8
+ change_column_without_comment(table_name, column_name, type, options = {})
9
+ change_column_comment(table_name, column_name, comment) unless comment.nil?
10
+ end
11
+ alias_method_chain :change_column, :comment
12
+
13
+ def change_column_comment(table_name, column_name, comment)
14
+ execute "COMMENT ON COLUMN #{quote_table_name(table_name)}.#{quote_column_name(column_name)} IS '#{quote_string(comment)}'"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ require "activerecord/column_comment/version"
2
+ require "activerecord/connection_adapters/abstract/schema_definitions"
3
+ require "activerecord/connection_adapters/abstract_mysql_adapter"
@@ -0,0 +1,3 @@
1
+ module ActiverecordColumnComment
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord_column_comment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ac
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ description: this will add an option to add column comment in sql statement on migration
31
+ email:
32
+ - ac@mba.local
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - activerecord_column_comment.gemspec
43
+ - examples/comment_on_change.rb
44
+ - examples/comment_on_create.rb
45
+ - lib/activerecord/connection_adapters/abstract/schema_definitions.rb
46
+ - lib/activerecord/connection_adapters/abstract_mysql_adapter.rb
47
+ - lib/activerecord/connection_adapters/postgresql_adapter.rb
48
+ - lib/activerecord_column_comment.rb
49
+ - lib/activerecord_column_comment/version.rb
50
+ homepage: https://github.com/github0013/activerecord_column_comment
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.24
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: activerecord will have commentable columns
74
+ test_files: []