web-connect 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7b6165c1609c61f31bdc2da429040c476f0f7bf
4
- data.tar.gz: 69f1ff505d4ccf3d6321d891b665f81ac96c4482
3
+ metadata.gz: 2d6d07bce951df691ca0c55dd4aefbcf9820268b
4
+ data.tar.gz: f9b7d39e82d2c54287615ffbe3cec4cb2bbbcfdb
5
5
  SHA512:
6
- metadata.gz: 42793ad4d2d3806fd64c73ec47e31be5c3824bea42dbbec5f35f21150e9a9b231830bf928aa0196c6e383da4589898f85c1f2398b5813b63e176c82021297ecd
7
- data.tar.gz: 97f707bfb922fd415a4817934ffb8e0a83b703b2b06b432ecba679778a4bf040aeb551972b950c098df0eb8bc13385fde5f3888439be73913d368c76eee09214
6
+ metadata.gz: 542d2b415f376a97444957d3703ca2a75a547de472532822f71e1b9a146487eda1a64de6364578e86dfb79111532d2346b30d8596933cdf533bc320e48c43ba1
7
+ data.tar.gz: 53396060972b9f7c7ddd5ea8270c7335e924802cff72c80d908870d468b54ca0fe9279d6a9cf08aee35fd5d96c497758d36dbe4a49464e75a9fe762d104d9ad0
@@ -16,6 +16,7 @@ module Netfira::WebConnect
16
16
  value = Checksum.new(value) if value and (key == 'checksum' or key == 'digest')
17
17
  [key, value]
18
18
  end.to_h
19
+ previous.merge! previous_translations if previous && has_languages?
19
20
  yield
20
21
  as_readonly do
21
22
  if previous
@@ -22,12 +22,38 @@ module Netfira::WebConnect
22
22
  shop.locale
23
23
  end
24
24
 
25
+ def [](key)
26
+ if translated_attribute_names.include? key.to_s
27
+ get_translated_string key.to_sym
28
+ else
29
+ super key
30
+ end
31
+ end
32
+
33
+ def []=(key, value)
34
+ if translated_attribute_names.include? key.to_s
35
+ set_translated_string key.to_sym, value
36
+ else
37
+ super key, value
38
+ end
39
+ end
40
+
25
41
  private
26
42
 
27
43
  def translations
28
44
  @translations ||= translation_models.map{ |model| [model.language, model]}.to_h
29
45
  end
30
46
 
47
+ def previous_translations
48
+ Hash.new { |hash, k| hash[k] = {} }.tap do |result|
49
+ translations.each do |language, translation|
50
+ translation.changed_attributes.each do |attr, value|
51
+ result[attr][language] = value if translation.class.translated_attribute_names.include? attr
52
+ end
53
+ end
54
+ end
55
+ end
56
+
31
57
  def translated_strings
32
58
  @translated_strings ||= {}
33
59
  end
@@ -58,6 +84,10 @@ module Netfira::WebConnect
58
84
  self
59
85
  end
60
86
 
87
+ def translated_attribute_names
88
+ self.class::Translation.translated_attribute_names
89
+ end
90
+
61
91
  end
62
92
  end
63
93
  end
@@ -1,6 +1,6 @@
1
1
  module Netfira
2
2
  module WebConnect
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.2'
4
4
  PLATFORM_AND_VERSION = 'Rack/' << VERSION
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-31 00:00:00.000000000 Z
12
+ date: 2014-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord