mongoid_alize 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/config/locales/en.yml +1 -0
  2. data/lib/mongoid/alize/callback.rb +48 -13
  3. data/lib/mongoid/alize/callbacks/from/many.rb +5 -5
  4. data/lib/mongoid/alize/callbacks/from/one.rb +14 -31
  5. data/lib/mongoid/alize/errors/invalid_configuration.rb +16 -0
  6. data/lib/mongoid/alize/from_callback.rb +4 -2
  7. data/lib/mongoid/alize/instance_helpers.rb +25 -0
  8. data/lib/mongoid/alize/macros.rb +65 -42
  9. data/lib/mongoid/alize/to_callback.rb +104 -9
  10. data/lib/mongoid_alize.rb +3 -7
  11. data/spec/app/models/head.rb +17 -1
  12. data/spec/app/models/mock_object.rb +6 -0
  13. data/spec/app/models/person.rb +16 -0
  14. data/spec/helpers/macros_helper.rb +11 -7
  15. data/spec/mongoid/alize/callback_spec.rb +62 -6
  16. data/spec/mongoid/alize/callbacks/from/one_spec.rb +41 -43
  17. data/spec/mongoid/alize/callbacks/to/many_from_many_spec.rb +23 -17
  18. data/spec/mongoid/alize/callbacks/to/many_from_one_spec.rb +158 -60
  19. data/spec/mongoid/alize/callbacks/to/one_from_many_spec.rb +110 -42
  20. data/spec/mongoid/alize/callbacks/to/one_from_one_spec.rb +167 -47
  21. data/spec/mongoid/alize/instance_helpers_spec.rb +36 -0
  22. data/spec/mongoid/alize/macros_spec.rb +90 -17
  23. data/spec/mongoid/alize/to_callback_spec.rb +87 -18
  24. data/spec/mongoid_alize_spec.rb +245 -26
  25. data/spec/spec_helper.rb +3 -1
  26. metadata +6 -8
  27. data/lib/mongoid/alize/callbacks/to/many_from_many.rb +0 -16
  28. data/lib/mongoid/alize/callbacks/to/many_from_one.rb +0 -15
  29. data/lib/mongoid/alize/callbacks/to/one_from_many.rb +0 -15
  30. data/lib/mongoid/alize/callbacks/to/one_from_one.rb +0 -15
  31. data/lib/mongoid/alize/to_many_callback.rb +0 -50
  32. data/lib/mongoid/alize/to_one_callback.rb +0 -43
@@ -27,6 +27,8 @@ RSpec.configure do |config|
27
27
  }
28
28
 
29
29
  [Head, Person].each do |klass|
30
+ klass.alize_from_callbacks = []
31
+ klass.alize_to_callbacks = []
30
32
  klass.reset_callbacks(:save)
31
33
  klass.reset_callbacks(:create)
32
34
  klass.reset_callbacks(:destroy)
@@ -35,7 +37,7 @@ RSpec.configure do |config|
35
37
  persistent_fields[Object]).include?(field.to_sym)
36
38
  end
37
39
  klass.instance_methods.each do |method|
38
- if method =~ /^_?denormalize_/
40
+ if method =~ /^_?denormalize_/ && method !~ /_all$/
39
41
  klass.send(:undef_method, method)
40
42
  end
41
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_alize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-20 00:00:00.000000000 Z
12
+ date: 2012-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -53,20 +53,17 @@ files:
53
53
  - lib/mongoid/alize/callback.rb
54
54
  - lib/mongoid/alize/callbacks/from/many.rb
55
55
  - lib/mongoid/alize/callbacks/from/one.rb
56
- - lib/mongoid/alize/callbacks/to/many_from_many.rb
57
- - lib/mongoid/alize/callbacks/to/many_from_one.rb
58
- - lib/mongoid/alize/callbacks/to/one_from_many.rb
59
- - lib/mongoid/alize/callbacks/to/one_from_one.rb
60
56
  - lib/mongoid/alize/errors/alize_error.rb
61
57
  - lib/mongoid/alize/errors/already_defined_field.rb
58
+ - lib/mongoid/alize/errors/invalid_configuration.rb
62
59
  - lib/mongoid/alize/errors/invalid_field.rb
63
60
  - lib/mongoid/alize/from_callback.rb
61
+ - lib/mongoid/alize/instance_helpers.rb
64
62
  - lib/mongoid/alize/macros.rb
65
63
  - lib/mongoid/alize/to_callback.rb
66
- - lib/mongoid/alize/to_many_callback.rb
67
- - lib/mongoid/alize/to_one_callback.rb
68
64
  - lib/mongoid_alize.rb
69
65
  - spec/app/models/head.rb
66
+ - spec/app/models/mock_object.rb
70
67
  - spec/app/models/person.rb
71
68
  - spec/helpers/macros_helper.rb
72
69
  - spec/mongoid/alize/callback_spec.rb
@@ -77,6 +74,7 @@ files:
77
74
  - spec/mongoid/alize/callbacks/to/one_from_many_spec.rb
78
75
  - spec/mongoid/alize/callbacks/to/one_from_one_spec.rb
79
76
  - spec/mongoid/alize/from_callback_spec.rb
77
+ - spec/mongoid/alize/instance_helpers_spec.rb
80
78
  - spec/mongoid/alize/macros_spec.rb
81
79
  - spec/mongoid/alize/to_callback_spec.rb
82
80
  - spec/mongoid_alize_spec.rb
@@ -1,16 +0,0 @@
1
- module Mongoid
2
- module Alize
3
- module Callbacks
4
- module To
5
- class ManyFromMany < ToManyCallback
6
- protected
7
-
8
- def iterable_relation
9
- plain_relation
10
- end
11
-
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- module Mongoid
2
- module Alize
3
- module Callbacks
4
- module To
5
- class ManyFromOne < ToManyCallback
6
- protected
7
-
8
- def iterable_relation
9
- surrounded_relation
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module Mongoid
2
- module Alize
3
- module Callbacks
4
- module To
5
- class OneFromMany < ToOneCallback
6
- protected
7
-
8
- def iterable_relation
9
- plain_relation
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module Mongoid
2
- module Alize
3
- module Callbacks
4
- module To
5
- class OneFromOne < ToOneCallback
6
- protected
7
-
8
- def iterable_relation
9
- surrounded_relation
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,50 +0,0 @@
1
- module Mongoid
2
- module Alize
3
- class ToManyCallback < ToCallback
4
- protected
5
-
6
- def define_callback
7
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
8
- def #{callback_name}#{force_param}
9
- data = #{joined_field_values("self")}
10
- (#{iterable_relation}).each do |inverse|
11
- #{pull_from_inverse}
12
- inverse.push(:#{prefixed_name}, data)
13
- end
14
- end
15
- protected :#{callback_name}
16
- CALLBACK
17
- end
18
-
19
- def define_destroy_callback
20
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
21
- def #{destroy_callback_name}
22
- (#{iterable_relation}).each do |inverse|
23
- #{pull_from_inverse}
24
- end
25
- end
26
- protected :#{destroy_callback_name}
27
- CALLBACK
28
- end
29
-
30
- def pull_from_inverse
31
- <<-CALLBACK
32
- # this pull works in the DB, but not in memory
33
- # ($pull w/ expression not currently supported by Mongoid)
34
- inverse.pull(:#{prefixed_name}, { "_id" => self.id })
35
-
36
- # manually do the pull in memory for now
37
- if inverse.#{prefixed_name}
38
- inverse.#{prefixed_name}.reject! do |hash|
39
- hash["_id"] == self.id
40
- end
41
- end
42
- CALLBACK
43
- end
44
-
45
- def prefixed_name
46
- "#{inverse_relation}_fields"
47
- end
48
- end
49
- end
50
- end
@@ -1,43 +0,0 @@
1
- module Mongoid
2
- module Alize
3
- class ToOneCallback < ToCallback
4
- protected
5
-
6
- def define_callback
7
- _callback(callback_name, to_one_field_sets)
8
- end
9
-
10
- def define_destroy_callback
11
- _callback(destroy_callback_name, to_one_destroy_field_sets)
12
- end
13
-
14
- def to_one_field_sets
15
- fields.map { |field|
16
- "relation.set(:#{prefixed_field_name(field)}, self.send(:#{field}))"
17
- }.join("\n")
18
- end
19
-
20
- def to_one_destroy_field_sets
21
- fields.map { |field|
22
- "relation.set(:#{prefixed_field_name(field)}, nil)"
23
- }.join("\n")
24
- end
25
-
26
- def _callback(_callback_name, field_sets)
27
- klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
28
- def #{_callback_name}#{force_param}
29
- (#{iterable_relation}).each do |relation|
30
- #{field_sets}
31
- end
32
- true
33
- end
34
- protected :#{_callback_name}
35
- CALLBACK
36
- end
37
-
38
- def prefixed_field_name(name)
39
- "#{inverse_relation}_#{name}"
40
- end
41
- end
42
- end
43
- end