mongoid_embedded_helper 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source :gemcutter
2
2
 
3
- gem 'mongoid'
3
+ gem 'mongoid', '>=2.0.0.beta.14'
4
+ gem "mongoid_adjust", ">= 0.1.1"
4
5
  gem 'bson_ext', '>=1.0.1'
5
6
 
6
7
  group :test do
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.0.rc)
5
+ activesupport (= 3.0.0.rc)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.4.1)
8
+ activesupport (3.0.0.rc)
9
+ bson (1.0.4)
10
+ bson_ext (1.0.4)
11
+ builder (2.1.2)
12
+ diff-lcs (1.1.2)
13
+ i18n (0.4.1)
14
+ mocha (0.9.8)
15
+ rake
16
+ mongo (1.0.6)
17
+ bson (>= 1.0.4)
18
+ mongoid (2.0.0.beta.15)
19
+ activemodel (= 3.0.0.rc)
20
+ bson (= 1.0.4)
21
+ mongo (= 1.0.6)
22
+ tzinfo (= 0.3.22)
23
+ will_paginate (~> 3.0.pre)
24
+ mongoid_adjust (0.1.1)
25
+ bson (>= 1.0.3)
26
+ mongoid (>= 2.0.0.beta.14)
27
+ rake (0.8.7)
28
+ rspec (2.0.0.beta.19)
29
+ rspec-core (= 2.0.0.beta.19)
30
+ rspec-expectations (= 2.0.0.beta.19)
31
+ rspec-mocks (= 2.0.0.beta.19)
32
+ rspec-core (2.0.0.beta.19)
33
+ rspec-expectations (2.0.0.beta.19)
34
+ diff-lcs (>= 1.1.2)
35
+ rspec-mocks (2.0.0.beta.19)
36
+ tzinfo (0.3.22)
37
+ will_paginate (3.0.pre2)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bson_ext (>= 1.0.1)
44
+ mocha
45
+ mongoid (>= 2.0.0.beta.14)
46
+ mongoid_adjust (>= 0.1.1)
47
+ rspec (>= 2.0.0.beta.15)
data/Rakefile CHANGED
@@ -10,10 +10,11 @@ begin
10
10
  gem.email = "kmandrup@gmail.com"
11
11
  gem.homepage = "http://github.com/kristianmandrup/mongoid_embedded_helper"
12
12
  gem.authors = ["Kristian Mandrup"]
13
- gem.add_dependency("mongoid", "<= 2.0.0")
14
- gem.add_dependency("bson", ">= 1.0.3")
13
+ gem.add_dependency "mongoid", ">= 2.0.0.beta.14"
14
+ gem.add_dependency "mongoid_adjust", ">= 0.1.1"
15
+ gem.add_dependency "bson_ext", ">= 1.0.3"
15
16
 
16
- gem.add_development_dependency "rspec", ">=2.0.0.beta.12"
17
+ gem.add_development_dependency "rspec", ">=2.0.0.beta.15"
17
18
  end
18
19
  Jeweler::GemcutterTasks.new
19
20
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.5
@@ -59,92 +59,4 @@ module Mongoid
59
59
  end
60
60
  end
61
61
 
62
- class NilClass
63
- def integer?
64
- false
65
- end
66
- end
67
-
68
- module Mongoid::Extensions::Array
69
- module Mutators
70
- def adjust!(attrs = {})
71
- attrs.each_pair do |key, value|
72
- self.each do |doc|
73
- doc.adjust!(attrs)
74
- end
75
- end
76
- self
77
- end
78
- end
79
- end
80
-
81
- module Mongoid
82
- class Criteria
83
- def adjust!(attrs = {})
84
- to_a.adjust!(attrs)
85
- end
86
- end
87
- end
88
-
89
- module Mongoid::Document
90
-
91
- def present? key
92
- respond_to? key
93
- end
94
-
95
- def adjust!(attrs = {})
96
- (attrs || {}).each_pair do |key, value|
97
- next if !present? key # only add to properties already present!
98
- adjust_by_proc!(key, value) if value.kind_of?(Proc)
99
- adjust_by_symbol!(key, value) if value.kind_of?(Symbol) || value.kind_of?(String)
100
- adjust_by_number!(key, value) if value.kind_of?(Numeric) # only add integer values
101
- end
102
- self
103
- end
104
-
105
- private
106
62
 
107
- def adjust_by_proc! key, proc
108
- if set_allowed?(key)
109
- current_val = @attributes[key.to_s]
110
- @attributes[key.to_s] = proc.call(current_val)
111
- elsif write_allowed?(key)
112
- current_val = send("#{key}")
113
- send("#{key}=", proc.call(current_val))
114
- end
115
- end
116
-
117
- def adjust_by_symbol! key, name
118
- method = name.to_sym
119
- if set_allowed?(key)
120
- current_val = @attributes[key.to_s]
121
- @attributes[key.to_s] = current_val.send(method)
122
- elsif write_allowed?(key)
123
- current_val = send("#{key}")
124
- send("#{key}=", current_val.send(method))
125
- end
126
- end
127
-
128
-
129
- def adjust_by_number! key, value
130
- if set_allowed?(key)
131
- current_val = @attributes[key.to_s] || 0
132
-
133
- if current_val.kind_of? Numeric
134
- @attributes[key.to_s] = current_val + value
135
- end
136
-
137
- elsif write_allowed?(key)
138
- current_val = send("#{key}") || 0
139
-
140
- if current_val.kind_of? Numeric
141
- send("#{key}=", current_val + value)
142
- end
143
- end
144
- end
145
-
146
- end
147
-
148
- class Array
149
- include Mongoid::Extensions::Array::Mutators
150
- end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_embedded_helper}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-07-06}
12
+ s.date = %q{2010-08-08}
13
13
  s.description = %q{Facilitates performing queries on collections in embedded Mongoid documents by performing query from the root node}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.files = [
19
19
  ".gitignore",
20
20
  "Gemfile",
21
+ "Gemfile.lock",
21
22
  "MITLICENSE",
22
23
  "README.markdown",
23
24
  "Rakefile",
@@ -26,9 +27,11 @@ Gem::Specification.new do |s|
26
27
  "lib/mongoid/embedded_helper.rb",
27
28
  "lib/mongoid_embedded_helper.rb",
28
29
  "mongoid_embedded_helper.gemspec",
30
+ "rspec.options",
31
+ "spec/model/list.rb",
32
+ "spec/model/person_list.rb",
29
33
  "spec/mongoid/embedded_helper_spec.rb",
30
34
  "spec/mongoid/more_embedded_helper_spec.rb",
31
- "spec/rspec.options",
32
35
  "spec/spec_helper.rb"
33
36
  ]
34
37
  s.homepage = %q{http://github.com/kristianmandrup/mongoid_embedded_helper}
@@ -37,7 +40,9 @@ Gem::Specification.new do |s|
37
40
  s.rubygems_version = %q{1.3.7}
38
41
  s.summary = %q{Facilitates performing queries on collections in embedded Mongoid documents}
39
42
  s.test_files = [
40
- "spec/mongoid/embedded_helper_spec.rb",
43
+ "spec/model/list.rb",
44
+ "spec/model/person_list.rb",
45
+ "spec/mongoid/embedded_helper_spec.rb",
41
46
  "spec/mongoid/more_embedded_helper_spec.rb",
42
47
  "spec/spec_helper.rb"
43
48
  ]
@@ -47,18 +52,21 @@ Gem::Specification.new do |s|
47
52
  s.specification_version = 3
48
53
 
49
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_runtime_dependency(%q<mongoid>, ["<= 2.0.0"])
51
- s.add_runtime_dependency(%q<bson>, [">= 1.0.3"])
52
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
55
+ s.add_runtime_dependency(%q<mongoid>, [">= 2.0.0.beta.14"])
56
+ s.add_runtime_dependency(%q<mongoid_adjust>, [">= 0.1.1"])
57
+ s.add_runtime_dependency(%q<bson_ext>, [">= 1.0.3"])
58
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.15"])
53
59
  else
54
- s.add_dependency(%q<mongoid>, ["<= 2.0.0"])
55
- s.add_dependency(%q<bson>, [">= 1.0.3"])
56
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
60
+ s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.14"])
61
+ s.add_dependency(%q<mongoid_adjust>, [">= 0.1.1"])
62
+ s.add_dependency(%q<bson_ext>, [">= 1.0.3"])
63
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.15"])
57
64
  end
58
65
  else
59
- s.add_dependency(%q<mongoid>, ["<= 2.0.0"])
60
- s.add_dependency(%q<bson>, [">= 1.0.3"])
61
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
66
+ s.add_dependency(%q<mongoid>, [">= 2.0.0.beta.14"])
67
+ s.add_dependency(%q<mongoid_adjust>, [">= 0.1.1"])
68
+ s.add_dependency(%q<bson_ext>, [">= 1.0.3"])
69
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.15"])
62
70
  end
63
71
  end
64
72
 
File without changes
@@ -0,0 +1,29 @@
1
+ class SimpleList
2
+ include Mongoid::Document
3
+ field :pos, :type => Integer
4
+ field :name, :type => String
5
+ embeds_many :simple_items
6
+ end
7
+
8
+
9
+ class SimpleItem
10
+ include Mongoid::Document
11
+ include Mongoid::EmbeddedHelper
12
+ field :pos, :type => Integer
13
+ field :number, :type => Integer
14
+ field :name, :type => String
15
+ field :assoc, :type => Symbol
16
+
17
+ embedded_in :simple_list, :inverse_of => :simple_items
18
+
19
+ field :assimilated, :type => Boolean, :default => false
20
+ field :parentized, :type => Boolean, :default => false
21
+
22
+ def after_parentize
23
+ self.parentized = true
24
+ end
25
+
26
+ def after_assimilate
27
+ self.assimilated = true
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ class Person
2
+ include Mongoid::Document
3
+ include Mongoid::EmbeddedHelper
4
+ field :name, :type => String
5
+ embeds_many :lists
6
+
7
+ # after_update :do_it
8
+ # def do_it
9
+ # puts "hello"
10
+ # end
11
+ end
12
+
13
+ class PosPerson
14
+ include Mongoid::Document
15
+ include Mongoid::EmbeddedHelper
16
+ field :pos, :type => Integer
17
+ field :name, :type => String
18
+ embeds_many :lists
19
+ end
20
+
21
+
22
+ class List
23
+ include Mongoid::Document
24
+ include Mongoid::EmbeddedHelper
25
+ field :pos, :type => Integer
26
+ field :name, :type => String
27
+ embedded_in :person, :inverse_of => :lists
28
+
29
+ embeds_many :items
30
+ end
31
+
32
+
33
+ class Item
34
+ include Mongoid::Document
35
+ include Mongoid::EmbeddedHelper
36
+ field :pos, :type => Integer
37
+ field :number, :type => Integer
38
+ field :name, :type => String
39
+ field :assoc, :type => Symbol
40
+ embedded_in :list, :inverse_of => :items
41
+ end
42
+
@@ -1,48 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- Mongoid.configure.master = Mongo::Connection.new.db('acts_as_list-test')
4
-
5
- class Person
6
- include Mongoid::Document
7
- include Mongoid::EmbeddedHelper
8
- field :name, :type => String
9
- embeds_many :lists
10
-
11
- # after_update :do_it
12
- # def do_it
13
- # puts "hello"
14
- # end
15
- end
16
-
17
- class PosPerson
18
- include Mongoid::Document
19
- include Mongoid::EmbeddedHelper
20
- field :pos, :type => Integer
21
- field :name, :type => String
22
- embeds_many :lists
23
- end
24
-
25
-
26
- class List
27
- include Mongoid::Document
28
- include Mongoid::EmbeddedHelper
29
- field :pos, :type => Integer
30
- field :name, :type => String
31
- embedded_in :person, :inverse_of => :lists
32
-
33
- embeds_many :items
34
- end
35
-
36
-
37
- class Item
38
- include Mongoid::Document
39
- include Mongoid::EmbeddedHelper
40
- field :pos, :type => Integer
41
- field :number, :type => Integer
42
-
43
- field :assoc, :type => Symbol
44
- embedded_in :list, :inverse_of => :items
45
- end
2
+ require 'model/person_list'
46
3
 
47
4
  describe 'Mongoid Embedded Helper' do
48
5
 
@@ -81,75 +38,6 @@ describe 'Mongoid Embedded Helper' do
81
38
  result = @person.lists[0].items[0].in_collection.where(:number.gt => 1).to_a
82
39
  result.size.should == 2
83
40
  end
84
- end
85
-
86
- describe '#adjust! numeric' do
87
- context 'on an array' do
88
- it "should add 1 to all positions greater than 1" do
89
- result = @person.lists[0].items.where(:pos.gt => 1).to_a.adjust!(:pos => 1)
90
- result.map(&:pos).should == [3, 4]
91
- end
92
- end
93
-
94
- context 'on a criteria' do
95
- it "should add 1 to all positions greater than 1" do
96
- result = @person.lists[0].items.where(:pos.gt => 1).adjust!(:pos => 1)
97
- result.map(&:pos).should == [3, 4]
98
- end
99
- end
100
-
101
- context 'on a document with a pos' do
102
- it "should add 1 to the position" do
103
- result = @pos_person.adjust!(:pos => 1)
104
- result.pos.should == 1
105
- end
106
- end
107
-
108
- context 'on a document without a pos field' do
109
- it "should NOT add 1 to the position" do
110
- result = @person.adjust!(:pos => 1)
111
- lambda {result.pos}.should raise_error
112
- end
113
- end
114
- end
115
-
116
- describe '#adjust! by proc' do
117
- context 'on an array' do
118
- it "should times all positions (greater than 1) by 2" do
119
- result = @person.lists[0].items.where(:pos.gt => 1).to_a.adjust!(:pos => lambda {|e| e * 2})
120
- result.map(&:pos).should == [4, 6]
121
- end
122
- end
123
-
124
- context 'on a criteria' do
125
- it "should times all positions (greater than 1) by 2" do
126
- result = @person.lists[0].items.where(:pos.gt => 1).adjust!(:pos => lambda {|e| e * 2})
127
- result.map(&:pos).should == [4, 6]
128
- end
129
- end
130
-
131
- context 'on a document with a name field' do
132
- it "should upcase the name" do
133
- result = @person.adjust!(:name => lambda {|e| e.upcase })
134
- result.name.should == 'Kristian'.upcase
135
- end
136
- end
137
- end
138
-
139
- describe '#adjust! by symbol and string' do
140
- context 'on a document with a name field' do
141
- it "should upcase the name - using string arg" do
142
- result = @person.adjust!(:name => 'upcase')
143
- result.name.should == 'Kristian'.upcase
144
- end
145
- end
146
-
147
- context 'on a document with a name field' do
148
- it "should upcase the name - using symbol arg" do
149
- result = @person.adjust!(:name => :upcase)
150
- result.name.should == 'Kristian'.upcase
151
- end
152
- end
153
- end
41
+ end
154
42
  end
155
43
 
@@ -1,44 +1,13 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- Mongoid.configure.master = Mongo::Connection.new.db('acts_as_list-test')
4
-
5
- class List
6
- include Mongoid::Document
7
- field :pos, :type => Integer
8
- field :name, :type => String
9
- embeds_many :items
10
- end
11
-
12
-
13
- class Item
14
- include Mongoid::Document
15
- include Mongoid::EmbeddedHelper
16
- field :pos, :type => Integer
17
- field :number, :type => Integer
18
- field :name, :type => String
19
- field :assoc, :type => Symbol
20
-
21
- field :assimilated, :type => Boolean, :default => false
22
- field :parentized, :type => Boolean, :default => false
23
-
24
- embedded_in :list, :inverse_of => :items
25
-
26
- def after_parentize
27
- self.parentized = true
28
- end
29
-
30
- def after_assimilate
31
- self.assimilated = true
32
- end
33
- end
2
+ require 'model/list'
34
3
 
35
4
  describe 'Mongoid Embedded Helper' do
36
5
  before :each do
37
- @list = List.create! :pos => 1, :name => 'My list'
6
+ @list = SimpleList.create! :pos => 1, :name => 'My list'
38
7
  item_names = ('A'..'C').to_a
39
8
  (1..3).each do |counter|
40
- item = Item.new :pos => counter, :number => counter, :name => item_names[counter-1]
41
- @list.items << item
9
+ item = SimpleItem.new :pos => counter, :number => counter, :name => item_names[counter-1]
10
+ @list.simple_items << item
42
11
  end
43
12
  @list.save!
44
13
  end
@@ -51,21 +20,21 @@ describe 'Mongoid Embedded Helper' do
51
20
 
52
21
  describe '#in_collection' do
53
22
  it "should handle query from leaf node without List (non-embedded root node) includes Embedded::Helper" do
54
- result = @list.items[0].in_collection.where(:pos => 2).to_a.first
23
+ result = @list.simple_items[0].in_collection.where(:pos => 2).to_a.first
55
24
  result.pos.should == 2
56
25
  result.number.should == 2
57
26
  result.name.should == 'B'
58
27
  end
59
- end
28
+ end
60
29
 
61
- describe 'new callbacks' do
30
+ describe 'extra callbacks' do
62
31
  context 'item with callbacks added to parent' do
63
32
  it "should call :after_parentize callback" do
64
- @list.items[0].parentized.should be_true
33
+ @list.simple_items[0].parentized.should be_true
65
34
  end
66
35
 
67
36
  it "should NOT call :after_assimilate callback" do
68
- @list.items[0].assimilated.should be_false
37
+ @list.simple_items[0].assimilated.should be_false
69
38
  end
70
39
  end
71
40
  end
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,4 @@ RSpec.configure do |config|
8
8
  # config.mock_with :mocha
9
9
  end
10
10
 
11
+ Mongoid.configure.master = Mongo::Connection.new.db('acts_as_list-test')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 5
9
+ version: 0.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-06 00:00:00 +02:00
17
+ date: 2010-08-08 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,19 +23,36 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - <=
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 2
30
30
  - 0
31
31
  - 0
32
- version: 2.0.0
32
+ - beta
33
+ - 14
34
+ version: 2.0.0.beta.14
33
35
  type: :runtime
34
36
  version_requirements: *id001
35
37
  - !ruby/object:Gem::Dependency
36
- name: bson
38
+ name: mongoid_adjust
37
39
  prerelease: false
38
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 0
47
+ - 1
48
+ - 1
49
+ version: 0.1.1
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: bson_ext
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
39
56
  none: false
40
57
  requirements:
41
58
  - - ">="
@@ -46,11 +63,11 @@ dependencies:
46
63
  - 3
47
64
  version: 1.0.3
48
65
  type: :runtime
49
- version_requirements: *id002
66
+ version_requirements: *id003
50
67
  - !ruby/object:Gem::Dependency
51
68
  name: rspec
52
69
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
54
71
  none: false
55
72
  requirements:
56
73
  - - ">="
@@ -60,10 +77,10 @@ dependencies:
60
77
  - 0
61
78
  - 0
62
79
  - beta
63
- - 12
64
- version: 2.0.0.beta.12
80
+ - 15
81
+ version: 2.0.0.beta.15
65
82
  type: :development
66
- version_requirements: *id003
83
+ version_requirements: *id004
67
84
  description: Facilitates performing queries on collections in embedded Mongoid documents by performing query from the root node
68
85
  email: kmandrup@gmail.com
69
86
  executables: []
@@ -75,6 +92,7 @@ extra_rdoc_files:
75
92
  files:
76
93
  - .gitignore
77
94
  - Gemfile
95
+ - Gemfile.lock
78
96
  - MITLICENSE
79
97
  - README.markdown
80
98
  - Rakefile
@@ -83,9 +101,11 @@ files:
83
101
  - lib/mongoid/embedded_helper.rb
84
102
  - lib/mongoid_embedded_helper.rb
85
103
  - mongoid_embedded_helper.gemspec
104
+ - rspec.options
105
+ - spec/model/list.rb
106
+ - spec/model/person_list.rb
86
107
  - spec/mongoid/embedded_helper_spec.rb
87
108
  - spec/mongoid/more_embedded_helper_spec.rb
88
- - spec/rspec.options
89
109
  - spec/spec_helper.rb
90
110
  has_rdoc: true
91
111
  homepage: http://github.com/kristianmandrup/mongoid_embedded_helper
@@ -120,6 +140,8 @@ signing_key:
120
140
  specification_version: 3
121
141
  summary: Facilitates performing queries on collections in embedded Mongoid documents
122
142
  test_files:
143
+ - spec/model/list.rb
144
+ - spec/model/person_list.rb
123
145
  - spec/mongoid/embedded_helper_spec.rb
124
146
  - spec/mongoid/more_embedded_helper_spec.rb
125
147
  - spec/spec_helper.rb