i18n-sequel_bitemporal 1.0.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f731e3323b34e7a0253dee70fbd08d2dd8cff9b3589347908663d8905840baff
4
- data.tar.gz: d42a2810825195aec26371edd59724e1058b994c8c8215f56cd9b5595272072a
3
+ metadata.gz: 57e9252a463de8d43116d067cbe849cdf70a9647e8b7a3cb2dcdbc1016d86317
4
+ data.tar.gz: 6d504736bf4b6e300807bd9973049b3dcebcb3799f5ba9c61aa013374f8aa839
5
5
  SHA512:
6
- metadata.gz: da5c601442f074c486ff12ddae35576a73bdc33ad269b9a1463360d404dbce1d8843215db794e079046b8b85d8571a376c2a57ad25f966b554e9a43853ac783d
7
- data.tar.gz: 4467d7ffa4f04ada44ac4df07906ae17c2ae2e49b4fbd6714d4910503a456be800a2f6918b769e75b84511030203ab7e3ef2db508edf5de9c3b9e4c49af0c465
6
+ metadata.gz: 19b6b5aade339b69265e235d812a1d488a3e0494b1816dd248023ac8d1022183ef86c1c8ae8f44cbbc304047917ecece3322c470f64d08398c1216b3c0bcf3df
7
+ data.tar.gz: 93a7efa3a130e5f4ef83ea6bc8804234380aca8df3d6f785b518c0130841a7136db177bc4b81f6e36a2949459d42598b176fce722e1a68c8e103c23bc645b94f
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.1
1
+ 2.6.3
data/.travis.yml CHANGED
@@ -5,8 +5,9 @@ before_script:
5
5
  - psql -c 'create database i18n_sequel_bitemporal;' -U postgres
6
6
  rvm:
7
7
  - 2.3.8
8
- - 2.4.5
9
- - 2.5.3
8
+ - 2.4.6
9
+ - 2.5.5
10
+ - 2.6.3
10
11
  env:
11
12
  - ADAPTER=sqlite3
12
13
  - ADAPTER=postgres
@@ -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.save
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
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module SequelBitemporal
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  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
@@ -1,3 +1,4 @@
1
+ ENV["TZ"] = "UTC"
1
2
  $:.unshift File.expand_path(".", File.dirname(__FILE__))
2
3
 
3
4
  require 'test_setup'
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.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: 2018-12-05 00:00:00.000000000 Z
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
- rubyforge_project: "[none]"
93
- rubygems_version: 2.7.6
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: