mongoid_denormalize 0.2.2 → 0.3.0

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.
Files changed (2) hide show
  1. data/lib/mongoid_denormalize.rb +21 -4
  2. metadata +6 -6
@@ -36,6 +36,10 @@ module Mongoid::Denormalize
36
36
  fields.each { |name| field "#{options[:from]}_#{name}", :type => options[:type] || String }
37
37
  end
38
38
  end
39
+
40
+ def is_denormalized?
41
+ true
42
+ end
39
43
  end
40
44
 
41
45
  def denormalized_valid?
@@ -46,7 +50,7 @@ module Mongoid::Denormalize
46
50
  def repair_denormalized!
47
51
  self.save! unless denormalized_valid?
48
52
  end
49
-
53
+
50
54
  private
51
55
  def denormalize_from
52
56
  self.denormalize_definitions.each do |definition|
@@ -66,15 +70,28 @@ module Mongoid::Denormalize
66
70
  relation = []
67
71
  reflect = self.class.reflect_on_association(association)
68
72
  relation = reflect.relation.macro unless reflect.nil? || reflect.relation.nil?
69
-
73
+
74
+ reflect.klass.skip_callback(:save, :before, :denormalize_from) if reflect.klass.try(:is_denormalized?)
75
+
70
76
  if [:embedded_in, :embeds_one, :referenced_in, :references_one, :has_one, :belongs_to].include? relation
71
77
  c = self.send(association)
72
78
 
73
- c.update_attributes(assigns) unless c.blank?
79
+ unless c.blank?
80
+ assigns.each { |assign| c.send("#{assign[0]}=", assign[1]) }
81
+
82
+ c.save
83
+ end
74
84
  else
75
85
  c = self.send(association)
76
- c.to_a.each { |a| a.update_attributes(assigns) }
86
+
87
+ c.to_a.each do |a|
88
+ assigns.each { |assign| a.send("#{assign[0]}=", assign[1]) }
89
+
90
+ a.save
91
+ end
77
92
  end
93
+
94
+ reflect.klass.set_callback(:save, :before, :denormalize_from) if reflect.klass.try(:is_denormalized?)
78
95
  end
79
96
  end
80
97
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Logan Raarup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-08-04 00:00:00 +02:00
17
+ date: 2012-02-05 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -41,11 +41,11 @@ extra_rdoc_files:
41
41
  - LICENSE
42
42
  - README.md
43
43
  files:
44
- - LICENSE
45
- - README.md
46
44
  - lib/mongoid_denormalize.rb
47
45
  - lib/railties/denormalize.rake
48
46
  - lib/railties/railtie.rb
47
+ - LICENSE
48
+ - README.md
49
49
  has_rdoc: true
50
50
  homepage: http://github.com/logandk/mongoid_denormalize
51
51
  licenses: []