localizable_db 1.0.3 → 1.0.4

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
  SHA256:
3
- metadata.gz: 31e7f15049877054ce397628c917f921cdc4074921babde61fd6fd8e5b343cdc
4
- data.tar.gz: eb30572262c710f71d22d8664869ef8a8064f81d6ddb9c9afef62798147a7117
3
+ metadata.gz: 6d0119e727257691483d9321ca6f86f138818d73a97906607fa0fa99956123c1
4
+ data.tar.gz: 165c8c4a035498c6e6592b911d628906b74abe87cbb2ef386d09d96a3aa12c34
5
5
  SHA512:
6
- metadata.gz: c020d11f3ed427183a59cecaee40356c2a9e1946f8f286314d5e9b639bdcb04cec44189b7100902006a28b70c20035d9f05f125977d9c158266da4af5acac713
7
- data.tar.gz: 01b0bc39b12189f334dd333bde061d5d4ea7eac81120f12749b3babc54f4423d81151b19bd1880019b4b3757b3debc7b0dace87135f4c654f87901cc4762ba09
6
+ metadata.gz: 854eca87de0935b2863adfb45ffbc11b47b0103f8793702bdf30fa13f8ded8ca166d101f41341033c915b16811536521e5cc1a2a0990fc794893acc6f3cd1662
7
+ data.tar.gz: 27d8fedcf72a998505e98fe3407b773eba879e8fc55a5007f445ec147bd67b154089fbe5b502cd2b8e978ab9c6372a3b91b337362ddde5ad1cfe7de7453e49f7
data/README.md CHANGED
@@ -95,6 +95,15 @@ product = Product.l(:fr).find(3)
95
95
  product.inspect
96
96
  #=> #<Product id: 3, name: "l'amour">
97
97
  ````
98
+ Destroying
99
+ ````ruby
100
+ Product.find(1).destroy
101
+ # begin transaction
102
+ # SELECT "product_languages".* FROM "product_languages" WHERE "product_languages"."localizable_object_id" = ? [["localizable_object_id", 1]]
103
+ # DELETE FROM "product_languages" WHERE "product_languages"."id" = ? [["id", 1]]
104
+ # DELETE FROM "products" WHERE "products"."id" = ? [["id", 1]]
105
+ # commit transaction
106
+ ````
98
107
  Eager loading support
99
108
  ````ruby
100
109
  products = Product.includes(:features).where(id: 1)
@@ -16,13 +16,23 @@ module LocalizableDb
16
16
  aux_object.send(:"#{attribute}=", language_values[attribute.to_sym])
17
17
  end
18
18
  aux_object.localizable_object_id = self.id
19
+ validators_copy = aux_object._validators.dup
20
+ validators_to_remove = aux_object._validators.keys - self.class.localized_attributes.map{|attribute| attribute.to_sym}
21
+ validators_to_remove.each do |validator|
22
+ aux_object._validators.delete(validator)
23
+ end
24
+ aux_object._validators.values.each do |validator_value|
25
+ validators_to_remove.each{|validator| validator_value.flatten.first.attributes.delete(validator) }
26
+ end
19
27
  aux_object.save
28
+ aux_object._validators.merge(validators_copy)
20
29
  aux_object.errors.messages.each do |err_key,err_message|
21
30
  self.errors.add("#{language_key}_#{err_key}", err_message)
22
31
  end if aux_object.errors.any?
23
32
  aux_object
24
33
  end
25
34
  self.class.table_name = self.class.name.pluralize.dasherize.downcase
35
+ raise ActiveRecord::Rollback, "Languages error" if self.errors.any?
26
36
  end
27
37
  ensure
28
38
  self.class.table_name = self.class.name.pluralize.dasherize.downcase
@@ -1,3 +1,3 @@
1
1
  module LocalizableDb
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localizable_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yonga9121
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-08 00:00:00.000000000 Z
12
+ date: 2018-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails