schema_comments 0.1.4 → 0.2.0.alpha1
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/Gemfile +23 -0
 - data/Gemfile.lock +125 -0
 - data/README.rdoc +9 -10
 - data/Rakefile +31 -37
 - data/VERSION +1 -1
 - data/lib/annotate_models.rb +27 -25
 - data/lib/hash_key_orderable.rb +1 -1
 - data/lib/schema_comments/base.rb +9 -9
 - data/lib/schema_comments/connection_adapters.rb +13 -8
 - data/lib/schema_comments/migration.rb +2 -2
 - data/lib/schema_comments/migrator.rb +2 -2
 - data/lib/schema_comments/schema.rb +1 -1
 - data/lib/schema_comments/schema_comment.rb +10 -10
 - data/lib/schema_comments/schema_dumper.rb +15 -15
 - data/lib/schema_comments.rb +9 -7
 - data/schema_comments.gemspec +94 -98
 - data/spec/annotate_models_spec.rb +3 -3
 - data/spec/fake_app.rb +17 -0
 - data/spec/hash_key_orderable_spec.rb +1 -1
 - data/spec/i18n_export_spec.rb +7 -7
 - data/spec/migrations/valid/001_create_products.rb +1 -1
 - data/spec/schema_comments/connection_adapters_spec.rb +7 -7
 - data/spec/schema_comments/schema_comment_spec.rb +4 -4
 - data/spec/schema_comments/schema_comments.yml +3 -2
 - data/spec/schema_comments/schema_dumper_spec.rb +11 -9
 - data/spec/spec_helper.rb +27 -38
 - data/spec/yaml_export_spec.rb +10 -10
 - metadata +134 -52
 - data/.gitignore +0 -5
 
    
        data/Gemfile
    ADDED
    
    | 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            source "http://rubygems.org"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            gem "activesupport", "~> 3.1.0"
         
     | 
| 
      
 4 
     | 
    
         
            +
            gem "activerecord", "~> 3.1.0"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            group :test do
         
     | 
| 
      
 8 
     | 
    
         
            +
              gem "rails", "~> 3.1.0"
         
     | 
| 
      
 9 
     | 
    
         
            +
              gem "sqlite3"
         
     | 
| 
      
 10 
     | 
    
         
            +
              gem "yaml_waml"
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            # Add dependencies to develop your gem here.
         
     | 
| 
      
 14 
     | 
    
         
            +
            # Include everything needed to run rake, tests, features, etc.
         
     | 
| 
      
 15 
     | 
    
         
            +
            group :development do
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem "rspec", "~> 2.8.0"
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem "rspec-rails", "~> 2.8.1"
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem "yard", "~> 0.7"
         
     | 
| 
      
 19 
     | 
    
         
            +
              gem "rdoc", "~> 3.12"
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem "bundler", "~> 1.0.0"
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem "jeweler", "~> 1.8.3"
         
     | 
| 
      
 22 
     | 
    
         
            +
              gem "simplecov", ">= 0"
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
    
        data/Gemfile.lock
    ADDED
    
    | 
         @@ -0,0 +1,125 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            GEM
         
     | 
| 
      
 2 
     | 
    
         
            +
              remote: http://rubygems.org/
         
     | 
| 
      
 3 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 4 
     | 
    
         
            +
                actionmailer (3.1.4)
         
     | 
| 
      
 5 
     | 
    
         
            +
                  actionpack (= 3.1.4)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  mail (~> 2.3.0)
         
     | 
| 
      
 7 
     | 
    
         
            +
                actionpack (3.1.4)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  activemodel (= 3.1.4)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  activesupport (= 3.1.4)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  builder (~> 3.0.0)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  erubis (~> 2.7.0)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  i18n (~> 0.6)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  rack (~> 1.3.6)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  rack-cache (~> 1.1)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  rack-mount (~> 0.8.2)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  rack-test (~> 0.6.1)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  sprockets (~> 2.0.3)
         
     | 
| 
      
 18 
     | 
    
         
            +
                activemodel (3.1.4)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  activesupport (= 3.1.4)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  builder (~> 3.0.0)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  i18n (~> 0.6)
         
     | 
| 
      
 22 
     | 
    
         
            +
                activerecord (3.1.4)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  activemodel (= 3.1.4)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  activesupport (= 3.1.4)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  arel (~> 2.2.3)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  tzinfo (~> 0.3.29)
         
     | 
| 
      
 27 
     | 
    
         
            +
                activeresource (3.1.4)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  activemodel (= 3.1.4)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  activesupport (= 3.1.4)
         
     | 
| 
      
 30 
     | 
    
         
            +
                activesupport (3.1.4)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  multi_json (~> 1.0)
         
     | 
| 
      
 32 
     | 
    
         
            +
                arel (2.2.3)
         
     | 
| 
      
 33 
     | 
    
         
            +
                builder (3.0.0)
         
     | 
| 
      
 34 
     | 
    
         
            +
                diff-lcs (1.1.3)
         
     | 
| 
      
 35 
     | 
    
         
            +
                erubis (2.7.0)
         
     | 
| 
      
 36 
     | 
    
         
            +
                git (1.2.5)
         
     | 
| 
      
 37 
     | 
    
         
            +
                hike (1.2.1)
         
     | 
| 
      
 38 
     | 
    
         
            +
                i18n (0.6.0)
         
     | 
| 
      
 39 
     | 
    
         
            +
                jeweler (1.8.3)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  bundler (~> 1.0)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  git (>= 1.2.5)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  rake
         
     | 
| 
      
 43 
     | 
    
         
            +
                  rdoc
         
     | 
| 
      
 44 
     | 
    
         
            +
                json (1.6.6)
         
     | 
| 
      
 45 
     | 
    
         
            +
                mail (2.3.3)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  i18n (>= 0.4.0)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  mime-types (~> 1.16)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  treetop (~> 1.4.8)
         
     | 
| 
      
 49 
     | 
    
         
            +
                mime-types (1.18)
         
     | 
| 
      
 50 
     | 
    
         
            +
                multi_json (1.2.0)
         
     | 
| 
      
 51 
     | 
    
         
            +
                polyglot (0.3.3)
         
     | 
| 
      
 52 
     | 
    
         
            +
                rack (1.3.6)
         
     | 
| 
      
 53 
     | 
    
         
            +
                rack-cache (1.2)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  rack (>= 0.4)
         
     | 
| 
      
 55 
     | 
    
         
            +
                rack-mount (0.8.3)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  rack (>= 1.0.0)
         
     | 
| 
      
 57 
     | 
    
         
            +
                rack-ssl (1.3.2)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  rack
         
     | 
| 
      
 59 
     | 
    
         
            +
                rack-test (0.6.1)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  rack (>= 1.0)
         
     | 
| 
      
 61 
     | 
    
         
            +
                rails (3.1.4)
         
     | 
| 
      
 62 
     | 
    
         
            +
                  actionmailer (= 3.1.4)
         
     | 
| 
      
 63 
     | 
    
         
            +
                  actionpack (= 3.1.4)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  activerecord (= 3.1.4)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  activeresource (= 3.1.4)
         
     | 
| 
      
 66 
     | 
    
         
            +
                  activesupport (= 3.1.4)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  bundler (~> 1.0)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  railties (= 3.1.4)
         
     | 
| 
      
 69 
     | 
    
         
            +
                railties (3.1.4)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  actionpack (= 3.1.4)
         
     | 
| 
      
 71 
     | 
    
         
            +
                  activesupport (= 3.1.4)
         
     | 
| 
      
 72 
     | 
    
         
            +
                  rack-ssl (~> 1.3.2)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  rake (>= 0.8.7)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  rdoc (~> 3.4)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  thor (~> 0.14.6)
         
     | 
| 
      
 76 
     | 
    
         
            +
                rake (0.9.2.2)
         
     | 
| 
      
 77 
     | 
    
         
            +
                rdoc (3.12)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  json (~> 1.4)
         
     | 
| 
      
 79 
     | 
    
         
            +
                rspec (2.8.0)
         
     | 
| 
      
 80 
     | 
    
         
            +
                  rspec-core (~> 2.8.0)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  rspec-expectations (~> 2.8.0)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  rspec-mocks (~> 2.8.0)
         
     | 
| 
      
 83 
     | 
    
         
            +
                rspec-core (2.8.0)
         
     | 
| 
      
 84 
     | 
    
         
            +
                rspec-expectations (2.8.0)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  diff-lcs (~> 1.1.2)
         
     | 
| 
      
 86 
     | 
    
         
            +
                rspec-mocks (2.8.0)
         
     | 
| 
      
 87 
     | 
    
         
            +
                rspec-rails (2.8.1)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  actionpack (>= 3.0)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  activesupport (>= 3.0)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  railties (>= 3.0)
         
     | 
| 
      
 91 
     | 
    
         
            +
                  rspec (~> 2.8.0)
         
     | 
| 
      
 92 
     | 
    
         
            +
                simplecov (0.6.1)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  multi_json (~> 1.0)
         
     | 
| 
      
 94 
     | 
    
         
            +
                  simplecov-html (~> 0.5.3)
         
     | 
| 
      
 95 
     | 
    
         
            +
                simplecov-html (0.5.3)
         
     | 
| 
      
 96 
     | 
    
         
            +
                sprockets (2.0.3)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  hike (~> 1.2)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  rack (~> 1.0)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  tilt (~> 1.1, != 1.3.0)
         
     | 
| 
      
 100 
     | 
    
         
            +
                sqlite3 (1.3.5)
         
     | 
| 
      
 101 
     | 
    
         
            +
                thor (0.14.6)
         
     | 
| 
      
 102 
     | 
    
         
            +
                tilt (1.3.3)
         
     | 
| 
      
 103 
     | 
    
         
            +
                treetop (1.4.10)
         
     | 
| 
      
 104 
     | 
    
         
            +
                  polyglot
         
     | 
| 
      
 105 
     | 
    
         
            +
                  polyglot (>= 0.3.1)
         
     | 
| 
      
 106 
     | 
    
         
            +
                tzinfo (0.3.33)
         
     | 
| 
      
 107 
     | 
    
         
            +
                yaml_waml (0.3.0)
         
     | 
| 
      
 108 
     | 
    
         
            +
                yard (0.7.5)
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
            PLATFORMS
         
     | 
| 
      
 111 
     | 
    
         
            +
              ruby
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            DEPENDENCIES
         
     | 
| 
      
 114 
     | 
    
         
            +
              activerecord (~> 3.1.0)
         
     | 
| 
      
 115 
     | 
    
         
            +
              activesupport (~> 3.1.0)
         
     | 
| 
      
 116 
     | 
    
         
            +
              bundler (~> 1.0.0)
         
     | 
| 
      
 117 
     | 
    
         
            +
              jeweler (~> 1.8.3)
         
     | 
| 
      
 118 
     | 
    
         
            +
              rails (~> 3.1.0)
         
     | 
| 
      
 119 
     | 
    
         
            +
              rdoc (~> 3.12)
         
     | 
| 
      
 120 
     | 
    
         
            +
              rspec (~> 2.8.0)
         
     | 
| 
      
 121 
     | 
    
         
            +
              rspec-rails (~> 2.8.1)
         
     | 
| 
      
 122 
     | 
    
         
            +
              simplecov
         
     | 
| 
      
 123 
     | 
    
         
            +
              sqlite3
         
     | 
| 
      
 124 
     | 
    
         
            +
              yaml_waml
         
     | 
| 
      
 125 
     | 
    
         
            +
              yard (~> 0.7)
         
     | 
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -1,7 +1,6 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            SchemaComments 
         
     | 
| 
       2 
     | 
    
         
            -
            ==========
         
     | 
| 
      
 1 
     | 
    
         
            +
            = SchemaComments 
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            == Install 
     | 
| 
      
 3 
     | 
    
         
            +
            == Install
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
5 
     | 
    
         
             
            === as a plugin
         
     | 
| 
       7 
6 
     | 
    
         
             
             ruby script/plugin install git://github.com/akm/schema_comments.git
         
     | 
| 
         @@ -26,7 +25,7 @@ If you install schema_comments as a gem, must create config/initializers/schema_ 
     | 
|
| 
       26 
25 
     | 
    
         
             
             SchemaComments.setup
         
     | 
| 
       27 
26 
     | 
    
         | 
| 
       28 
27 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
            == overview 
     | 
| 
      
 28 
     | 
    
         
            +
            == overview
         
     | 
| 
       30 
29 
     | 
    
         
             
            schema_commentsプラグインを使うと、テーブルとカラムにコメントを記述することができます。
         
     | 
| 
       31 
30 
     | 
    
         | 
| 
       32 
31 
     | 
    
         
             
             class CreateProducts < ActiveRecord::Migration
         
     | 
| 
         @@ -67,13 +66,13 @@ columns, create_table, drop_table, rename_table 
     | 
|
| 
       67 
66 
     | 
    
         
             
            remove_column, add_column, change_column
         
     | 
| 
       68 
67 
     | 
    
         | 
| 
       69 
68 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
            == コメントはどこに保存されるのか 
     | 
| 
      
 69 
     | 
    
         
            +
            == コメントはどこに保存されるのか
         
     | 
| 
       71 
70 
     | 
    
         
             
            db/schema_comments.yml にYAML形式で保存されます。
         
     | 
| 
       72 
71 
     | 
    
         
             
            あまり推奨しませんが、もしマイグレーションにコメントを記述するのを忘れてしまった場合、db/schema_comments.yml
         
     | 
| 
       73 
72 
     | 
    
         
             
            を直接編集した後、rake db:schema:dumpやマイグレーションを実行すると、db/schema.rbのコメントに反映されます。
         
     | 
| 
       74 
73 
     | 
    
         | 
| 
       75 
74 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
            == I18nへの対応 
     | 
| 
      
 75 
     | 
    
         
            +
            == I18nへの対応
         
     | 
| 
       77 
76 
     | 
    
         
             
            rake i18n:schema_comments:update_config_localeタスクを実行すると、i18n用のYAMLを更新できます。
         
     | 
| 
       78 
77 
     | 
    
         | 
| 
       79 
78 
     | 
    
         
             
            rake i18n:schema_comments:update_config_locale LOCALE=ja でデフォルトではconfig/locales/ja.ymlを更新します。
         
     | 
| 
         @@ -85,7 +84,7 @@ I18n.default_locale = 'ja' 
     | 
|
| 
       85 
84 
     | 
    
         
             
            また出力先のYAMLのPATHを指定したい場合、YAML_PATHで指定が可能です。
         
     | 
| 
       86 
85 
     | 
    
         
             
            rake i18n:schema_comments:update_config_locale LOCALE=ja YAML_PATH=/path/to/yaml
         
     | 
| 
       87 
86 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
            === コメント内コメント 
     | 
| 
      
 87 
     | 
    
         
            +
            === コメント内コメント
         
     | 
| 
       89 
88 
     | 
    
         
             
            コメント中の ((( から ))) は反映されませんので、モデル名/属性名に含めたくない箇所は ((( と ))) で括ってください。
         
     | 
| 
       90 
89 
     | 
    
         
             
            ((( ))) と同様に[[[ ]]]も使用できます。
         
     | 
| 
       91 
90 
     | 
    
         
             
            例えば以下のようにdb/schema.rbに出力されている場合、
         
     | 
| 
         @@ -113,17 +112,17 @@ ja: 
     | 
|
| 
       113 
112 
     | 
    
         | 
| 
       114 
113 
     | 
    
         | 
| 
       115 
114 
     | 
    
         | 
| 
       116 
     | 
    
         
            -
            == MySQLのビュー 
     | 
| 
      
 115 
     | 
    
         
            +
            == MySQLのビュー
         
     | 
| 
       117 
116 
     | 
    
         
             
            MySQLのビューを使用した場合、元々MySQLではSHOW TABLES でビューも表示してしまうため、
         
     | 
| 
       118 
117 
     | 
    
         
             
            ビューはテーブルとしてSchemaDumperに認識され、development環境ではMySQLのビューとして作成されているのに、
         
     | 
| 
       119 
118 
     | 
    
         
             
            test環境ではテーブルとして作成されてしまい、テストが正しく動かないことがあります。
         
     | 
| 
       120 
119 
     | 
    
         
             
            これを避けるため、schema_commentsでは、db/schema.rbを出力する際、テーブルに関する記述の後に、CREATE VIEWを行う記述を追加します。
         
     | 
| 
       121 
120 
     | 
    
         | 
| 
       122 
121 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
            == annotate_models 
     | 
| 
      
 122 
     | 
    
         
            +
            == annotate_models
         
     | 
| 
       124 
123 
     | 
    
         
             
            rake db:annotate で以下のようなコメントを、モデル、テスト、フィクスチャといったモデルに関係の強いファイルの
         
     | 
| 
       125 
124 
     | 
    
         
             
            先頭に追加します。
         
     | 
| 
       126 
     | 
    
         
            -
              # == Schema Info 
     | 
| 
      
 125 
     | 
    
         
            +
              # == Schema Info
         
     | 
| 
       127 
126 
     | 
    
         
             
              # 
         
     | 
| 
       128 
127 
     | 
    
         
             
              # Schema version: 20090721185959
         
     | 
| 
       129 
128 
     | 
    
         
             
              #
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,50 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'rubygems'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'bundler'
         
     | 
| 
      
 5 
     | 
    
         
            +
            begin
         
     | 
| 
      
 6 
     | 
    
         
            +
              Bundler.setup(:default, :development)
         
     | 
| 
      
 7 
     | 
    
         
            +
            rescue Bundler::BundlerError => e
         
     | 
| 
      
 8 
     | 
    
         
            +
              $stderr.puts e.message
         
     | 
| 
      
 9 
     | 
    
         
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         
     | 
| 
      
 10 
     | 
    
         
            +
              exit e.status_code
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
       2 
12 
     | 
    
         
             
            require 'rake'
         
     | 
| 
       3 
13 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
               
     | 
| 
       17 
     | 
    
         
            -
              Jeweler::GemcutterTasks.new
         
     | 
| 
       18 
     | 
    
         
            -
            rescue LoadError
         
     | 
| 
       19 
     | 
    
         
            -
              puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
         
     | 
| 
      
 14 
     | 
    
         
            +
            require 'jeweler'
         
     | 
| 
      
 15 
     | 
    
         
            +
            Jeweler::Tasks.new do |gem|
         
     | 
| 
      
 16 
     | 
    
         
            +
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.name = "schema_comments"
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem.homepage = "http://github.com/akm/schema_comments"
         
     | 
| 
      
 19 
     | 
    
         
            +
              gem.license = "Ruby License"
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem.summary  = "schema_comments generates extra methods dynamically"
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem.description  = "schema_comments generates extra methods dynamically for attribute which has options"
         
     | 
| 
      
 22 
     | 
    
         
            +
              gem.email = "akm2000@gmail.com"
         
     | 
| 
      
 23 
     | 
    
         
            +
              gem.authors = ["akimatter"]
         
     | 
| 
      
 24 
     | 
    
         
            +
              # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
         
     | 
| 
      
 25 
     | 
    
         
            +
              gem.test_files = Dir.glob('spec/**/*.rb') + Dir.glob('spec/**/*.yml')
         
     | 
| 
      
 26 
     | 
    
         
            +
              # dependencies defined in Gemfile
         
     | 
| 
       20 
27 
     | 
    
         
             
            end
         
     | 
| 
      
 28 
     | 
    
         
            +
            Jeweler::RubygemsDotOrgTasks.new
         
     | 
| 
       21 
29 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
            require ' 
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              spec. 
     | 
| 
      
 30 
     | 
    
         
            +
            require 'rspec/core'
         
     | 
| 
      
 31 
     | 
    
         
            +
            require 'rspec/core/rake_task'
         
     | 
| 
      
 32 
     | 
    
         
            +
            RSpec::Core::RakeTask.new(:spec) do |spec|
         
     | 
| 
      
 33 
     | 
    
         
            +
              spec.pattern = FileList['spec/**/*_spec.rb']
         
     | 
| 
       26 
34 
     | 
    
         
             
            end
         
     | 
| 
       27 
35 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              spec.libs << 'lib' << 'spec'
         
     | 
| 
      
 36 
     | 
    
         
            +
            RSpec::Core::RakeTask.new(:rcov) do |spec|
         
     | 
| 
       30 
37 
     | 
    
         
             
              spec.pattern = 'spec/**/*_spec.rb'
         
     | 
| 
       31 
38 
     | 
    
         
             
              spec.rcov = true
         
     | 
| 
       32 
     | 
    
         
            -
              spec.rcov_opts = lambda do
         
     | 
| 
       33 
     | 
    
         
            -
                IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
39 
     | 
    
         
             
            end
         
     | 
| 
       36 
40 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
            task :spec => :check_dependencies
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
41 
     | 
    
         
             
            task :default => :spec
         
     | 
| 
       40 
42 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
            require ' 
     | 
| 
       42 
     | 
    
         
            -
            Rake:: 
     | 
| 
       43 
     | 
    
         
            -
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
       46 
     | 
    
         
            -
              rdoc.title = "schema_comments #{version}"
         
     | 
| 
       47 
     | 
    
         
            -
              rdoc.rdoc_files.include('README.rdoc')
         
     | 
| 
       48 
     | 
    
         
            -
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
       49 
     | 
    
         
            -
              rdoc.options = ["--charset", "utf-8", "--line-numbers"]
         
     | 
| 
       50 
     | 
    
         
            -
            end
         
     | 
| 
      
 43 
     | 
    
         
            +
            require 'yard'
         
     | 
| 
      
 44 
     | 
    
         
            +
            YARD::Rake::YardocTask.new
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.2.0.alpha1
         
     | 
    
        data/lib/annotate_models.rb
    CHANGED
    
    | 
         @@ -2,16 +2,18 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            # fork from
         
     | 
| 
       3 
3 
     | 
    
         
             
            # http://github.com/rotuka/annotate_models/blob/d2afee82020dbc592b147d92f9beeadbf665a9e0/lib/annotate_models.rb
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
            require 'rails'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       5 
7 
     | 
    
         
             
            require "config/environment" if File.exist?("config/environment")
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            MODEL_DIR         =  
     | 
| 
       8 
     | 
    
         
            -
            UNIT_TEST_DIR     =  
     | 
| 
       9 
     | 
    
         
            -
            SPEC_MODEL_DIR    =  
     | 
| 
       10 
     | 
    
         
            -
            FIXTURES_DIR      =  
     | 
| 
       11 
     | 
    
         
            -
            SPEC_FIXTURES_DIR =  
     | 
| 
      
 9 
     | 
    
         
            +
            MODEL_DIR         = Rails.root.join("app/models" )
         
     | 
| 
      
 10 
     | 
    
         
            +
            UNIT_TEST_DIR     = Rails.root.join("test/unit"  )
         
     | 
| 
      
 11 
     | 
    
         
            +
            SPEC_MODEL_DIR    = Rails.root.join("spec/models")
         
     | 
| 
      
 12 
     | 
    
         
            +
            FIXTURES_DIR      = Rails.root.join("test/fixtures")
         
     | 
| 
      
 13 
     | 
    
         
            +
            SPEC_FIXTURES_DIR = Rails.root.join("spec/fixtures")
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
            module AnnotateModels
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       15 
17 
     | 
    
         
             
              PREFIX_AT_BOTTOM = "== Schema Info"
         
     | 
| 
       16 
18 
     | 
    
         
             
              SUFFIX_AT_BOTTOM = ""
         
     | 
| 
       17 
19 
     | 
    
         
             
              PREFIX_ON_TOP = "== Schema Info =="
         
     | 
| 
         @@ -61,7 +63,7 @@ module AnnotateModels 
     | 
|
| 
       61 
63 
     | 
    
         
             
                  value.inspect
         
     | 
| 
       62 
64 
     | 
    
         
             
                end
         
     | 
| 
       63 
65 
     | 
    
         
             
              end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
       65 
67 
     | 
    
         
             
              # Use the column information in an ActiveRecord class
         
     | 
| 
       66 
68 
     | 
    
         
             
              # to create a comment block containing a line for
         
     | 
| 
       67 
69 
     | 
    
         
             
              # each column. The line contains the column name,
         
     | 
| 
         @@ -71,7 +73,7 @@ module AnnotateModels 
     | 
|
| 
       71 
73 
     | 
    
         
             
                table_info << " # #{klass.table_comment}" unless klass.table_comment.blank?
         
     | 
| 
       72 
74 
     | 
    
         
             
                table_info << "\n#\n"
         
     | 
| 
       73 
75 
     | 
    
         
             
                max_size = klass.column_names.collect{|name| name.size}.max + 1
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
       75 
77 
     | 
    
         
             
                columns = klass.columns
         
     | 
| 
       76 
78 
     | 
    
         | 
| 
       77 
79 
     | 
    
         
             
                cols = if self.sort_columns
         
     | 
| 
         @@ -83,10 +85,10 @@ module AnnotateModels 
     | 
|
| 
       83 
85 
     | 
    
         
             
                       else
         
     | 
| 
       84 
86 
     | 
    
         
             
                         columns
         
     | 
| 
       85 
87 
     | 
    
         
             
                       end
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
       87 
89 
     | 
    
         
             
                col_lines = append_comments(cols.map{|col| [col, annotate_column(col, klass, max_size)]})
         
     | 
| 
       88 
90 
     | 
    
         
             
                cols_text = col_lines.join("\n")
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
       90 
92 
     | 
    
         
             
                result = "# #{self.output_prefix}\n# \n# Schema version: #{get_schema_version}\n#\n"
         
     | 
| 
       91 
93 
     | 
    
         
             
                result << table_info
         
     | 
| 
       92 
94 
     | 
    
         
             
                result << cols_text
         
     | 
| 
         @@ -94,13 +96,13 @@ module AnnotateModels 
     | 
|
| 
       94 
96 
     | 
    
         
             
                result << "\n"
         
     | 
| 
       95 
97 
     | 
    
         
             
                result
         
     | 
| 
       96 
98 
     | 
    
         
             
              end
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
       98 
100 
     | 
    
         
             
              def self.annotate_column(col, klass, max_size)
         
     | 
| 
       99 
101 
     | 
    
         
             
                attrs = []
         
     | 
| 
       100 
102 
     | 
    
         
             
                attrs << "not null" unless col.null
         
     | 
| 
       101 
103 
     | 
    
         
             
                attrs << "default(#{quote(col.default)})" if col.default
         
     | 
| 
       102 
104 
     | 
    
         
             
                attrs << "primary key" if col.name == klass.primary_key
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
       104 
106 
     | 
    
         
             
                col_type = col.type.to_s
         
     | 
| 
       105 
107 
     | 
    
         
             
                if col_type == "decimal"
         
     | 
| 
       106 
108 
     | 
    
         
             
                  col_type << "(#{col.precision}, #{col.scale})"
         
     | 
| 
         @@ -120,7 +122,7 @@ module AnnotateModels 
     | 
|
| 
       120 
122 
     | 
    
         
             
                  end
         
     | 
| 
       121 
123 
     | 
    
         
             
                end
         
     | 
| 
       122 
124 
     | 
    
         
             
              end
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
       124 
126 
     | 
    
         
             
              # Add a schema block to a file. If the file already contains
         
     | 
| 
       125 
127 
     | 
    
         
             
              # a schema info block (a comment starting
         
     | 
| 
       126 
128 
     | 
    
         
             
              # with "Schema as of ..."), remove it first.
         
     | 
| 
         @@ -128,7 +130,7 @@ module AnnotateModels 
     | 
|
| 
       128 
130 
     | 
    
         
             
              def self.annotate_one_file(file_name, info_block)
         
     | 
| 
       129 
131 
     | 
    
         
             
                if File.exist?(file_name)
         
     | 
| 
       130 
132 
     | 
    
         
             
                  content = File.read(file_name)
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
       132 
134 
     | 
    
         
             
                  encoding_comment = content.scan(/^\#\s*-\*-(.+?)-\*-/).flatten.first
         
     | 
| 
       133 
135 
     | 
    
         
             
                  content.sub!(/^\#\s*-\*-(.+?)-\*-/, '')
         
     | 
| 
       134 
136 
     | 
    
         | 
| 
         @@ -136,7 +138,7 @@ module AnnotateModels 
     | 
|
| 
       136 
138 
     | 
    
         
             
                  content.sub!(/(\n)*^# #{PREFIX_ON_TOP}.*?\n(#.*\n)*# #{SUFFIX_ON_TOP}/, '')
         
     | 
| 
       137 
139 
     | 
    
         
             
                  content.sub!(/(\n)*^# #{PREFIX_AT_BOTTOM}.*?\n(#.*\n)*#.*(\n)*/, '')
         
     | 
| 
       138 
140 
     | 
    
         
             
                  content.sub!(/^[\n\s]*/, '')
         
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
       140 
142 
     | 
    
         
             
                  # Write it back
         
     | 
| 
       141 
143 
     | 
    
         
             
                  File.open(file_name, "w") do |f|
         
     | 
| 
       142 
144 
     | 
    
         
             
                    f.print "# -*- #{encoding_comment.strip} -*-\n\n" unless encoding_comment.blank?
         
     | 
| 
         @@ -153,27 +155,27 @@ module AnnotateModels 
     | 
|
| 
       153 
155 
     | 
    
         
             
                end
         
     | 
| 
       154 
156 
     | 
    
         
             
              end
         
     | 
| 
       155 
157 
     | 
    
         | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
       157 
159 
     | 
    
         
             
              # Given the name of an ActiveRecord class, create a schema
         
     | 
| 
       158 
160 
     | 
    
         
             
              # info block (basically a comment containing information
         
     | 
| 
       159 
161 
     | 
    
         
             
              # on the columns and their types) and put it at the front
         
     | 
| 
       160 
     | 
    
         
            -
              # of the model and fixture source files. 
     | 
| 
      
 162 
     | 
    
         
            +
              # of the model and fixture source files.
         
     | 
| 
       161 
163 
     | 
    
         
             
              def self.annotate(klass)
         
     | 
| 
       162 
164 
     | 
    
         
             
                info = get_schema_info(klass)
         
     | 
| 
       163 
165 
     | 
    
         
             
                model_name = klass.name.underscore
         
     | 
| 
       164 
166 
     | 
    
         
             
                fixtures_name = "#{klass.table_name}.yml"
         
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
       166 
168 
     | 
    
         
             
                [
         
     | 
| 
       167 
169 
     | 
    
         
             
                  File.join(self.model_dir,     "#{model_name}.rb"),      # model
         
     | 
| 
       168 
170 
     | 
    
         
             
                  File.join(UNIT_TEST_DIR,      "#{model_name}_test.rb"), # test
         
     | 
| 
       169 
171 
     | 
    
         
             
                  File.join(FIXTURES_DIR,       fixtures_name),           # fixture
         
     | 
| 
       170 
172 
     | 
    
         
             
                  File.join(SPEC_MODEL_DIR,     "#{model_name}_spec.rb"), # spec
         
     | 
| 
       171 
173 
     | 
    
         
             
                  File.join(SPEC_FIXTURES_DIR,  fixtures_name),           # spec fixture
         
     | 
| 
       172 
     | 
    
         
            -
                   
     | 
| 
       173 
     | 
    
         
            -
                   
     | 
| 
      
 174 
     | 
    
         
            +
                  Rails.root.join(        'test', 'factories.rb'),  # factories file
         
     | 
| 
      
 175 
     | 
    
         
            +
                  Rails.root.join(        'spec', 'factories.rb'),  # factories file
         
     | 
| 
       174 
176 
     | 
    
         
             
                ].each { |file| annotate_one_file(file, info) }
         
     | 
| 
       175 
177 
     | 
    
         
             
              end
         
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
       177 
179 
     | 
    
         
             
              # Return a list of the model files to annotate. If we have
         
     | 
| 
       178 
180 
     | 
    
         
             
              # command line arguments, they're assumed to be either
         
     | 
| 
       179 
181 
     | 
    
         
             
              # the underscore or CamelCase versions of model names.
         
     | 
| 
         @@ -183,16 +185,16 @@ module AnnotateModels 
     | 
|
| 
       183 
185 
     | 
    
         
             
                result = nil
         
     | 
| 
       184 
186 
     | 
    
         
             
                if self.models.empty?
         
     | 
| 
       185 
187 
     | 
    
         
             
                  Dir.chdir(self.model_dir) do
         
     | 
| 
       186 
     | 
    
         
            -
                    result = Dir["**/*.rb"].map do |filename| 
     | 
| 
      
 188 
     | 
    
         
            +
                    result = Dir["**/*.rb"].map do |filename|
         
     | 
| 
       187 
189 
     | 
    
         
             
                      filename.sub(/\.rb$/, '').camelize
         
     | 
| 
       188 
190 
     | 
    
         
             
                    end
         
     | 
| 
       189 
191 
     | 
    
         
             
                  end
         
     | 
| 
       190 
192 
     | 
    
         
             
                else
         
     | 
| 
       191 
193 
     | 
    
         
             
                  result = self.models.dup
         
     | 
| 
       192 
194 
     | 
    
         
             
                end
         
     | 
| 
       193 
     | 
    
         
            -
                result 
     | 
| 
      
 195 
     | 
    
         
            +
                result
         
     | 
| 
       194 
196 
     | 
    
         
             
              end
         
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
       196 
198 
     | 
    
         
             
              # We're passed a name of things that might be
         
     | 
| 
       197 
199 
     | 
    
         
             
              # ActiveRecord models. If we can find the class, and
         
     | 
| 
       198 
200 
     | 
    
         
             
              # if its a subclass of ActiveRecord::Base,
         
     | 
| 
         @@ -213,7 +215,7 @@ module AnnotateModels 
     | 
|
| 
       213 
215 
     | 
    
         
             
                end
         
     | 
| 
       214 
216 
     | 
    
         
             
                puts "Annotated #{annotated.join(', ')}"
         
     | 
| 
       215 
217 
     | 
    
         
             
              end
         
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
      
 218 
     | 
    
         
            +
             
     | 
| 
       217 
219 
     | 
    
         
             
              def self.get_schema_version
         
     | 
| 
       218 
220 
     | 
    
         
             
                unless @schema_version
         
     | 
| 
       219 
221 
     | 
    
         
             
                  version = ActiveRecord::Migrator.current_version rescue 0
         
     | 
    
        data/lib/hash_key_orderable.rb
    CHANGED
    
    
    
        data/lib/schema_comments/base.rb
    CHANGED
    
    | 
         @@ -7,12 +7,12 @@ module SchemaComments 
     | 
|
| 
       7 
7 
     | 
    
         
             
                    alias :columns :columns_with_schema_comments
         
     | 
| 
       8 
8 
     | 
    
         
             
                  end
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       11 
11 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       12 
12 
     | 
    
         
             
                  def table_comment
         
     | 
| 
       13 
13 
     | 
    
         
             
                    @table_comment ||= connection.table_comment(table_name)
         
     | 
| 
       14 
14 
     | 
    
         
             
                  end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       16 
16 
     | 
    
         
             
                  def columns_with_schema_comments
         
     | 
| 
       17 
17 
     | 
    
         
             
                    result = columns_without_schema_comments
         
     | 
| 
       18 
18 
     | 
    
         
             
                    unless @column_comments_loaded
         
     | 
| 
         @@ -24,17 +24,17 @@ module SchemaComments 
     | 
|
| 
       24 
24 
     | 
    
         
             
                    end
         
     | 
| 
       25 
25 
     | 
    
         
             
                    result
         
     | 
| 
       26 
26 
     | 
    
         
             
                  end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       28 
28 
     | 
    
         
             
                  def reset_column_comments
         
     | 
| 
       29 
29 
     | 
    
         
             
                    @column_comments_loaded = false
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       32 
32 
     | 
    
         
             
                  def reset_table_comments
         
     | 
| 
       33 
33 
     | 
    
         
             
                    @table_comment = nil
         
     | 
| 
       34 
34 
     | 
    
         
             
                  end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       36 
36 
     | 
    
         
             
                  attr_accessor_with_default :ignore_pattern_to_export_i18n, /\[.*\]/
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
       38 
38 
     | 
    
         
             
                  def export_i18n_models
         
     | 
| 
       39 
39 
     | 
    
         
             
                    subclasses = ActiveRecord::Base.send(:subclasses).select do |klass|
         
     | 
| 
       40 
40 
     | 
    
         
             
                      (klass != SchemaComments::SchemaComment) and
         
     | 
| 
         @@ -47,7 +47,7 @@ module SchemaComments 
     | 
|
| 
       47 
47 
     | 
    
         
             
                      d
         
     | 
| 
       48 
48 
     | 
    
         
             
                    end
         
     | 
| 
       49 
49 
     | 
    
         
             
                  end
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       51 
51 
     | 
    
         
             
                  def export_i18n_attributes(connection = ActiveRecord::Base.connection)
         
     | 
| 
       52 
52 
     | 
    
         
             
                    subclasses = ActiveRecord::Base.send(:subclasses).select do |klass|
         
     | 
| 
       53 
53 
     | 
    
         
             
                      (klass != SchemaComments::SchemaComment) and
         
     | 
| 
         @@ -65,8 +65,8 @@ module SchemaComments 
     | 
|
| 
       65 
65 
     | 
    
         
             
                      d
         
     | 
| 
       66 
66 
     | 
    
         
             
                    end
         
     | 
| 
       67 
67 
     | 
    
         
             
                  end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
       69 
69 
     | 
    
         
             
                end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       71 
71 
     | 
    
         
             
              end
         
     | 
| 
       72 
72 
     | 
    
         
             
            end
         
     | 
| 
         @@ -40,16 +40,21 @@ module SchemaComments 
     | 
|
| 
       40 
40 
     | 
    
         
             
                  #   column_comments(:users, {:first_name => "User's given name", :last_name => "Family name"})
         
     | 
| 
       41 
41 
     | 
    
         
             
                  #   column_comments(:tags , {:id => "Tag IDentifier"})
         
     | 
| 
       42 
42 
     | 
    
         
             
                  def column_comments(*args)
         
     | 
| 
       43 
     | 
    
         
            -
                     
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                      args. 
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 43 
     | 
    
         
            +
                    case args.length
         
     | 
| 
      
 44 
     | 
    
         
            +
                    when 1 then
         
     | 
| 
      
 45 
     | 
    
         
            +
                       # こっちはSchemaComments::Base::ClassMethods#columns_with_schema_commentsから呼び出されます。
         
     | 
| 
      
 46 
     | 
    
         
            +
                      return SchemaComment.column_comments(args.first)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    when 2 then
         
     | 
| 
      
 48 
     | 
    
         
            +
                      if args.last.is_a?(Hash)
         
     | 
| 
      
 49 
     | 
    
         
            +
                        # マイグレーションからActiveRecord関係を経由して呼び出されます。
         
     | 
| 
      
 50 
     | 
    
         
            +
                        table_name = args.first.to_s
         
     | 
| 
      
 51 
     | 
    
         
            +
                        args.last.each do |col, comment|
         
     | 
| 
      
 52 
     | 
    
         
            +
                          column_comment(table_name, col, comment) unless SchemaComments.quiet
         
     | 
| 
      
 53 
     | 
    
         
            +
                        end
         
     | 
| 
      
 54 
     | 
    
         
            +
                        return
         
     | 
| 
       48 
55 
     | 
    
         
             
                      end
         
     | 
| 
       49 
     | 
    
         
            -
                    else
         
     | 
| 
       50 
     | 
    
         
            -
                      # こっちはSchemaComments::Base::ClassMethods#columns_with_schema_commentsから呼び出されます。
         
     | 
| 
       51 
     | 
    
         
            -
                      SchemaComment.column_comments(args)
         
     | 
| 
       52 
56 
     | 
    
         
             
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
                    raise ArgumentError, "#{self.class}#column_comments accepts (tabel_name) or (tabel_name, hash_col_comment)"
         
     | 
| 
       53 
58 
     | 
    
         
             
                  end
         
     | 
| 
       54 
59 
     | 
    
         | 
| 
       55 
60 
     | 
    
         
             
                  def table_comment(table_name, comment = nil) #:nodoc:
         
     | 
| 
         @@ -7,7 +7,7 @@ module SchemaComments 
     | 
|
| 
       7 
7 
     | 
    
         
             
                    alias :migrate :migrate_with_schema_comments
         
     | 
| 
       8 
8 
     | 
    
         
             
                  end
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       11 
11 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       12 
12 
     | 
    
         
             
                  def migrate_with_schema_comments(*args, &block)
         
     | 
| 
       13 
13 
     | 
    
         
             
                    SchemaComments::SchemaComment.yaml_access do
         
     | 
| 
         @@ -15,6 +15,6 @@ module SchemaComments 
     | 
|
| 
       15 
15 
     | 
    
         
             
                    end
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         
             
            end
         
     | 
| 
         @@ -7,7 +7,7 @@ module SchemaComments 
     | 
|
| 
       7 
7 
     | 
    
         
             
                    alias :migrate :migrate_with_schema_comments
         
     | 
| 
       8 
8 
     | 
    
         
             
                  end
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       11 
11 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       12 
12 
     | 
    
         
             
                  def migrate_with_schema_comments(*args, &block)
         
     | 
| 
       13 
13 
     | 
    
         
             
                    SchemaComments::SchemaComment.yaml_access do
         
     | 
| 
         @@ -15,6 +15,6 @@ module SchemaComments 
     | 
|
| 
       15 
15 
     | 
    
         
             
                    end
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
20 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,7 +3,7 @@ require 'yaml/store' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'hash_key_orderable'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            module SchemaComments
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       7 
7 
     | 
    
         
             
              # 現在はActiveRecord::Baseを継承していますが、将来移行が完全に終了した
         
     | 
| 
       8 
8 
     | 
    
         
             
              # 時点で、ActiveRecord::Baseの継承をやめます。
         
     | 
| 
       9 
9 
     | 
    
         
             
              #
         
     | 
| 
         @@ -23,7 +23,7 @@ module SchemaComments 
     | 
|
| 
       23 
23 
     | 
    
         
             
                    return nil unless table_exists?
         
     | 
| 
       24 
24 
     | 
    
         
             
                    connection.select_value(sanitize_conditions("select descriptions from schema_comments where table_name = '%s' and column_name is null" % table_name))
         
     | 
| 
       25 
25 
     | 
    
         
             
                  end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
       27 
27 
     | 
    
         
             
                  def column_comment(table_name, column_name)
         
     | 
| 
       28 
28 
     | 
    
         
             
                    if yaml_exist?
         
     | 
| 
       29 
29 
     | 
    
         
             
                      @column_names ||= yaml_access{|db| db[COLUMN_KEY] }.dup
         
     | 
| 
         @@ -33,7 +33,7 @@ module SchemaComments 
     | 
|
| 
       33 
33 
     | 
    
         
             
                    return nil unless table_exists?
         
     | 
| 
       34 
34 
     | 
    
         
             
                    connection.select_value(sanitize_conditions("select descriptions from schema_comments where table_name = '%s' and column_name = '%s'" % [table_name, column_name]))
         
     | 
| 
       35 
35 
     | 
    
         
             
                  end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
       37 
37 
     | 
    
         
             
                  def column_comments(table_name)
         
     | 
| 
       38 
38 
     | 
    
         
             
                    if yaml_exist?
         
     | 
| 
       39 
39 
     | 
    
         
             
                      result = nil
         
     | 
| 
         @@ -45,14 +45,14 @@ module SchemaComments 
     | 
|
| 
       45 
45 
     | 
    
         
             
                    hash_array = connection.select_all(sanitize_conditions("select column_name, descriptions from schema_comments where table_name = '%s' and column_name is not null" % table_name))
         
     | 
| 
       46 
46 
     | 
    
         
             
                    hash_array.inject({}){|dest, r| dest[r['column_name']] = r['descriptions']; dest}
         
     | 
| 
       47 
47 
     | 
    
         
             
                  end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       49 
49 
     | 
    
         
             
                  def save_table_comment(table_name, comment)
         
     | 
| 
       50 
50 
     | 
    
         
             
                    yaml_access do |db|
         
     | 
| 
       51 
51 
     | 
    
         
             
                      db[TABLE_KEY][table_name.to_s] = comment
         
     | 
| 
       52 
52 
     | 
    
         
             
                    end
         
     | 
| 
       53 
53 
     | 
    
         
             
                    @table_names = nil
         
     | 
| 
       54 
54 
     | 
    
         
             
                  end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       56 
56 
     | 
    
         
             
                  def save_column_comment(table_name, column_name, comment)
         
     | 
| 
       57 
57 
     | 
    
         
             
                    yaml_access do |db|
         
     | 
| 
       58 
58 
     | 
    
         
             
                      db[COLUMN_KEY][table_name.to_s] ||= {}
         
     | 
| 
         @@ -60,7 +60,7 @@ module SchemaComments 
     | 
|
| 
       60 
60 
     | 
    
         
             
                    end
         
     | 
| 
       61 
61 
     | 
    
         
             
                    @column_names = nil
         
     | 
| 
       62 
62 
     | 
    
         
             
                  end
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       64 
64 
     | 
    
         
             
                  def destroy_of(table_name, column_name)
         
     | 
| 
       65 
65 
     | 
    
         
             
                    yaml_access do |db|
         
     | 
| 
       66 
66 
     | 
    
         
             
                      column_hash = db[COLUMN_KEY][table_name.to_s]
         
     | 
| 
         @@ -68,7 +68,7 @@ module SchemaComments 
     | 
|
| 
       68 
68 
     | 
    
         
             
                    end
         
     | 
| 
       69 
69 
     | 
    
         
             
                    @column_names = nil
         
     | 
| 
       70 
70 
     | 
    
         
             
                  end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
       72 
72 
     | 
    
         
             
                  def update_table_name(table_name, new_name)
         
     | 
| 
       73 
73 
     | 
    
         
             
                    if yaml_exist?
         
     | 
| 
       74 
74 
     | 
    
         
             
                      yaml_access do |db|
         
     | 
| 
         @@ -79,7 +79,7 @@ module SchemaComments 
     | 
|
| 
       79 
79 
     | 
    
         
             
                    @table_names = nil
         
     | 
| 
       80 
80 
     | 
    
         
             
                    @column_names = nil
         
     | 
| 
       81 
81 
     | 
    
         
             
                  end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
       83 
83 
     | 
    
         
             
                  def update_column_name(table_name, column_name, new_name)
         
     | 
| 
       84 
84 
     | 
    
         
             
                    if yaml_exist?
         
     | 
| 
       85 
85 
     | 
    
         
             
                      yaml_access do |db|
         
     | 
| 
         @@ -92,11 +92,11 @@ module SchemaComments 
     | 
|
| 
       92 
92 
     | 
    
         
             
                    @table_names = nil
         
     | 
| 
       93 
93 
     | 
    
         
             
                    @column_names = nil
         
     | 
| 
       94 
94 
     | 
    
         
             
                  end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
       96 
96 
     | 
    
         
             
                  def yaml_exist?
         
     | 
| 
       97 
97 
     | 
    
         
             
                    File.exist?(SchemaComments.yaml_path)
         
     | 
| 
       98 
98 
     | 
    
         
             
                  end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
       100 
100 
     | 
    
         
             
                  def yaml_access(&block)
         
     | 
| 
       101 
101 
     | 
    
         
             
                    if @yaml_transaction
         
     | 
| 
       102 
102 
     | 
    
         
             
                      yield(@yaml_transaction) if block_given?
         
     |