globalize_overlap_checker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1daf8e78b892e1d071bbf0e236a762c15cc6c371
4
+ data.tar.gz: 012d0041fa448a03ff565d360b220d84b2a51cb1
5
+ SHA512:
6
+ metadata.gz: 5ca79dff2411681bd4fe410d51ab2772ed2b605c3484ae1e6ecfda921ec97075fd82ee61fde9bd67b7199c1ca44c6d636ba8ea313aca3a8eb47502160dcd5814
7
+ data.tar.gz: cdf5b17964cf45df5454446d592ffb6198c0ff4f1886999aec8cebec612fb56969b07a813766ae1e327e247ffcadfea44ae9c0e539c951dc5970d7a34d206ffd
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ota42y@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in globalize_overlap_checker.gemspec
6
+ gemspec
@@ -0,0 +1,62 @@
1
+ # GlobalizeOverlapChecker
2
+
3
+ When there are table and model this.
4
+
5
+ ```ruby
6
+ class Post < ActiveRecord::Base
7
+ translates :name
8
+ end
9
+ ```
10
+
11
+ And if posts table have `name` column, globalize overlap this column by translate method.
12
+ In globalize 5.x, ActiveRecord's column data return overlaped column.
13
+ But globalize 5.1 or later, thease method doesn't return overlaped column.
14
+
15
+ And we shouldn't use overlaped column because its' difficult to understand.
16
+
17
+ This gem check overlaped columns and generate removing migration and raise error when thease migration exist.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'globalize_overlap_checker'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install globalize_overlap_checker
34
+
35
+ ## Usage
36
+
37
+ When you want to generate migration file.
38
+ ```bash
39
+ rake globalize_overlap_checker:generate_remove_overlap_migration
40
+ ```
41
+
42
+ If you want to raise error when overlaped, write this.
43
+ *If you want to generate migration, don't execute this*
44
+
45
+ ```
46
+ GlobalizeOverlapChecker.prohibition_overlap!
47
+ ```
48
+
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/globalize_overlap_checker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+ ## Code of Conduct
61
+
62
+ Everyone interacting in the GlobalizeOverlapChecker project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/globalize_overlap_checker/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "globalize_overlap_checker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "globalize_overlap_checker/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "globalize_overlap_checker"
8
+ spec.version = GlobalizeOverlapChecker::VERSION
9
+ spec.authors = ["ota42y"]
10
+ spec.email = ["ota42y@gmail.com"]
11
+
12
+ spec.summary = "raise error when duplicated tlanslate columns exist and generate remove migration"
13
+ spec.description = "raise error when duplicated tlanslate columns exist and generate remove migration"
14
+ spec.homepage = "https://ota42y.com"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "globalize", ">=5.1.0.beta1"
24
+ spec.add_dependency "activerecord"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
@@ -0,0 +1,47 @@
1
+ require "globalize_overlap_checker/version"
2
+ require "globalize_overlap_checker/globalize/acto_macro"
3
+
4
+ module GlobalizeOverlapChecker
5
+ class GlobalizeOverlapError < StandardError; end
6
+ class MyRailtie < Rails::Railtie
7
+ rake_tasks do
8
+ load "tasks/generate_remove_overlap_migration.rake"
9
+ end
10
+ end
11
+
12
+ @prohibition_overlap = false
13
+
14
+ class << self
15
+ def prohibition_overlap?
16
+ @prohibition_overlap
17
+ end
18
+
19
+ def prohibition_overlap!
20
+ @prohibition_overlap = true
21
+ end
22
+
23
+ def add_overlap_model(table_name, overlap)
24
+ @overlap_models = [] unless defined?(@overlap_models)
25
+ @overlap_models << { table_name: table_name, overlap: overlap }
26
+ end
27
+
28
+ def generate_migration(output_filepath)
29
+ Rails.application.eager_load!
30
+
31
+ migration_heads = [
32
+ "class RemoveGlobalizeOverlapMigration < ActiveRecord::Migration",
33
+ " def change"
34
+ ]
35
+
36
+ migration_tails = [" end",
37
+ "end"]
38
+
39
+ sorted_tables = @overlap_models.compact.sort_by { |d| d[:table_name] }
40
+ migration = (migration_heads +
41
+ sorted_tables.map { |d| " remove_columns :#{d[:table_name].to_sym}, #{d[:overlap].map{ |c| ":#{c}"}.join(", ")}" } +
42
+ migration_tails).flatten
43
+
44
+ open(output_filepath, 'w') { |f| f.write(migration.join("\n")) }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ require 'globalize'
2
+ require 'active_record'
3
+
4
+ module Globalize
5
+ module ActiveRecord
6
+ module ActMacro
7
+
8
+ protected
9
+
10
+ def globalize_overlap_checker_check_columns!(attr_names)
11
+ if table_exists? && translation_class.table_exists? && (overlap = attr_names.map(&:to_s) & column_names).present?
12
+ if ::GlobalizeOverlapChecker.prohibition_overlap?
13
+ raise ::GlobalizeOverlapChecker::GlobalizeOverlapError.
14
+ new("overlap translate columns!\nModel name (table name): #{model_name} (#{table_name})\nAttribute name(s): #{overlap.join(', ')}\n")
15
+ else
16
+ ::GlobalizeOverlapChecker.add_overlap_model(table_name, overlap)
17
+ end
18
+ end
19
+
20
+ globalize_overlap_checker_original_check_columns!(attr_names)
21
+ end
22
+
23
+ alias_method :globalize_overlap_checker_original_check_columns!, :check_columns!
24
+ alias_method :check_columns!, :globalize_overlap_checker_check_columns!
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module GlobalizeOverlapChecker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ namespace :globalize_overlap_checker do
2
+ desc "generate_remove_overlap_migration"
3
+ task :generate_remove_overlap_migration => :environment do
4
+ filepath = "db/migrate/#{DateTime.now.strftime("%Y%m%d%H%M%S")}_remove_globalize_overlap_migration.rb"
5
+ ::GlobalizeOverlapChecker.generate_migration(filepath)
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: globalize_overlap_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ota42y
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: globalize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0.beta1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.0.beta1
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: raise error when duplicated tlanslate columns exist and generate remove
70
+ migration
71
+ email:
72
+ - ota42y@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - globalize_overlap_checker.gemspec
85
+ - lib/globalize_overlap_checker.rb
86
+ - lib/globalize_overlap_checker/globalize/acto_macro.rb
87
+ - lib/globalize_overlap_checker/version.rb
88
+ - lib/tasks/generate_remove_overlap_migration.rake
89
+ homepage: https://ota42y.com
90
+ licenses: []
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.6.13
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: raise error when duplicated tlanslate columns exist and generate remove migration
112
+ test_files: []