mongoid_alize 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82f38f130a43b157a89d24db64a6e480f5ebf4c0
4
+ data.tar.gz: 631e2a0cb7c8fea2facca96b36b9299f6acc79c3
5
+ SHA512:
6
+ metadata.gz: 7a3070a9aeeb79e137bb2cd7afdc4bec9228e05e1ff2f825850e90ff1061c3ca56a8fb7a22c36a02e5ff5d57ce0f74901bffa396ca98d98cf18ae51b913bc306
7
+ data.tar.gz: 271ebad88154ca6424425c9fedbffb6269364a48cf3173b7a5d5cf84b7e32ea89c8f63254609cb0670aa3382c31206a2dc714593e9a56965f68f80ccd23133f7
@@ -62,7 +62,7 @@ module Mongoid
62
62
  _denorm_attrs = denorm_attrs
63
63
  if denorm_attrs.is_a?(Proc)
64
64
  klass.send(:define_method, denorm_attrs_name) do |inverse|
65
- _denorm_attrs.bind(self).call(inverse).map(&:to_s)
65
+ self.instance_exec(inverse, &_denorm_attrs).map(&:to_s)
66
66
  end
67
67
  else
68
68
  klass.send(:define_method, denorm_attrs_name) do |inverse|
@@ -31,10 +31,10 @@ module Mongoid
31
31
 
32
32
  prefixed_name = #{prefixed_name}
33
33
  if is_one
34
- relation.set(prefixed_name, field_values)
34
+ #{relation_set('prefixed_name', 'field_values')}
35
35
  else
36
36
  #{pull_from_inverse}
37
- relation.push(prefixed_name, field_values)
37
+ #{relation_push('prefixed_name', 'field_values')}
38
38
  end
39
39
 
40
40
  end
@@ -56,7 +56,7 @@ module Mongoid
56
56
  is_one = #{is_one?}
57
57
  prefixed_name = #{prefixed_name}
58
58
  if is_one
59
- relation.set(prefixed_name, nil)
59
+ #{relation_set('prefixed_name', 'nil')}
60
60
  else
61
61
  #{pull_from_inverse}
62
62
  end
@@ -71,7 +71,7 @@ module Mongoid
71
71
 
72
72
  def pull_from_inverse
73
73
  <<-RUBIES
74
- relation.pull(prefixed_name, { "_id" => self.id })
74
+ #{relation_pull('prefixed_name', '{ "_id" => self.id }')}
75
75
  if _f = relation.send(prefixed_name)
76
76
  _f.reject! do |hash|
77
77
  hash["_id"] == self.id
@@ -90,6 +90,18 @@ module Mongoid
90
90
  end
91
91
  end
92
92
 
93
+ def relation_set(field, value)
94
+ mongoid_4? ? "relation.set(#{field} => #{value})" : "relation.set(#{field}, #{value})"
95
+ end
96
+
97
+ def relation_pull(field, value)
98
+ mongoid_4? ? "relation.pull(#{field} => #{value})" : "relation.pull(#{field}, #{value})"
99
+ end
100
+
101
+ def relation_push(field, value)
102
+ mongoid_4? ? "relation.push(#{field} => #{value})" : "relation.push(#{field}, #{value})"
103
+ end
104
+
93
105
  def is_one?
94
106
  if inverse_relation
95
107
  if self.inverse_metadata.relation.superclass == Mongoid::Relations::One
@@ -142,6 +154,10 @@ module Mongoid
142
154
  def direction
143
155
  "to"
144
156
  end
157
+
158
+ def mongoid_4?
159
+ Mongoid::VERSION =~ /^4\./
160
+ end
145
161
  end
146
162
  end
147
163
  end
@@ -2,6 +2,10 @@ class Head
2
2
  include Mongoid::Document
3
3
  include Mongoid::Alize
4
4
 
5
+ if SpecHelper.mongoid_4?
6
+ include Mongoid::Attributes::Dynamic
7
+ end
8
+
5
9
  field :size, type: Integer
6
10
  field :weight
7
11
 
@@ -2,10 +2,14 @@ class Person
2
2
  include Mongoid::Document
3
3
  include Mongoid::Alize
4
4
 
5
+ if SpecHelper.mongoid_4?
6
+ include Mongoid::Attributes::Dynamic
7
+ end
8
+
5
9
  field :name, type: String
6
10
  field :created_at, type: Time
7
11
 
8
- if SpecHelper.mongoid_3?
12
+ if SpecHelper.mongoid_3? || SpecHelper.mongoid_4?
9
13
  field :my_date, type: Date
10
14
  field :my_datetime, type: DateTime
11
15
  end
@@ -189,6 +189,7 @@ describe Mongoid::Alize::ToCallback do
189
189
  end
190
190
 
191
191
  it "should do nothing if the relation doesn't exist" do
192
+ @person.reload
192
193
  @person.nearest_head = nil
193
194
  run_destroy_callback
194
195
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
2
2
  require 'mongoid'
3
3
 
4
4
  unless ENV['CI']
5
- require 'looksee'
6
5
  require 'awesome_print'
7
6
  require 'wirble'
8
7
  end
@@ -11,10 +10,14 @@ module SpecHelper
11
10
  def self.mongoid_3?
12
11
  defined?(Mongoid::VERSION) && Mongoid::VERSION =~ /^3/
13
12
  end
13
+
14
+ def self.mongoid_4?
15
+ defined?(Mongoid::VERSION) && Mongoid::VERSION =~ /^4/
16
+ end
14
17
  end
15
18
 
16
19
  Mongoid.configure do |config|
17
- if SpecHelper.mongoid_3?
20
+ if SpecHelper.mongoid_3? || SpecHelper.mongoid_4?
18
21
  config.connect_to("mongoid_alize_test")
19
22
  Moped.logger = Logger.new($stdout)
20
23
  Moped.logger.level = Logger::INFO
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_alize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
5
- prerelease:
4
+ version: 0.4.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Josh Dzielak
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-16 00:00:00.000000000 Z
11
+ date: 2014-05-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mongoid
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '2.4'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '2.4'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -81,27 +76,28 @@ files:
81
76
  - spec/mongoid_alize_spec.rb
82
77
  - spec/spec_helper.rb
83
78
  homepage: https://github.com/dzello/mongoid_alize
84
- licenses: []
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
85
82
  post_install_message:
86
83
  rdoc_options: []
87
84
  require_paths:
88
85
  - lib
89
86
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
87
  requirements:
92
- - - ! '>='
88
+ - - '>='
93
89
  - !ruby/object:Gem::Version
94
90
  version: '0'
95
91
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
92
  requirements:
98
- - - ! '>='
93
+ - - '>='
99
94
  - !ruby/object:Gem::Version
100
95
  version: '0'
101
96
  requirements: []
102
97
  rubyforge_project:
103
- rubygems_version: 1.8.23
98
+ rubygems_version: 2.0.3
104
99
  signing_key:
105
- specification_version: 3
100
+ specification_version: 4
106
101
  summary: Comprehensive field denormalization for Mongoid that stays in sync.
107
102
  test_files: []
103
+ has_rdoc: