translateable 0.1.4 → 0.1.5
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 +4 -4
- data/.rubocop.yml +4 -0
- data/README.md +1 -1
- data/lib/translateable.rb +7 -0
- data/lib/translateable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e12b39f79599cd0ee0824bd36c1dccc248af77f
|
4
|
+
data.tar.gz: fcd42bc9f98f5d28e02088be3b61771c7f627ccf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a862624f81082209bc850a0e033c124983e2f1d01bfdb093beace015a9272a15a5138b3eb0afc08ac0cfaafbac815b79a8da108e8d9115f2808fd0af08d2d130
|
7
|
+
data.tar.gz: 4823cc44b1eaab551fcb820869b1a3f823ab17495c34583ba0c9f5b32a284a17f489e85ad36578734cab1b0d61baa0c012136b25825c1cf1fff82bff86742117
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -147,7 +147,7 @@ Attributes must exist with `JSONB` type in a database, so create a migration:
|
|
147
147
|
```ruby
|
148
148
|
class AddTitleToPosts < ActiveRecord::Migration
|
149
149
|
def change
|
150
|
-
add_column :posts, :title, :jsonb, null: false, default:
|
150
|
+
add_column :posts, :title, :jsonb, null: false, default: {}
|
151
151
|
end
|
152
152
|
end
|
153
153
|
```
|
data/lib/translateable.rb
CHANGED
@@ -19,6 +19,7 @@ module Translateable
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def translateable_sanity_check(attr)
|
22
|
+
return unless database_connection_exists?
|
22
23
|
attr = attr.to_s
|
23
24
|
raise ArgumentError, "no such column '#{attr}' in '#{name}' model" unless column_names.include?(attr)
|
24
25
|
raise ArgumentError, "'#{attr}' column must be of JSONB type" unless columns_hash[attr].type.to_s.casecmp('jsonb').zero?
|
@@ -30,6 +31,12 @@ module Translateable
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
def database_connection_exists?
|
35
|
+
ActiveRecord::Base.connection_pool.with_connection(&:active?)
|
36
|
+
rescue
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
33
40
|
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
34
41
|
def define_translateable_methods(attr)
|
35
42
|
define_method("#{attr}_fetch_translateable") do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translateable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
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: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.6.8
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: Allows to store text data in different languages.
|