activerecord-simple_index_name 0.1.0 → 0.2.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fa6b9aae3727e763a002f35d1ce57aad24114fa
4
- data.tar.gz: eb91da3010ce3ae2e2ca0054706da0c16d9917d8
3
+ metadata.gz: 0af826dbe87652a6514641bf5929772e87e253d4
4
+ data.tar.gz: 3024da2dcf30d5618b5970e2dfe5e24e5878944c
5
5
  SHA512:
6
- metadata.gz: 1a8931aae60ddc11a440ab53c811a4d57a779c893af7902475190a0234b2fa658a8b5a3defac05e19e128509ee1368ff5287fee49ce1f19c0186b39b633bb936
7
- data.tar.gz: ec67d7146748d7243b38c26b128cfd82a00ce24fe4ebcb59d494f92bbd1908edc6809fcd133c74b6499b2ad912f420a2b5ad585c5bba57e0d6cd6912cb039054
6
+ metadata.gz: 69a94c95b1fd18b4a87e803664ed4a342b57f3fe7ea63411e77d77b633ec43266d083d31c9a6234d83c4b5a416b562deb22a29ea85298328162387eb2892b9bc
7
+ data.tar.gz: b1d095044799f1355ae75fb12e26510b29444de7ee8a4c846b87072bb1ef9d5df365b04264071d5194ab41bbc819793fc51639ea64020f328f6abbb22d0ecd32
data/.travis.yml CHANGED
@@ -5,8 +5,9 @@ rvm:
5
5
  - 2.3
6
6
  - ruby-head
7
7
  gemfile:
8
- - gemfiles/activerecord_4_1.gemfile
9
- - gemfiles/activerecord_4_2.gemfile
8
+ - gemfiles/rails_4_0.gemfile
9
+ - gemfiles/rails_4_1.gemfile
10
+ - gemfiles/rails_4_2.gemfile
10
11
  cache: bundler
11
12
  sudo: false
12
13
  before_install: gem install bundler -v 1.10.6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
+ # Change Log
2
+
1
3
  ## Unreleased
2
- [full changelog](http://github.com/sue445/rubicure/compare/v0.1.0...master)
4
+ [full changelog](http://github.com/sue445/activerecord-simple_index_name/compare/v0.1.0...master)
5
+
6
+ ### Enhancements
7
+ * Add `ActiveRecord::SimpleIndexName.config.auto_shorten` configuration
8
+ * https://github.com/sue445/activerecord-simple_index_name/pull/13
9
+ * Add `ActiveRecord::SimpleIndexName::EnableShorten`, `ActiveRecord::SimpleIndexName::DisableShorten`
10
+ * https://github.com/sue445/activerecord-simple_index_name/pull/12
3
11
 
12
+ ### Other
13
+ * Test with Rails 4.0.x
14
+ * https://github.com/sue445/activerecord-simple_index_name/pull/19
15
+ * Move files and rename module
16
+ * https://github.com/sue445/activerecord-simple_index_name/pull/17
17
+ * Move: `lib/activerecord/simple_index_name` -> `lib/active_record/simple_index_name`
18
+ * Rename: `Activerecord::SimpleIndexName` -> `ActiveRecord::SimpleIndexName`
19
+ * Other tiny refactorings
20
+ * https://github.com/sue445/activerecord-simple_index_name/pull/14
21
+ * https://github.com/sue445/activerecord-simple_index_name/pull/15
22
+ * https://github.com/sue445/activerecord-simple_index_name/pull/16
23
+
4
24
  ## v0.1.0
5
25
  * First release
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Activerecord::SimpleIndexName
1
+ # ActiveRecord::SimpleIndexName
2
2
 
3
3
  Shorten index name
4
4
 
@@ -8,7 +8,11 @@ Shorten index name
8
8
  [![Coverage Status](https://coveralls.io/repos/sue445/activerecord-simple_index_name/badge.svg?branch=master&service=github)](https://coveralls.io/github/sue445/activerecord-simple_index_name?branch=master)
9
9
  [![Code Climate](https://codeclimate.com/github/sue445/activerecord-simple_index_name/badges/gpa.svg)](https://codeclimate.com/github/sue445/activerecord-simple_index_name)
10
10
 
11
- ## Supported
11
+ ## Requirements
12
+ * Ruby 2.1+
13
+ * activerecord 4.0+
14
+
15
+ ## Supported frameworks
12
16
  * [Ruby on Rails](https://github.com/rails/rails)
13
17
  * [Padrino](https://github.com/padrino/padrino-framework)
14
18
  * or plain activerecord
@@ -47,6 +51,62 @@ add_index :user_stocks, [:user_id, :article_id]
47
51
  * Index name without `activerecord-simple_index_name` : `index_user_stocks_on_user_id_and_article_id`
48
52
  * Index name with `activerecord-simple_index_name` : `user_id_and_article_id`
49
53
 
54
+ ## Configurations
55
+ ### Usage
56
+
57
+ ```ruby
58
+ ActiveRecord::SimpleIndexName.config.auto_shorten = true
59
+ ```
60
+
61
+ or
62
+
63
+ ```ruby
64
+ ActiveRecord::SimpleIndexName.configure do |config|
65
+ config.auto_shorten = true
66
+ end
67
+ ```
68
+
69
+ * `auto_shorten` : Whether shorten index name
70
+ * `true` (default) : all index names are shorten (e.g. `user_id_and_article_id`)
71
+ * `false` : all index names are **not** shorten (e.g. `index_user_stocks_on_user_id_and_article_id`)
72
+
73
+
74
+ ## Opt-in/Opt-out
75
+ When `auto_shorten` is enabled, we can disable simple index name in only specified migration.
76
+ (or when `auto_shorten` is disabled, we can enable simple index name in only specified migration)
77
+
78
+ * `ActiveRecord::SimpleIndexName::EnableShorten`
79
+ * When include `ActiveRecord::SimpleIndexName::EnableShorten` in any migration file, enable simple index name
80
+ * `ActiveRecord::SimpleIndexName::DisableShorten`
81
+ * When include `ActiveRecord::SimpleIndexName::DisableShorten` in any migration file, disable simple index name
82
+
83
+ ### Opt-in Example
84
+ ```ruby
85
+ class AddCategoryIdToArticles < ActiveRecord::Migration
86
+ include Activerecord::SimpleIndexName::EnableShorten
87
+
88
+ def change
89
+ add_column :articles, :category_id, :integer
90
+ add_index :articles, :category_id
91
+ end
92
+ end
93
+ ```
94
+
95
+ include `ActiveRecord::SimpleIndexName::EnableShorten`, use simple index name regardless of whether `auto_shorten` is `true` or `false`
96
+
97
+ ### Opt-out Example
98
+ ```ruby
99
+ class AddArticleIndexToUserStocks < ActiveRecord::Migration
100
+ include ActiveRecord::SimpleIndexName::DisableShorten
101
+
102
+ def change
103
+ add_index :user_stocks, :article_id
104
+ end
105
+ end
106
+ ```
107
+
108
+ include `ActiveRecord::SimpleIndexName::DisableShorten`, don't use simple index name regardless of whether `auto_shorten` is `true` or `false`
109
+
50
110
  ## Development
51
111
 
52
112
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'activerecord/simple_index_name/version'
4
+ require 'active_record/simple_index_name/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "activerecord-simple_index_name"
8
- spec.version = Activerecord::SimpleIndexName::VERSION
8
+ spec.version = ActiveRecord::SimpleIndexName::VERSION
9
9
  spec.authors = ["sue445"]
10
10
  spec.email = ["sue445@sue445.net"]
11
11
 
@@ -20,10 +20,13 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "activerecord"
23
+ spec.add_dependency "activesupport"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.10"
25
26
  spec.add_development_dependency "coveralls"
26
27
  spec.add_development_dependency "codeclimate-test-reporter"
28
+ spec.add_development_dependency "pry-byebug"
29
+ spec.add_development_dependency "rails"
27
30
  spec.add_development_dependency "rake", "~> 10.0"
28
31
  spec.add_development_dependency "rspec"
29
32
  spec.add_development_dependency "rspec-power_assert"
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "activerecord/simple_index_name"
4
+ require "active_record/simple_index_name"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activerecord", "~> 4.0.0"
4
+ gem "activesupport", "~> 4.0.0"
5
+
6
+ gemspec path: '../'
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "activerecord", "~> 4.1.0"
4
+ gem "activesupport", "~> 4.1.0"
4
5
 
5
6
  gemspec path: '../'
@@ -1,5 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "activerecord", "~> 4.2.0"
4
+ gem "activesupport", "~> 4.2.0"
4
5
 
5
6
  gemspec path: '../'
@@ -0,0 +1,31 @@
1
+ require "active_record"
2
+ require "active_record/simple_index_name/version"
3
+ require "active_record/simple_index_name/configuration"
4
+ require "active_record/simple_index_name/disable_shorten"
5
+ require "active_record/simple_index_name/enable_shorten"
6
+
7
+ module ActiveRecord
8
+ module SimpleIndexName
9
+ def self.config
10
+ @config ||= Configuration.new
11
+ end
12
+
13
+ def self.configure
14
+ yield config if block_given?
15
+ end
16
+
17
+ def self.with_shorten(shorten)
18
+ Thread.current[:simple_index_name_shorten_mode] = shorten
19
+
20
+ yield if block_given?
21
+ ensure
22
+ Thread.current[:simple_index_name_shorten_mode] = nil
23
+ end
24
+ end
25
+ end
26
+
27
+ if defined?(Rails)
28
+ require "active_record/simple_index_name/railtie"
29
+ else
30
+ require "active_record/simple_index_name/active_record_ext"
31
+ end
@@ -0,0 +1,29 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module SchemaStatements
4
+ def index_name_with_simple(table_name, options)
5
+ shorten_mode =
6
+ case Thread.current[:simple_index_name_shorten_mode]
7
+ when :enable
8
+ true
9
+ when :disable
10
+ false
11
+ else
12
+ ActiveRecord::SimpleIndexName.config.auto_shorten
13
+ end
14
+
15
+ if shorten_mode
16
+ if Hash === options && options[:column]
17
+ Array.wrap(options[:column]) * "_and_"
18
+ else
19
+ index_name_without_simple(table_name, options)
20
+ end
21
+ else
22
+ index_name_without_simple(table_name, options)
23
+ end
24
+ end
25
+
26
+ alias_method_chain :index_name, :simple
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ module SimpleIndexName
3
+ require "active_support/configurable"
4
+
5
+ class Configuration
6
+ include ActiveSupport::Configurable
7
+
8
+ config_accessor :auto_shorten
9
+
10
+ configure do |config|
11
+ config.auto_shorten = true
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveRecord
2
+ module SimpleIndexName
3
+ module DisableShorten
4
+ def exec_migration(conn, direction)
5
+ ActiveRecord::SimpleIndexName.with_shorten(:disable) do
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveRecord
2
+ module SimpleIndexName
3
+ module EnableShorten
4
+ def exec_migration(conn, direction)
5
+ ActiveRecord::SimpleIndexName.with_shorten(:enable) do
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,9 +1,9 @@
1
- module Activerecord
1
+ module ActiveRecord
2
2
  module SimpleIndexName
3
3
  class Railtie < ::Rails::Railtie
4
4
  initializer "simple_index_name.initializer" do
5
5
  ActiveSupport.on_load(:active_record) do
6
- require "activerecord/simple_index_name/active_record_ext"
6
+ require "active_record/simple_index_name/active_record_ext"
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module SimpleIndexName
3
+ VERSION = "0.2.0.beta1"
4
+ end
5
+ end
@@ -1 +1 @@
1
- require "activerecord/simple_index_name"
1
+ require "active_record/simple_index_name"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-simple_index_name
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,34 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: rake
71
113
  requirement: !ruby/object:Gem::Requirement
@@ -141,13 +183,17 @@ files:
141
183
  - activerecord-simple_index_name.gemspec
142
184
  - bin/console
143
185
  - bin/setup
144
- - gemfiles/activerecord_4_1.gemfile
145
- - gemfiles/activerecord_4_2.gemfile
186
+ - gemfiles/rails_4_0.gemfile
187
+ - gemfiles/rails_4_1.gemfile
188
+ - gemfiles/rails_4_2.gemfile
189
+ - lib/active_record/simple_index_name.rb
190
+ - lib/active_record/simple_index_name/active_record_ext.rb
191
+ - lib/active_record/simple_index_name/configuration.rb
192
+ - lib/active_record/simple_index_name/disable_shorten.rb
193
+ - lib/active_record/simple_index_name/enable_shorten.rb
194
+ - lib/active_record/simple_index_name/railtie.rb
195
+ - lib/active_record/simple_index_name/version.rb
146
196
  - lib/activerecord-simple_index_name.rb
147
- - lib/activerecord/simple_index_name.rb
148
- - lib/activerecord/simple_index_name/active_record_ext.rb
149
- - lib/activerecord/simple_index_name/railtie.rb
150
- - lib/activerecord/simple_index_name/version.rb
151
197
  homepage: https://github.com/sue445/activerecord-simple_index_name
152
198
  licenses:
153
199
  - MIT
@@ -163,9 +209,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
209
  version: '0'
164
210
  required_rubygems_version: !ruby/object:Gem::Requirement
165
211
  requirements:
166
- - - ">="
212
+ - - ">"
167
213
  - !ruby/object:Gem::Version
168
- version: '0'
214
+ version: 1.3.1
169
215
  requirements: []
170
216
  rubyforge_project:
171
217
  rubygems_version: 2.4.5.1
@@ -1,13 +0,0 @@
1
- require "activerecord/simple_index_name/version"
2
- require "active_record"
3
-
4
- module Activerecord
5
- module SimpleIndexName
6
- end
7
- end
8
-
9
- if defined?(Rails)
10
- require "activerecord/simple_index_name/railtie"
11
- else
12
- require "activerecord/simple_index_name/active_record_ext"
13
- end
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module SchemaStatements
4
- def index_name_with_simple(table_name, options)
5
- if Hash === options && options[:column]
6
- Array.wrap(options[:column]) * "_and_"
7
- else
8
- index_name_without_simple(table_name, options)
9
- end
10
- end
11
-
12
- alias_method_chain :index_name, :simple
13
- end
14
- end
15
- end
@@ -1,5 +0,0 @@
1
- module Activerecord
2
- module SimpleIndexName
3
- VERSION = "0.1.0"
4
- end
5
- end