mongomodel 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/Appraisals +9 -0
  2. data/Gemfile +2 -2
  3. data/Rakefile +23 -13
  4. data/gemfiles/rails-3.0.gemfile +10 -0
  5. data/gemfiles/rails-3.0.gemfile.lock +73 -0
  6. data/gemfiles/rails-3.1.gemfile +10 -0
  7. data/gemfiles/rails-3.1.gemfile.lock +83 -0
  8. data/lib/mongomodel.rb +0 -1
  9. data/lib/mongomodel/concerns/abstract_class.rb +1 -0
  10. data/lib/mongomodel/concerns/associations.rb +12 -3
  11. data/lib/mongomodel/concerns/associations/base/definition.rb +5 -3
  12. data/lib/mongomodel/concerns/attribute_methods.rb +14 -7
  13. data/lib/mongomodel/concerns/properties.rb +15 -4
  14. data/lib/mongomodel/document/indexes.rb +14 -5
  15. data/lib/mongomodel/document/persistence.rb +7 -5
  16. data/lib/mongomodel/document/scopes.rb +22 -8
  17. data/lib/mongomodel/railtie.rb +2 -3
  18. data/lib/mongomodel/support/collection.rb +3 -1
  19. data/lib/mongomodel/support/map.rb +4 -2
  20. data/lib/mongomodel/support/mongo_options.rb +9 -34
  21. data/lib/mongomodel/support/scope.rb +2 -14
  22. data/lib/mongomodel/version.rb +1 -1
  23. data/mongomodel.gemspec +3 -3
  24. data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +4 -6
  25. data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +123 -123
  26. data/spec/mongomodel/concerns/logging_spec.rb +1 -1
  27. data/spec/mongomodel/document/dynamic_finders_spec.rb +32 -32
  28. data/spec/mongomodel/support/scope_spec.rb +0 -18
  29. data/spec/spec.opts +0 -3
  30. data/spec/spec_helper.rb +4 -4
  31. data/spec/support/helpers/document_finder_stubs.rb +2 -2
  32. data/spec/support/matchers/be_a_subclass_of.rb +1 -1
  33. data/spec/support/matchers/be_truthy.rb +1 -1
  34. data/spec/support/matchers/find_with.rb +4 -4
  35. data/spec/support/matchers/respond_to_boolean.rb +1 -1
  36. data/spec/support/matchers/run_callbacks.rb +1 -1
  37. metadata +23 -74
@@ -0,0 +1,9 @@
1
+ appraise "rails-3.0" do
2
+ gem "activesupport", "3.0.9"
3
+ gem "activemodel", "3.0.9"
4
+ end
5
+
6
+ appraise "rails-3.1" do
7
+ gem "activesupport", :git => "https://github.com/rails/rails.git", :branch => "3-1-stable"
8
+ gem "activemodel", :git => "https://github.com/rails/rails.git", :branch => "3-1-stable"
9
+ end
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "bson_ext", '~> 1.3.0'
6
- gem "SystemTimer"
5
+ gem "appraisal", "~> 0.3.6"
6
+ gem "bson_ext", "~> 1.3.0"
data/Rakefile CHANGED
@@ -1,20 +1,23 @@
1
- require 'rake/rdoctask'
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'appraisal'
2
5
 
3
6
  task :default => :spec
4
7
 
5
8
  begin
6
- require 'spec/rake/spectask'
9
+ require 'rspec/core/rake_task'
7
10
  desc 'Run the specs'
8
- Spec::Rake::SpecTask.new(:spec) do |t|
9
- t.libs << 'lib'
10
- t.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ #t.libs << 'lib'
13
+ t.rspec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
11
14
  end
12
15
 
13
16
  namespace :spec do
14
17
  desc "Run specs in nested documenting format"
15
- Spec::Rake::SpecTask.new(:doc) do |t|
16
- t.libs << 'lib'
17
- t.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/specdoc.opts"]
18
+ RSpec::Core::RakeTask.new(:doc) do |t|
19
+ #t.libs << 'lib'
20
+ t.rspec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/specdoc.opts"]
18
21
  end
19
22
  end
20
23
  rescue LoadError
@@ -26,11 +29,18 @@ rescue LoadError
26
29
  end
27
30
  end
28
31
 
29
- desc "Generate documentation"
30
- Rake::RDocTask.new(:doc) do |rdoc|
31
- rdoc.rdoc_dir = 'doc'
32
- rdoc.options << '--line-numbers' << '--inline-source'
33
- rdoc.rdoc_files.include('lib')
32
+ begin
33
+ require 'rdoc/task'
34
+ desc "Generate documentation"
35
+ Rake::RDocTask.new(:doc) do |rdoc|
36
+ rdoc.rdoc_dir = 'doc'
37
+ rdoc.options << '--line-numbers' << '--inline-source'
38
+ rdoc.rdoc_files.include('lib')
39
+ end
40
+ rescue LoadError
41
+ task :doc do
42
+ STDERR.puts "You must have rdoc to generate the documentation"
43
+ end
34
44
  end
35
45
 
36
46
  require 'bundler'
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 0.3.6"
6
+ gem "bson_ext", "~> 1.3.0"
7
+ gem "activesupport", "3.0.9"
8
+ gem "activemodel", "3.0.9"
9
+
10
+ gemspec :path=>"../"
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: /Users/sam/Development/MongoDB/mongomodel
3
+ specs:
4
+ mongomodel (0.3.3)
5
+ activemodel (~> 3.0)
6
+ activesupport (~> 3.0)
7
+ mongo (~> 1.3.0)
8
+ will_paginate (~> 2.3.15)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ activemodel (3.0.9)
14
+ activesupport (= 3.0.9)
15
+ builder (~> 2.1.2)
16
+ i18n (~> 0.5.0)
17
+ activesupport (3.0.9)
18
+ appraisal (0.3.6)
19
+ aruba (~> 0.4.2)
20
+ bundler
21
+ rake
22
+ aruba (0.4.3)
23
+ bcat (>= 0.6.1)
24
+ childprocess (>= 0.1.9)
25
+ cucumber (>= 0.10.7)
26
+ rdiscount (>= 1.6.8)
27
+ rspec (>= 2.6.0)
28
+ bcat (0.6.1)
29
+ rack (~> 1.0)
30
+ bson (1.3.1)
31
+ bson_ext (1.3.1)
32
+ builder (2.1.2)
33
+ childprocess (0.1.9)
34
+ ffi (~> 1.0.6)
35
+ cucumber (1.0.0)
36
+ builder (>= 2.1.2)
37
+ diff-lcs (>= 1.1.2)
38
+ gherkin (~> 2.4.1)
39
+ json (>= 1.4.6)
40
+ term-ansicolor (>= 1.0.5)
41
+ diff-lcs (1.1.2)
42
+ ffi (1.0.9)
43
+ gherkin (2.4.1)
44
+ json (>= 1.4.6)
45
+ i18n (0.5.0)
46
+ json (1.5.3)
47
+ mongo (1.3.1)
48
+ bson (>= 1.3.1)
49
+ rack (1.3.0)
50
+ rake (0.9.2)
51
+ rdiscount (1.6.8)
52
+ rspec (2.6.0)
53
+ rspec-core (~> 2.6.0)
54
+ rspec-expectations (~> 2.6.0)
55
+ rspec-mocks (~> 2.6.0)
56
+ rspec-core (2.6.4)
57
+ rspec-expectations (2.6.0)
58
+ diff-lcs (~> 1.1.2)
59
+ rspec-mocks (2.6.0)
60
+ term-ansicolor (1.0.5)
61
+ will_paginate (2.3.15)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ activemodel (= 3.0.9)
68
+ activesupport (= 3.0.9)
69
+ appraisal (~> 0.3.6)
70
+ bson_ext (~> 1.3.0)
71
+ bundler (>= 1.0.0)
72
+ mongomodel!
73
+ rspec (~> 2.6.0)
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 0.3.6"
6
+ gem "bson_ext", "~> 1.3.0"
7
+ gem "activesupport", :git=>"https://github.com/rails/rails.git", :branch=>"3-1-stable"
8
+ gem "activemodel", :git=>"https://github.com/rails/rails.git", :branch=>"3-1-stable"
9
+
10
+ gemspec :path=>"../"
@@ -0,0 +1,83 @@
1
+ GIT
2
+ remote: https://github.com/rails/rails.git
3
+ revision: 07ea84a03b2a2c753768965a840913b4d4d42cee
4
+ branch: 3-1-stable
5
+ specs:
6
+ activemodel (3.1.0.rc4)
7
+ activesupport (= 3.1.0.rc4)
8
+ bcrypt-ruby (~> 2.1.4)
9
+ builder (~> 3.0.0)
10
+ i18n (~> 0.6)
11
+ activesupport (3.1.0.rc4)
12
+ multi_json (~> 1.0)
13
+
14
+ PATH
15
+ remote: /Users/sam/Development/MongoDB/mongomodel
16
+ specs:
17
+ mongomodel (0.3.3)
18
+ activemodel (~> 3.0)
19
+ activesupport (~> 3.0)
20
+ mongo (~> 1.3.0)
21
+ will_paginate (~> 2.3.15)
22
+
23
+ GEM
24
+ remote: http://rubygems.org/
25
+ specs:
26
+ appraisal (0.3.6)
27
+ aruba (~> 0.4.2)
28
+ bundler
29
+ rake
30
+ aruba (0.4.3)
31
+ bcat (>= 0.6.1)
32
+ childprocess (>= 0.1.9)
33
+ cucumber (>= 0.10.7)
34
+ rdiscount (>= 1.6.8)
35
+ rspec (>= 2.6.0)
36
+ bcat (0.6.1)
37
+ rack (~> 1.0)
38
+ bcrypt-ruby (2.1.4)
39
+ bson (1.3.1)
40
+ bson_ext (1.3.1)
41
+ builder (3.0.0)
42
+ childprocess (0.1.9)
43
+ ffi (~> 1.0.6)
44
+ cucumber (1.0.0)
45
+ builder (>= 2.1.2)
46
+ diff-lcs (>= 1.1.2)
47
+ gherkin (~> 2.4.1)
48
+ json (>= 1.4.6)
49
+ term-ansicolor (>= 1.0.5)
50
+ diff-lcs (1.1.2)
51
+ ffi (1.0.9)
52
+ gherkin (2.4.1)
53
+ json (>= 1.4.6)
54
+ i18n (0.6.0)
55
+ json (1.5.3)
56
+ mongo (1.3.1)
57
+ bson (>= 1.3.1)
58
+ multi_json (1.0.3)
59
+ rack (1.3.0)
60
+ rake (0.9.2)
61
+ rdiscount (1.6.8)
62
+ rspec (2.6.0)
63
+ rspec-core (~> 2.6.0)
64
+ rspec-expectations (~> 2.6.0)
65
+ rspec-mocks (~> 2.6.0)
66
+ rspec-core (2.6.4)
67
+ rspec-expectations (2.6.0)
68
+ diff-lcs (~> 1.1.2)
69
+ rspec-mocks (2.6.0)
70
+ term-ansicolor (1.0.5)
71
+ will_paginate (2.3.15)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ activemodel!
78
+ activesupport!
79
+ appraisal (~> 0.3.6)
80
+ bson_ext (~> 1.3.0)
81
+ bundler (>= 1.0.0)
82
+ mongomodel!
83
+ rspec (~> 2.6.0)
@@ -58,7 +58,6 @@ module MongoModel
58
58
  autoload :Store, 'mongomodel/attributes/store'
59
59
  autoload :Typecasting, 'mongomodel/attributes/typecasting'
60
60
  autoload :Mongo, 'mongomodel/attributes/mongo'
61
- autoload :Dirty, 'mongomodel/attributes/dirty'
62
61
  end
63
62
 
64
63
  module Associations
@@ -3,6 +3,7 @@ module MongoModel
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def inherited(subclass)
6
+ super
6
7
  subclass.abstract_class = false
7
8
  end
8
9
 
@@ -10,6 +10,14 @@ module MongoModel
10
10
  end
11
11
 
12
12
  module ClassMethods
13
+ def associations
14
+ @_associations ||= {}
15
+ end
16
+
17
+ def associations=(associations)
18
+ @_associations = associations
19
+ end
20
+
13
21
  def belongs_to(name, options={})
14
22
  associations[name] = create_association(BelongsTo, name, options)
15
23
  end
@@ -17,9 +25,10 @@ module MongoModel
17
25
  def has_many(name, options={})
18
26
  associations[name] = create_association(has_many_type(options), name, options)
19
27
  end
20
-
21
- def associations
22
- read_inheritable_attribute(:associations) || write_inheritable_attribute(:associations, {})
28
+
29
+ def inherited(subclass)
30
+ super
31
+ subclass.associations = associations.dup
23
32
  end
24
33
 
25
34
  private
@@ -46,12 +46,14 @@ module MongoModel
46
46
  options.slice(:conditions, :select, :offset, :limit, :order)
47
47
  end
48
48
 
49
- def self.properties(&block)
50
- block_given? ? write_inheritable_attribute(:properties, block) : read_inheritable_attribute(:properties)
49
+ def self.properties
50
+ @properties = Proc.new if block_given?
51
+ @properties
51
52
  end
52
53
 
53
54
  def self.methods(&block)
54
- block_given? ? write_inheritable_attribute(:methods, block) : read_inheritable_attribute(:methods)
55
+ @methods = Proc.new if block_given?
56
+ @methods
55
57
  end
56
58
 
57
59
  private
@@ -8,7 +8,18 @@ module MongoModel
8
8
  # Generates all the attribute related methods for defined properties
9
9
  # accessors, mutators and query methods.
10
10
  def define_attribute_methods
11
+ return if attribute_methods_generated?
11
12
  super(properties.keys)
13
+ @attribute_methods_generated = true
14
+ end
15
+
16
+ def attribute_methods_generated?
17
+ @attribute_methods_generated ||= false
18
+ end
19
+
20
+ def undefine_attribute_methods(*args)
21
+ super
22
+ @attribute_methods_generated = false
12
23
  end
13
24
 
14
25
  def property(*args)
@@ -23,20 +34,16 @@ module MongoModel
23
34
  # see if we've created the method we're looking for.
24
35
  unless self.class.attribute_methods_generated?
25
36
  self.class.define_attribute_methods
26
- method_name = method_id.to_s
27
-
28
- guard_private_attribute_method!(method_name, args)
29
37
 
30
- if self.class.generated_attribute_methods.method_defined?(method_name)
31
- return self.send(method_id, *args, &block)
32
- end
38
+ guard_private_attribute_method!(method_id.to_s, args)
39
+ return __send__(method_id, *args, &block)
33
40
  end
34
41
 
35
42
  super
36
43
  end
37
44
 
38
45
  def respond_to?(*args)
39
- self.class.define_attribute_methods
46
+ self.class.define_attribute_methods unless self.class.attribute_methods_generated?
40
47
  super
41
48
  end
42
49
 
@@ -1,4 +1,3 @@
1
- require 'active_support/core_ext/class/inheritable_attributes'
2
1
  require 'active_support/core_ext/module/delegation'
3
2
  require 'active_support/core_ext/array/extract_options'
4
3
  require 'active_support/core_ext/hash/except'
@@ -7,9 +6,8 @@ module MongoModel
7
6
  module Properties
8
7
  extend ActiveSupport::Concern
9
8
 
10
- included do
11
- class_inheritable_accessor :properties
12
- self.properties = ActiveSupport::OrderedHash.new
9
+ def properties
10
+ self.class.properties
13
11
  end
14
12
 
15
13
  module ClassMethods
@@ -19,6 +17,14 @@ module MongoModel
19
17
  end
20
18
  end
21
19
 
20
+ def properties
21
+ @properties ||= ActiveSupport::OrderedHash.new
22
+ end
23
+
24
+ def properties=(properties)
25
+ @properties = properties
26
+ end
27
+
22
28
  def model_properties
23
29
  properties.reject { |k, p| p.internal? }
24
30
  end
@@ -26,6 +32,11 @@ module MongoModel
26
32
  def internal_properties
27
33
  properties.select { |k, p| p.internal? }.map { |k, p| p }
28
34
  end
35
+
36
+ def inherited(subclass)
37
+ super
38
+ subclass.properties = properties.dup
39
+ end
29
40
  end
30
41
 
31
42
  class Property
@@ -16,17 +16,21 @@ module MongoModel
16
16
  property
17
17
  end
18
18
 
19
+ def indexes
20
+ @_indexes ||= []
21
+ end
22
+
23
+ def indexes=(indexes)
24
+ @_indexes = indexes
25
+ end
26
+
19
27
  def index(*args)
20
28
  index = Index.new(*args)
21
- indexes << index
29
+ self.indexes << index
22
30
  @_indexes_initialized = false
23
31
  index
24
32
  end
25
33
 
26
- def indexes
27
- read_inheritable_attribute(:indexes) || write_inheritable_attribute(:indexes, [])
28
- end
29
-
30
34
  def indexes_initialized?
31
35
  @_indexes_initialized == true
32
36
  end
@@ -38,6 +42,11 @@ module MongoModel
38
42
 
39
43
  @_indexes_initialized = true
40
44
  end
45
+
46
+ def inherited(subclass)
47
+ super
48
+ subclass.indexes = indexes.dup
49
+ end
41
50
  end
42
51
  end
43
52
  end