i18n-sequel_bitemporal 1.0.0 → 1.0.3
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/.ruby-version +1 -1
- data/.travis.yml +3 -2
- data/i18n-sequel_bitemporal.gemspec +1 -1
- data/lib/i18n/backend/sequel_bitemporal.rb +12 -1
- data/lib/i18n/sequel_bitemporal/version.rb +1 -1
- data/test/sequel_test.rb +33 -0
- data/test/test_helper.rb +1 -0
- metadata +20 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57e9252a463de8d43116d067cbe849cdf70a9647e8b7a3cb2dcdbc1016d86317
|
4
|
+
data.tar.gz: 6d504736bf4b6e300807bd9973049b3dcebcb3799f5ba9c61aa013374f8aa839
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19b6b5aade339b69265e235d812a1d488a3e0494b1816dd248023ac8d1022183ef86c1c8ae8f44cbbc304047917ecece3322c470f64d08398c1216b3c0bcf3df
|
7
|
+
data.tar.gz: 93a7efa3a130e5f4ef83ea6bc8804234380aca8df3d6f785b518c0130841a7136db177bc4b81f6e36a2949459d42598b176fce722e1a68c8e103c23bc645b94f
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.3
|
data/.travis.yml
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://github.com/TalentBox/i18n-sequel_bitemporal"
|
11
11
|
s.summary = "I18n Bitemporal Sequel backend"
|
12
12
|
s.description = "I18n Bitemporal Sequel backend. Allows to store translations in a database using Sequel using a bitemporal approach, e.g. for providing a web-interface for managing translations."
|
13
|
-
s.rubyforge_project = "[none]"
|
14
13
|
|
15
14
|
s.platform = Gem::Platform::RUBY
|
16
15
|
|
@@ -21,4 +20,5 @@ Gem::Specification.new do |s|
|
|
21
20
|
|
22
21
|
s.add_dependency "i18n", ">= 1.0.0"
|
23
22
|
s.add_dependency "sequel_bitemporal", ">= 0.8.0"
|
23
|
+
s.add_dependency "activesupport", ">= 4.0.2"
|
24
24
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'i18n/backend/base'
|
2
|
+
require 'active_support/core_ext/hash/keys'
|
2
3
|
|
3
4
|
module I18n
|
4
5
|
module Backend
|
@@ -24,6 +25,7 @@ module I18n
|
|
24
25
|
end
|
25
26
|
|
26
27
|
module Implementation
|
28
|
+
using I18n::HashRefinements if defined?(I18n::HashRefinements)
|
27
29
|
include Base, Flatten
|
28
30
|
|
29
31
|
def initialize(opts= {})
|
@@ -42,6 +44,8 @@ module I18n
|
|
42
44
|
|
43
45
|
def store_translations(locale, data, options = {})
|
44
46
|
escape = options.fetch(:escape, true)
|
47
|
+
point_in_time_for_new = options[:point_in_time_for_new]
|
48
|
+
valid_from_for_new = options[:valid_from_for_new]
|
45
49
|
flatten_translations(locale, data, escape, false).each do |key, value|
|
46
50
|
# Invalidate all keys matching current one:
|
47
51
|
# key = foo.bar invalidates foo, foo.bar and foo.bar.*
|
@@ -52,7 +56,14 @@ module I18n
|
|
52
56
|
translation = Translation.locale(locale).lookup_exactly(expand_keys(key)).limit(1).all.first ||
|
53
57
|
Translation.new(:locale => locale.to_s, :key => key.to_s)
|
54
58
|
translation.attributes = {:value => value}
|
55
|
-
translation.
|
59
|
+
translation.attributes[:valid_from] = valid_from_for_new if translation.new?
|
60
|
+
if point_in_time_for_new && translation.new?
|
61
|
+
::Sequel::Plugins::Bitemporal.as_we_knew_it point_in_time_for_new do
|
62
|
+
translation.save
|
63
|
+
end
|
64
|
+
else
|
65
|
+
translation.save
|
66
|
+
end
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
data/test/sequel_test.rb
CHANGED
@@ -52,6 +52,39 @@ class I18nBackendSequelBitemporalTest < I18nBitemporalTest
|
|
52
52
|
assert_equal [], translations.map(&:value)
|
53
53
|
end
|
54
54
|
|
55
|
+
test "use today as the default valid from for the new translation" do
|
56
|
+
I18n.backend.store_translations(:es, {:"Pagina's" => "Pagina's"} )
|
57
|
+
translation = I18n::Backend::SequelBitemporal::Translation.locale(:es).lookup("Pagina's").limit(1).all.first
|
58
|
+
assert_equal "Pagina's", translation.value
|
59
|
+
assert_equal Date.today, translation.current_version.valid_from
|
60
|
+
end
|
61
|
+
|
62
|
+
test "can specify valid from for the new translation" do
|
63
|
+
valid_from_for_new = Date.parse("2001-01-01")
|
64
|
+
I18n.backend.store_translations(:es, {:"Pagina's" => "Pagina's"}, valid_from_for_new: valid_from_for_new )
|
65
|
+
translation = I18n::Backend::SequelBitemporal::Translation.locale(:es).lookup("Pagina's").limit(1).all.first
|
66
|
+
assert_equal "Pagina's", translation.value
|
67
|
+
assert_equal valid_from_for_new, translation.current_version.valid_from
|
68
|
+
end
|
69
|
+
|
70
|
+
test "can specify point in time for the new translation" do
|
71
|
+
point_in_time_for_new = Time.parse("2001-01-01T12:00:00Z")
|
72
|
+
I18n.backend.store_translations(:es, {:"Pagina's" => "Pagina's"}, point_in_time_for_new: point_in_time_for_new )
|
73
|
+
translation = I18n::Backend::SequelBitemporal::Translation.locale(:es).lookup("Pagina's").limit(1).all.first
|
74
|
+
assert_equal "Pagina's", translation.value
|
75
|
+
assert_equal point_in_time_for_new, translation.current_version.created_at
|
76
|
+
end
|
77
|
+
|
78
|
+
test "can specify both point in time and valid_from for the new translation" do
|
79
|
+
point_in_time_for_new = Time.parse("2001-01-01T12:00:00Z")
|
80
|
+
valid_from_for_new = Date.parse("2001-01-01")
|
81
|
+
I18n.backend.store_translations(:es, {:"Pagina's" => "Pagina's"}, point_in_time_for_new: point_in_time_for_new, valid_from_for_new: valid_from_for_new )
|
82
|
+
translation = I18n::Backend::SequelBitemporal::Translation.locale(:es).lookup("Pagina's").limit(1).all.first
|
83
|
+
assert_equal "Pagina's", translation.value
|
84
|
+
assert_equal point_in_time_for_new, translation.current_version.created_at
|
85
|
+
assert_equal valid_from_for_new, translation.current_version.valid_from
|
86
|
+
end
|
87
|
+
|
55
88
|
with_mocha do
|
56
89
|
test "missing translations table does not cause an error in #available_locales" do
|
57
90
|
I18n::Backend::SequelBitemporal::Translation.expects(:available_locales).raises(::Sequel::Error)
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-sequel_bitemporal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Tron
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.2
|
41
55
|
description: I18n Bitemporal Sequel backend. Allows to store translations in a database
|
42
56
|
using Sequel using a bitemporal approach, e.g. for providing a web-interface for
|
43
57
|
managing translations.
|
@@ -74,7 +88,7 @@ files:
|
|
74
88
|
homepage: http://github.com/TalentBox/i18n-sequel_bitemporal
|
75
89
|
licenses: []
|
76
90
|
metadata: {}
|
77
|
-
post_install_message:
|
91
|
+
post_install_message:
|
78
92
|
rdoc_options: []
|
79
93
|
require_paths:
|
80
94
|
- lib
|
@@ -89,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
103
|
- !ruby/object:Gem::Version
|
90
104
|
version: '0'
|
91
105
|
requirements: []
|
92
|
-
|
93
|
-
|
94
|
-
signing_key:
|
106
|
+
rubygems_version: 3.3.7
|
107
|
+
signing_key:
|
95
108
|
specification_version: 4
|
96
109
|
summary: I18n Bitemporal Sequel backend
|
97
110
|
test_files:
|