translateable 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/gemfiles/6.0.gemfile +6 -0
- data/lib/generators/translateable/migration_generator.rb +2 -17
- data/lib/generators/translateable/templates/migration.rb.erb +4 -4
- data/lib/translateable.rb +0 -3
- data/lib/translateable/version.rb +1 -1
- data/translateable.gemspec +3 -4
- metadata +12 -28
- data/.rubocop.yml +0 -18
- data/gemfiles/4.2.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f1c8fd60b4fc6af2bc16471c0655015bebfb2b9e6d80ac24ee4a23fb5fbfa7d
|
4
|
+
data.tar.gz: fbf64c55adb25358e0340857780eed1df75e1f63852cf30b203c2752d85e4a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd28660d2d526157247283ecb8ef127dea68a3b46eef1d5349d578967da848ed04ef711093afcb2e6021770d7b4b25763262fd6ee71b4eb4eafd969596851fba
|
7
|
+
data.tar.gz: c08ec3530d7997f823d8aa4f278b35ea52d8bc17ebf305e4e3ab8350cfed784d30da018588b8043cae086fd7db111c881203c8eb1bb0985b78a80e143c66d804
|
data/.travis.yml
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.2.2
|
4
3
|
- 2.5.0
|
4
|
+
- 2.6.1
|
5
5
|
|
6
6
|
gemfile:
|
7
|
-
- gemfiles/4.2.gemfile
|
8
7
|
- gemfiles/5.0.gemfile
|
9
8
|
- gemfiles/5.2.gemfile
|
9
|
+
- gemfiles/6.0.gemfile
|
10
10
|
|
11
11
|
script:
|
12
12
|
- bundle exec rspec
|
13
|
-
- bundle exec rubocop
|
14
13
|
|
15
14
|
before_install: gem install bundler
|
16
15
|
|
@@ -10,30 +10,15 @@ if defined?(Rails)
|
|
10
10
|
argument :field_name, type: :string
|
11
11
|
argument :locale, type: :string, default: I18n.default_locale
|
12
12
|
|
13
|
-
# rubocop: disable Metrics/AbcSize
|
14
13
|
def create_migration_file
|
15
14
|
raise ArgumentError, "given locale #{locale} is not available, check I18n.available_locales" unless I18n.available_locales.include?(locale.to_sym)
|
16
|
-
migration_template('migration.rb.erb', "db/migrate/migrate_translateable_#{
|
17
|
-
migration_version: migration_version,
|
18
|
-
table_name: name,
|
19
|
-
field_name: field_name,
|
20
|
-
field_type: name.classify.constantize.columns_hash[field_name].type,
|
21
|
-
locale: locale)
|
15
|
+
migration_template('migration.rb.erb', "db/migrate/migrate_translateable_#{table_name}_#{field_name}.rb", migration_version: migration_version)
|
22
16
|
end
|
23
|
-
# rubocop: enable Metrics/AbcSize
|
24
17
|
|
25
18
|
private
|
26
19
|
|
27
|
-
def rails5?
|
28
|
-
Rails.version.start_with?('5')
|
29
|
-
end
|
30
|
-
|
31
20
|
def migration_version
|
32
|
-
|
33
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
34
|
-
else
|
35
|
-
''
|
36
|
-
end
|
21
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
37
22
|
end
|
38
23
|
end
|
39
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class MigrateTranslateable<%= table_name.
|
1
|
+
class MigrateTranslateable<%= table_name.capitalize + field_name.capitalize %> < ActiveRecord::Migration<%= migration_version %>
|
2
2
|
def change
|
3
3
|
reversible do |dir|
|
4
4
|
dir.up do
|
@@ -13,13 +13,13 @@ class MigrateTranslateable<%= table_name.camelize + field_name.camelize %> < Act
|
|
13
13
|
SQL
|
14
14
|
remove_column :<%= table_name %>, :<%= field_name %>
|
15
15
|
rename_column :<%= table_name %>, :<%= field_name + '_t' %>, :<%= field_name %>
|
16
|
-
<% if index_exists?(table_name, field_name) %>
|
16
|
+
<% if ActiveRecord::Base.connection.index_exists?(table_name, field_name) %>
|
17
17
|
add_index :<%= table_name %>, :<%= field_name %>, using: :gin
|
18
18
|
<% end %>
|
19
19
|
end
|
20
20
|
|
21
21
|
dir.down do
|
22
|
-
add_column :<%= table_name %>, :<%= field_name + '_t' %>,
|
22
|
+
add_column :<%= table_name %>, :<%= field_name + '_t' %>, :string, null: false, default: ''
|
23
23
|
execute <<-SQL
|
24
24
|
UPDATE <%= table_name %> AS m1
|
25
25
|
SET <%= field_name + '_t' %> = (
|
@@ -28,7 +28,7 @@ class MigrateTranslateable<%= table_name.camelize + field_name.camelize %> < Act
|
|
28
28
|
SQL
|
29
29
|
remove_column :<%= table_name %>, :<%= field_name %>
|
30
30
|
rename_column :<%= table_name %>, :<%= field_name + '_t' %>, :<%= field_name %>
|
31
|
-
<% if index_exists?(table_name, field_name) %>
|
31
|
+
<% if ActiveRecord::Base.connection.index_exists?(table_name, field_name) %>
|
32
32
|
add_index :<%= table_name %>, :<%= field_name %>
|
33
33
|
<% end %>
|
34
34
|
end
|
data/lib/translateable.rb
CHANGED
@@ -23,7 +23,6 @@ module Translateable
|
|
23
23
|
return unless database_connection_exists?
|
24
24
|
attr = attr.to_s
|
25
25
|
raise ArgumentError, "no such column '#{attr}' in '#{name}' model" unless column_names.include?(attr)
|
26
|
-
raise ArgumentError, "'#{attr}' column must be of JSONB type" unless columns_hash[attr].type.to_s.casecmp('jsonb').zero?
|
27
26
|
end
|
28
27
|
|
29
28
|
def define_translateable_strong_params(*attrs)
|
@@ -38,7 +37,6 @@ module Translateable
|
|
38
37
|
false
|
39
38
|
end
|
40
39
|
|
41
|
-
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
42
40
|
def define_translateable_methods(attr)
|
43
41
|
define_method("#{attr}_fetch_translateable") do
|
44
42
|
value = self[attr]
|
@@ -69,6 +67,5 @@ module Translateable
|
|
69
67
|
self[attr] = value
|
70
68
|
end
|
71
69
|
end
|
72
|
-
# rubocop: enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
73
70
|
end
|
74
71
|
end
|
data/translateable.gemspec
CHANGED
@@ -18,13 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = %w(lib)
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
-
spec.add_development_dependency 'rubocop'
|
25
24
|
|
26
|
-
spec.add_dependency 'activerecord', '>=
|
27
|
-
spec.add_dependency 'activesupport', '>=
|
25
|
+
spec.add_dependency 'activerecord', '>= 5.0'
|
26
|
+
spec.add_dependency 'activesupport', '>= 5.0'
|
28
27
|
spec.add_dependency 'i18n'
|
29
28
|
spec.add_dependency 'pg'
|
30
29
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translateable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Antonyan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,48 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: activerecord
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '5.0'
|
76
62
|
type: :runtime
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '5.0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: activesupport
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '5.0'
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - ">="
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '5.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: i18n
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,7 +118,6 @@ extra_rdoc_files: []
|
|
132
118
|
files:
|
133
119
|
- ".gitignore"
|
134
120
|
- ".rspec"
|
135
|
-
- ".rubocop.yml"
|
136
121
|
- ".travis.yml"
|
137
122
|
- CODE_OF_CONDUCT.md
|
138
123
|
- Gemfile
|
@@ -141,9 +126,9 @@ files:
|
|
141
126
|
- Rakefile
|
142
127
|
- bin/console
|
143
128
|
- bin/setup
|
144
|
-
- gemfiles/4.2.gemfile
|
145
129
|
- gemfiles/5.0.gemfile
|
146
130
|
- gemfiles/5.2.gemfile
|
131
|
+
- gemfiles/6.0.gemfile
|
147
132
|
- lib/generators/translateable/migration_generator.rb
|
148
133
|
- lib/generators/translateable/templates/migration.rb.erb
|
149
134
|
- lib/translateable.rb
|
@@ -168,8 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
153
|
- !ruby/object:Gem::Version
|
169
154
|
version: '0'
|
170
155
|
requirements: []
|
171
|
-
|
172
|
-
rubygems_version: 2.7.3
|
156
|
+
rubygems_version: 3.0.3
|
173
157
|
signing_key:
|
174
158
|
specification_version: 4
|
175
159
|
summary: Allows to store text data in different languages.
|
data/.rubocop.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
Style/Documentation:
|
2
|
-
Enabled: false
|
3
|
-
|
4
|
-
Metrics/LineLength:
|
5
|
-
Max: 162
|
6
|
-
|
7
|
-
Style/Lambda:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
Style/FrozenStringLiteralComment:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
Style/PercentLiteralDelimiters:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Metrics/BlockLength:
|
17
|
-
Exclude:
|
18
|
-
- 'spec/**/*'
|