denormalize_mm 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,48 +1,48 @@
1
- module MongoMapper
2
- module Denormalization
3
- def self.included(mod)
4
- mod.extend(MongoMapper::Denormalization::ClassMethods)
5
- end
1
+ require 'mongo_mapper'
6
2
 
7
- module ClassMethods
8
- def denormalize_field(association, field, options={})
9
- denormalize(association, field, options)
10
- end
3
+ module MongoMapper::Denormalization
4
+ def self.included(mod)
5
+ mod.extend(MongoMapper::Denormalization::ClassMethods)
6
+ end
11
7
 
12
- def denormalize_association(dest, options={})
13
- options = options.dup
14
- source = options.delete(:from)
8
+ module ClassMethods
9
+ def denormalize_field(association, field, options={})
10
+ denormalize(association, field, options)
11
+ end
15
12
 
16
- if !source
17
- raise "denormalize_association must take a from (source) option"
18
- end
13
+ def denormalize_association(dest, options={})
14
+ options = options.dup
15
+ source = options.delete(:from)
19
16
 
20
- denormalize(source, dest, {
21
- :target_field => dest,
22
- }.merge(options))
17
+ if !source
18
+ raise "denormalize_association must take a from (source) option"
23
19
  end
24
20
 
25
- def denormalize(association, field, options={})
26
- method_name = "denormalize_#{association}_#{field}"
21
+ denormalize(source, dest, {
22
+ :target_field => dest,
23
+ }.merge(options))
24
+ end
27
25
 
28
- validation_method = options[:on] || "before_validation"
29
- source_field_code = options[:source_field] || "#{association}.#{field}"
30
- target_field_code = options[:target_field] || "#{association}_#{field}"
26
+ def denormalize(association, field, options={})
27
+ method_name = "denormalize_#{association}_#{field}"
31
28
 
32
- self.class_eval <<-CODE, __FILE__, __LINE__
33
- #{validation_method} :#{method_name}
29
+ validation_method = options[:on] || "before_validation"
30
+ source_field_code = options[:source_field] || "#{association}.#{field}"
31
+ target_field_code = options[:target_field] || "#{association}_#{field}"
34
32
 
35
- def #{method_name}
36
- if self.#{association}
37
- self.#{target_field_code} = #{source_field_code}
38
- end
33
+ self.class_eval <<-CODE, __FILE__, __LINE__
34
+ #{validation_method} :#{method_name}
39
35
 
40
- true
36
+ def #{method_name}
37
+ if self.#{association}
38
+ self.#{target_field_code} = #{source_field_code}
41
39
  end
42
40
 
43
- private :#{method_name}
44
- CODE
45
- end
41
+ true
42
+ end
43
+
44
+ private :#{method_name}
45
+ CODE
46
46
  end
47
47
  end
48
48
  end
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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: