denormalize_mm 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/mongo_mapper/denormalization.rb +14 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODJjYmQwYmVhMWQxYzk5N2YxMjlmOTJjNDdlYTE1N2ZlOGE5MDk3Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWMxNGM2MGJmMGRlMzhhMWFhMGFkNTYzMmViNDIyOGVhOTdlMjhjMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDJlNTg1MGY3YTJjM2I3ODQ2NjQwZmEwOTFlM2Y3Y2FiOGFjZmI3MDJjM2E4
|
10
|
+
NGM1MjA1Zjk3Njc5YTY4MjhmN2QyYWJhMGM1MjlmMGI1NTI5OWQzOTAwMDBj
|
11
|
+
YTk2OGJhMDUyMmZiNmY3ZWVmZmY3OWZmMDYyMjdmOTYyZDliYjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTNiNjFkOGJjZDBjYWNlOWY2YThhZjFkNjgyMTZlYmQ5OTljZGEyN2IyODM1
|
14
|
+
Y2I4ZjlkZjk1M2I2ZWZjNjlhNjkwZmY1ODI5NDkxNzM4YjA1MzFlOGE2NDAy
|
15
|
+
ZjhmOWM4MmI5MzZiNDFlNjI0ZWU2MDcxODhhZWU1YTViZGFmZGI=
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'mongo_mapper'
|
2
2
|
|
3
3
|
module MongoMapper::Denormalization
|
4
|
+
if defined?(ActiveModel::Validations::ClassMethods::VALID_OPTIONS_FOR_VALIDATE)
|
5
|
+
VALID_OPTIONS_FOR_VALIDATE = ActiveModel::Validations::ClassMethods::VALID_OPTIONS_FOR_VALIDATE
|
6
|
+
else
|
7
|
+
VALID_OPTIONS_FOR_VALIDATE = [:on, :if, :unless, :prepend].freeze
|
8
|
+
end
|
9
|
+
|
4
10
|
def self.included(mod)
|
5
11
|
mod.extend(MongoMapper::Denormalization::ClassMethods)
|
6
12
|
end
|
@@ -32,13 +38,16 @@ module MongoMapper::Denormalization
|
|
32
38
|
association = association.to_sym
|
33
39
|
field = field.to_sym
|
34
40
|
|
35
|
-
validation_method = options[:
|
41
|
+
validation_method = options[:method] || :before_validation
|
42
|
+
validation_method_params = options.slice(*VALID_OPTIONS_FOR_VALIDATE)
|
43
|
+
|
36
44
|
source_field_code = options[:source_field] || :"#{association}.#{field}"
|
37
45
|
target_field_code = options[:target_field] || :"#{association}_#{field}"
|
38
46
|
is_association = options[:is_association]
|
47
|
+
reflect_updates = options.has_key?(:reflect_updates) ? options[:reflect_updates] : true
|
39
48
|
|
40
|
-
denormalize_on_validation(association, field, validation_method, source_field_code, target_field_code)
|
41
|
-
denormalize_on_update(association, field, is_association, target_field_code)
|
49
|
+
denormalize_on_validation(association, field, validation_method, source_field_code, target_field_code, validation_method_params)
|
50
|
+
denormalize_on_update(association, field, is_association, target_field_code) if reflect_updates
|
42
51
|
end
|
43
52
|
|
44
53
|
private
|
@@ -82,12 +91,12 @@ module MongoMapper::Denormalization
|
|
82
91
|
CODE
|
83
92
|
end
|
84
93
|
|
85
|
-
def denormalize_on_validation(association, field, validation_method, source_field_code, target_field_code)
|
94
|
+
def denormalize_on_validation(association, field, validation_method, source_field_code, target_field_code, validation_method_params={})
|
86
95
|
validation_method_name = :"denormalize_#{association}_#{field}"
|
87
96
|
|
88
97
|
# denormalize the field
|
89
98
|
self.class_eval <<-CODE, __FILE__, __LINE__
|
90
|
-
#{validation_method} :#{validation_method_name}
|
99
|
+
#{validation_method} :#{validation_method_name}, #{validation_method_params.inspect}
|
91
100
|
|
92
101
|
def #{validation_method_name}
|
93
102
|
if self.#{association}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: denormalize_mm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Taylor
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Helpers to denormalize fields easily on mongo mapper models
|
15
15
|
email: scott@railsnewbie.com
|