mongomodel 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +23 -11
  3. data/gemfiles/rails-3.2.gemfile +2 -2
  4. data/gemfiles/rails-4-observers.gemfile +1 -1
  5. data/gemfiles/rails-4.1.gemfile +2 -2
  6. data/gemfiles/{mongoid.gemfile → rails-4.2.gemfile} +2 -3
  7. data/gemfiles/{mongo_mapper.gemfile → rails-5.0.gemfile} +2 -3
  8. data/gemfiles/rails-5.1.gemfile +10 -0
  9. data/gemfiles/rails-5.2.gemfile +10 -0
  10. data/lib/mongomodel.rb +15 -15
  11. data/lib/mongomodel/attributes/mongo.rb +7 -7
  12. data/lib/mongomodel/attributes/store.rb +4 -4
  13. data/lib/mongomodel/attributes/typecasting.rb +7 -7
  14. data/lib/mongomodel/compatibility/mongo_mapper.rb +3 -3
  15. data/lib/mongomodel/compatibility/mongoid.rb +3 -3
  16. data/lib/mongomodel/concerns/abstract_class.rb +3 -3
  17. data/lib/mongomodel/concerns/activemodel.rb +4 -4
  18. data/lib/mongomodel/concerns/associations.rb +8 -8
  19. data/lib/mongomodel/concerns/associations/base/association.rb +5 -5
  20. data/lib/mongomodel/concerns/associations/base/definition.rb +4 -4
  21. data/lib/mongomodel/concerns/associations/base/proxy.rb +1 -1
  22. data/lib/mongomodel/concerns/associations/belongs_to.rb +19 -19
  23. data/lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb +36 -36
  24. data/lib/mongomodel/concerns/associations/has_many_by_ids.rb +34 -34
  25. data/lib/mongomodel/concerns/attribute_methods.rb +10 -10
  26. data/lib/mongomodel/concerns/attribute_methods/before_type_cast.rb +4 -4
  27. data/lib/mongomodel/concerns/attribute_methods/dirty.rb +95 -13
  28. data/lib/mongomodel/concerns/attribute_methods/forbidden.rb +1 -1
  29. data/lib/mongomodel/concerns/attribute_methods/multi_parameter_assignment.rb +6 -6
  30. data/lib/mongomodel/concerns/attribute_methods/nested.rb +18 -18
  31. data/lib/mongomodel/concerns/attribute_methods/protected.rb +3 -3
  32. data/lib/mongomodel/concerns/attribute_methods/query.rb +3 -3
  33. data/lib/mongomodel/concerns/attribute_methods/read.rb +4 -4
  34. data/lib/mongomodel/concerns/attribute_methods/write.rb +4 -4
  35. data/lib/mongomodel/concerns/attributes.rb +18 -18
  36. data/lib/mongomodel/concerns/callbacks.rb +7 -7
  37. data/lib/mongomodel/concerns/document_parent.rb +2 -2
  38. data/lib/mongomodel/concerns/logging.rb +2 -2
  39. data/lib/mongomodel/concerns/map_reduce.rb +11 -11
  40. data/lib/mongomodel/concerns/pretty_inspect.rb +3 -3
  41. data/lib/mongomodel/concerns/properties.rb +18 -18
  42. data/lib/mongomodel/concerns/record_status.rb +9 -13
  43. data/lib/mongomodel/concerns/serialization.rb +4 -4
  44. data/lib/mongomodel/concerns/timestamps.rb +4 -4
  45. data/lib/mongomodel/concerns/translation.rb +2 -2
  46. data/lib/mongomodel/concerns/validations.rb +5 -5
  47. data/lib/mongomodel/concerns/validations/associated.rb +1 -1
  48. data/lib/mongomodel/document.rb +6 -6
  49. data/lib/mongomodel/document/callbacks.rb +15 -21
  50. data/lib/mongomodel/document/collection_modifiers.rb +5 -5
  51. data/lib/mongomodel/document/dynamic_finders.rb +1 -1
  52. data/lib/mongomodel/document/indexes.rb +19 -19
  53. data/lib/mongomodel/document/optimistic_locking.rb +7 -7
  54. data/lib/mongomodel/document/persistence.rb +23 -23
  55. data/lib/mongomodel/document/scopes.rb +20 -20
  56. data/lib/mongomodel/document/validations.rb +6 -6
  57. data/lib/mongomodel/document/validations/uniqueness.rb +11 -11
  58. data/lib/mongomodel/embedded_document.rb +11 -11
  59. data/lib/mongomodel/locale/en.yml +0 -1
  60. data/lib/mongomodel/log_subscriber.rb +5 -5
  61. data/lib/mongomodel/railtie.rb +13 -13
  62. data/lib/mongomodel/support/collection.rb +31 -31
  63. data/lib/mongomodel/support/configuration.rb +11 -11
  64. data/lib/mongomodel/support/core_extensions.rb +1 -1
  65. data/lib/mongomodel/support/dynamic_finder.rb +12 -12
  66. data/lib/mongomodel/support/exceptions.rb +6 -6
  67. data/lib/mongomodel/support/instrumented_collection.rb +20 -20
  68. data/lib/mongomodel/support/map.rb +33 -33
  69. data/lib/mongomodel/support/mongo_operator.rb +6 -6
  70. data/lib/mongomodel/support/mongo_options.rb +18 -18
  71. data/lib/mongomodel/support/mongo_order.rb +16 -16
  72. data/lib/mongomodel/support/paginator.rb +8 -8
  73. data/lib/mongomodel/support/reference.rb +10 -10
  74. data/lib/mongomodel/support/scope.rb +37 -37
  75. data/lib/mongomodel/support/scope/array_methods.rb +1 -1
  76. data/lib/mongomodel/support/scope/batches.rb +1 -1
  77. data/lib/mongomodel/support/scope/dynamic_finders.rb +1 -1
  78. data/lib/mongomodel/support/scope/finder_methods.rb +7 -7
  79. data/lib/mongomodel/support/scope/load_methods.rb +1 -1
  80. data/lib/mongomodel/support/scope/pagination.rb +1 -1
  81. data/lib/mongomodel/support/scope/query_methods.rb +6 -6
  82. data/lib/mongomodel/support/scope/spawn_methods.rb +8 -8
  83. data/lib/mongomodel/support/types.rb +2 -2
  84. data/lib/mongomodel/support/types/array.rb +1 -1
  85. data/lib/mongomodel/support/types/boolean.rb +3 -3
  86. data/lib/mongomodel/support/types/custom.rb +3 -3
  87. data/lib/mongomodel/support/types/date.rb +2 -2
  88. data/lib/mongomodel/support/types/date_time.rb +6 -16
  89. data/lib/mongomodel/support/types/float.rb +1 -1
  90. data/lib/mongomodel/support/types/hash.rb +1 -1
  91. data/lib/mongomodel/support/types/integer.rb +13 -10
  92. data/lib/mongomodel/support/types/object.rb +5 -5
  93. data/lib/mongomodel/support/types/rational.rb +3 -3
  94. data/lib/mongomodel/support/types/time.rb +2 -2
  95. data/lib/mongomodel/version.rb +1 -1
  96. data/lib/rails/generators/mongo_model/config/templates/mongomodel.yml +3 -4
  97. data/lib/rails/generators/mongo_model/model/model_generator.rb +3 -3
  98. data/mongomodel.gemspec +5 -4
  99. data/spec/mongomodel/attributes/store_spec.rb +21 -21
  100. data/spec/mongomodel/concerns/activemodel_spec.rb +4 -4
  101. data/spec/mongomodel/concerns/associations/base/association_spec.rb +12 -12
  102. data/spec/mongomodel/concerns/associations/belongs_to_spec.rb +34 -21
  103. data/spec/mongomodel/concerns/associations/has_many_by_foreign_key_spec.rb +53 -53
  104. data/spec/mongomodel/concerns/associations/has_many_by_ids_spec.rb +30 -30
  105. data/spec/mongomodel/concerns/attribute_methods/before_type_cast_spec.rb +7 -7
  106. data/spec/mongomodel/concerns/attribute_methods/dirty_spec.rb +45 -41
  107. data/spec/mongomodel/concerns/attribute_methods/multi_parameter_assignment_spec.rb +7 -7
  108. data/spec/mongomodel/concerns/attribute_methods/nested_spec.rb +31 -31
  109. data/spec/mongomodel/concerns/attribute_methods/protected_spec.rb +15 -15
  110. data/spec/mongomodel/concerns/attribute_methods/query_spec.rb +19 -19
  111. data/spec/mongomodel/concerns/attribute_methods/read_spec.rb +9 -9
  112. data/spec/mongomodel/concerns/attribute_methods/write_spec.rb +6 -6
  113. data/spec/mongomodel/concerns/attribute_methods_spec.rb +13 -13
  114. data/spec/mongomodel/concerns/attributes_spec.rb +34 -34
  115. data/spec/mongomodel/concerns/callbacks_spec.rb +25 -21
  116. data/spec/mongomodel/concerns/logging_spec.rb +5 -3
  117. data/spec/mongomodel/concerns/map_reduce_spec.rb +19 -19
  118. data/spec/mongomodel/concerns/observing_spec.rb +3 -3
  119. data/spec/mongomodel/concerns/pretty_inspect_spec.rb +10 -10
  120. data/spec/mongomodel/concerns/properties_spec.rb +11 -11
  121. data/spec/mongomodel/concerns/serialization/json_serialization_spec.rb +13 -13
  122. data/spec/mongomodel/concerns/timestamps_spec.rb +39 -39
  123. data/spec/mongomodel/concerns/validations_spec.rb +41 -38
  124. data/spec/mongomodel/document/callbacks_spec.rb +20 -16
  125. data/spec/mongomodel/document/collection_modifiers_spec.rb +16 -16
  126. data/spec/mongomodel/document/dynamic_finders_spec.rb +46 -46
  127. data/spec/mongomodel/document/finders_spec.rb +15 -15
  128. data/spec/mongomodel/document/indexes_spec.rb +29 -29
  129. data/spec/mongomodel/document/optimistic_locking_spec.rb +16 -16
  130. data/spec/mongomodel/document/persistence_spec.rb +39 -39
  131. data/spec/mongomodel/document/scopes_spec.rb +17 -17
  132. data/spec/mongomodel/document/validations/uniqueness_spec.rb +46 -46
  133. data/spec/mongomodel/document/validations_spec.rb +35 -35
  134. data/spec/mongomodel/document_spec.rb +19 -19
  135. data/spec/mongomodel/embedded_document_spec.rb +19 -19
  136. data/spec/mongomodel/mongomodel_spec.rb +7 -6
  137. data/spec/mongomodel/support/collection_spec.rb +54 -54
  138. data/spec/mongomodel/support/configuration_spec.rb +1 -1
  139. data/spec/mongomodel/support/map_spec.rb +66 -66
  140. data/spec/mongomodel/support/mongo_operator_spec.rb +5 -5
  141. data/spec/mongomodel/support/mongo_options_spec.rb +42 -42
  142. data/spec/mongomodel/support/mongo_order_spec.rb +24 -24
  143. data/spec/mongomodel/support/paginator_spec.rb +15 -15
  144. data/spec/mongomodel/support/property_spec.rb +29 -23
  145. data/spec/mongomodel/support/scope_spec.rb +205 -204
  146. data/spec/spec_helper.rb +13 -2
  147. data/spec/support/callbacks.rb +3 -8
  148. data/spec/support/helpers/define_class.rb +7 -7
  149. data/spec/support/helpers/document_finder_stubs.rb +6 -6
  150. data/spec/support/helpers/specs_for.rb +1 -1
  151. data/spec/support/helpers/validations.rb +1 -1
  152. data/spec/support/matchers/find_with.rb +8 -8
  153. data/spec/support/matchers/respond_to_boolean.rb +3 -3
  154. data/spec/support/matchers/run_callbacks.rb +6 -9
  155. data/spec/support/models.rb +5 -5
  156. metadata +23 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0ecf9f958c03a225872acdf72dca43ff7d6fc52d
4
- data.tar.gz: fcca66094d1b48857a28792c12364d49ae057593
2
+ SHA256:
3
+ metadata.gz: 619c79fda7efe88d443078fcc4070ab954a942429b1710090b1bf094042c9b76
4
+ data.tar.gz: b5c73c1d569db35d3da9c41d4984d24e63ca363c02ff0f389d38e30bafab6c90
5
5
  SHA512:
6
- metadata.gz: a6a69c5fddc9745f8db566ad2931ee0f5069e8047f0ca834eb08c3bb6ac8d1f4201f21ca3f3f5de0267efc86a054330a2586d23adb0a63dbf01b8ed8bf60424f
7
- data.tar.gz: bfefd11ce4643a8990c315aba9faa422cedbc026b1179e6cc7d4e2c4b69682139b1cb58ba0dd025ec38bf52bcc6d1cc7d043b3164483ae3a903cc17582d35885
6
+ metadata.gz: 6bef0fddd9ed4059e5f97ed98fd335299cc2f52d51b44973c9d8b7befb7e7c66abdd057065258d70d02d5f2a874eb2c1b4cab8ca59b31d5710a556aa7423f644
7
+ data.tar.gz: 16b56dacd31e9b4335a049c00bf2eec21346827ef71be8393399f846ea66994ba441c30205c8f1de0267416bff34ff24878b9b29ec9ddcbb629efc9b23ed4d31
@@ -1,18 +1,30 @@
1
1
  language: ruby
2
2
 
3
- services:
4
- - mongodb
3
+ before_install:
4
+ - gem update bundler
5
+
6
+ env:
7
+ - MONGODB=3.2.19
8
+
9
+ install:
10
+ - wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB}.tgz
11
+ - tar xzf mongodb-linux-x86_64-${MONGODB}.tgz
12
+ - ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --version
13
+ - bundle install
14
+
15
+ before_script:
16
+ - mkdir ${PWD}/mongodb-linux-x86_64-${MONGODB}/data
17
+ - ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --dbpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/data --logpath ${PWD}/mongodb-linux-x86_64-${MONGODB}/mongodb.log --fork
18
+
19
+ after_script:
20
+ - pkill mongod
5
21
 
6
22
  rvm:
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1.0
23
+ - 2.3.1
10
24
 
11
25
  gemfile:
12
- - gemfiles/rails-3.1.gemfile
13
26
  - gemfiles/rails-3.2.gemfile
14
- - gemfiles/rails-4.0.gemfile
15
- - gemfiles/rails-4.1.gemfile
16
- - gemfiles/rails-4-observers.gemfile
17
- - gemfiles/mongo_mapper.gemfile
18
- - gemfiles/mongoid.gemfile
27
+ - gemfiles/rails-4.2.gemfile
28
+ - gemfiles/rails-5.0.gemfile
29
+ - gemfiles/rails-5.1.gemfile
30
+ - gemfiles/rails-5.2.gemfile
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activesupport", "3.2.17"
4
- gem "activemodel", "3.2.17"
3
+ gem "activesupport", "3.2.22.5"
4
+ gem "activemodel", "3.2.22.5"
5
5
 
6
6
  gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "activesupport", :github => "rails/rails", :branch => "4-0-stable"
4
4
  gem "activemodel", :github => "rails/rails", :branch => "4-0-stable"
5
- gem "rails-observers", :github => "rails/rails-observers"
5
+ gem "rails-observers", "0.1.2"
6
6
 
7
7
  gem "bson_ext", "~> 1.8"
8
8
  gem "tzinfo"
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activesupport", :github => "rails/rails", :branch => "4-1-stable"
4
- gem "activemodel", :github => "rails/rails", :branch => "4-1-stable"
3
+ gem "activesupport", "4.1.16"
4
+ gem "activemodel", "4.1.16"
5
5
 
6
6
  gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
@@ -1,8 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activesupport", "3.2.13"
4
- gem "activemodel", "3.2.13"
5
- gem "mongoid"
3
+ gem "activesupport", "4.2.10"
4
+ gem "activemodel", "4.2.10"
6
5
 
7
6
  gem "bson_ext", "~> 1.8"
8
7
  gem "tzinfo"
@@ -1,8 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activesupport", "3.2.13"
4
- gem "activemodel", "3.2.13"
5
- gem "mongo_mapper"
3
+ gem "activesupport", "5.0.7"
4
+ gem "activemodel", "5.0.7"
6
5
 
7
6
  gem "bson_ext", "~> 1.8"
8
7
  gem "tzinfo"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activesupport", "5.1.6"
4
+ gem "activemodel", "5.1.6"
5
+
6
+ gem "bson_ext", "~> 1.8"
7
+ gem "tzinfo"
8
+ gem "rake"
9
+
10
+ gemspec :path => "../"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "activesupport", "5.2.0"
4
+ gem "activemodel", "5.2.0"
5
+
6
+ gem "bson_ext", "~> 1.8"
7
+ gem "tzinfo"
8
+ gem "rake"
9
+
10
+ gemspec :path => "../"
@@ -18,10 +18,10 @@ end
18
18
 
19
19
  module MongoModel
20
20
  autoload :VERSION, 'mongomodel/version'
21
-
21
+
22
22
  autoload :Document, 'mongomodel/document'
23
23
  autoload :EmbeddedDocument, 'mongomodel/embedded_document'
24
-
24
+
25
25
  autoload :Properties, 'mongomodel/concerns/properties'
26
26
  autoload :Attributes, 'mongomodel/concerns/attributes'
27
27
  autoload :AttributeMethods, 'mongomodel/concerns/attribute_methods'
@@ -40,7 +40,7 @@ module MongoModel
40
40
  autoload :DocumentParent, 'mongomodel/concerns/document_parent'
41
41
  autoload :MapReduce, 'mongomodel/concerns/map_reduce'
42
42
  autoload :ActiveModelCompatibility, 'mongomodel/concerns/activemodel'
43
-
43
+
44
44
  autoload :Reference, 'mongomodel/support/reference'
45
45
  autoload :MongoOptions, 'mongomodel/support/mongo_options'
46
46
  autoload :MongoOrder, 'mongomodel/support/mongo_order'
@@ -52,10 +52,10 @@ module MongoModel
52
52
  autoload :URIConfiguration, 'mongomodel/support/configuration'
53
53
  autoload :DynamicFinder, 'mongomodel/support/dynamic_finder'
54
54
  autoload :InstrumentedCollection, 'mongomodel/support/instrumented_collection'
55
-
55
+
56
56
  autoload :Collection, 'mongomodel/support/collection'
57
57
  autoload :Map, 'mongomodel/support/map'
58
-
58
+
59
59
  module AttributeMethods
60
60
  autoload :Read, 'mongomodel/concerns/attribute_methods/read'
61
61
  autoload :Write, 'mongomodel/concerns/attribute_methods/write'
@@ -67,25 +67,25 @@ module MongoModel
67
67
  autoload :Nested, 'mongomodel/concerns/attribute_methods/nested'
68
68
  autoload :MultiParameterAssignment, 'mongomodel/concerns/attribute_methods/multi_parameter_assignment'
69
69
  end
70
-
70
+
71
71
  module Attributes
72
72
  autoload :Store, 'mongomodel/attributes/store'
73
73
  autoload :Typecasting, 'mongomodel/attributes/typecasting'
74
74
  autoload :Mongo, 'mongomodel/attributes/mongo'
75
75
  end
76
-
76
+
77
77
  module Associations
78
78
  module Base
79
79
  autoload :Definition, 'mongomodel/concerns/associations/base/definition'
80
80
  autoload :Association, 'mongomodel/concerns/associations/base/association'
81
81
  autoload :Proxy, 'mongomodel/concerns/associations/base/proxy'
82
82
  end
83
-
83
+
84
84
  autoload :BelongsTo, 'mongomodel/concerns/associations/belongs_to'
85
85
  autoload :HasManyByIds, 'mongomodel/concerns/associations/has_many_by_ids'
86
86
  autoload :HasManyByForeignKey, 'mongomodel/concerns/associations/has_many_by_foreign_key'
87
87
  end
88
-
88
+
89
89
  module DocumentExtensions
90
90
  autoload :Persistence, 'mongomodel/document/persistence'
91
91
  autoload :OptimisticLocking, 'mongomodel/document/optimistic_locking'
@@ -96,13 +96,13 @@ module MongoModel
96
96
  autoload :Callbacks, 'mongomodel/document/callbacks'
97
97
  autoload :CollectionModifiers, 'mongomodel/document/collection_modifiers'
98
98
  end
99
-
99
+
100
100
  mattr_accessor :logger
101
-
101
+
102
102
  def self.configuration
103
103
  @_configuration ||= Configuration.defaults
104
104
  end
105
-
105
+
106
106
  def self.configuration=(config)
107
107
  @_database = nil
108
108
  @_configuration = case config
@@ -112,13 +112,13 @@ module MongoModel
112
112
  URIConfiguration.new(config)
113
113
  end
114
114
  end
115
-
115
+
116
116
  def self.database
117
117
  @_database ||= configuration.establish_connection
118
118
  end
119
-
119
+
120
120
  require 'mongomodel/railtie' if defined?(Rails::Railtie)
121
-
121
+
122
122
  require 'mongomodel/compatibility/mongoid' if defined?(Mongoid)
123
123
  require 'mongomodel/compatibility/mongo_mapper' if defined?(MongoMapper)
124
124
  end
@@ -4,36 +4,36 @@ module MongoModel
4
4
  def to_mongo
5
5
  inject({}) do |result, (k, v)|
6
6
  property = properties[k]
7
-
7
+
8
8
  if property
9
9
  result[property.as] = property.to_mongo(v)
10
10
  else
11
11
  converter = Types.converter_for(v.class)
12
12
  result[k.to_s] = converter.to_mongo(v)
13
13
  end
14
-
14
+
15
15
  result
16
16
  end
17
17
  end
18
-
18
+
19
19
  def load!(hash)
20
20
  from_mongo!(hash)
21
21
  end
22
-
22
+
23
23
  def from_mongo!(hash)
24
24
  hash.each do |k, v|
25
25
  property = properties_as[k.to_s]
26
-
26
+
27
27
  if property
28
28
  child = store(property.name, property.from_mongo(v))
29
29
  else
30
30
  child = store(k.to_sym, v)
31
31
  end
32
-
32
+
33
33
  child.parent_document = instance if child.respond_to?(:parent_document=)
34
34
  end
35
35
  end
36
-
36
+
37
37
  private
38
38
  def properties_as
39
39
  @properties_as ||= properties.inject({}) do |result, (name, property)|
@@ -5,20 +5,20 @@ module MongoModel
5
5
  class Store < ActiveSupport::OrderedHash
6
6
  include Typecasting
7
7
  include Mongo
8
-
8
+
9
9
  attr_reader :instance
10
10
  delegate :properties, :to => :instance
11
-
11
+
12
12
  def initialize(instance)
13
13
  super()
14
14
  @instance = instance
15
15
  set_defaults!
16
16
  end
17
-
17
+
18
18
  def inspect
19
19
  "{#{map { |k, v| "#{k.inspect}=>#{v.inspect}"}.join(', ')}}"
20
20
  end
21
-
21
+
22
22
  private
23
23
  def set_defaults!
24
24
  properties.each do |name, property|
@@ -3,12 +3,12 @@ module MongoModel
3
3
  module Typecasting
4
4
  def []=(key, value)
5
5
  values_before_typecast[key] = value
6
-
6
+
7
7
  result = super(key, typecast(key, value))
8
8
  result.parent_document = instance if result.respond_to?(:parent_document=)
9
9
  result
10
10
  end
11
-
11
+
12
12
  # Check if key has a value that typecasts to true.
13
13
  #
14
14
  # attributes = Attributes::Store.new(:comments_count => Property.new(:comments_count, Integer))
@@ -25,24 +25,24 @@ module MongoModel
25
25
  value = self[key]
26
26
  boolean_typecast(key, value)
27
27
  end
28
-
28
+
29
29
  def before_type_cast(key)
30
30
  values_before_typecast[key]
31
31
  end
32
-
32
+
33
33
  private
34
34
  def store(key, value)
35
35
  values_before_typecast[key] = value
36
36
  super(key, value)
37
37
  end
38
-
38
+
39
39
  def typecast(key, value)
40
40
  unless value.nil?
41
41
  property = properties[key]
42
42
  property ? property.cast(value) : value
43
43
  end
44
44
  end
45
-
45
+
46
46
  def boolean_typecast(key, value)
47
47
  if property = properties[key]
48
48
  value ? property.boolean(value) : false
@@ -50,7 +50,7 @@ module MongoModel
50
50
  !!value
51
51
  end
52
52
  end
53
-
53
+
54
54
  def values_before_typecast
55
55
  @values_before_typecast ||= {}
56
56
  end
@@ -2,15 +2,15 @@ class SymbolOperator
2
2
  def to_mongo_operator
3
3
  MongoModel::MongoOperator.new(field, operator)
4
4
  end
5
-
5
+
6
6
  def to_mongo_order_clause
7
7
  MongoModel::MongoOrder::Clause.new(field, operator.to_s == 'asc' ? :ascending : :descending)
8
8
  end
9
-
9
+
10
10
  def eql?(other)
11
11
  self == other
12
12
  end
13
-
13
+
14
14
  def hash
15
15
  field.hash ^ operator.hash
16
16
  end
@@ -2,15 +2,15 @@ class Origin::Key
2
2
  def to_mongo_operator
3
3
  MongoModel::MongoOperator.new(name, operator.sub(/^\$/, ""))
4
4
  end
5
-
5
+
6
6
  def to_mongo_order_clause
7
7
  MongoModel::MongoOrder::Clause.new(name, operator == 1 ? :ascending : :descending)
8
8
  end
9
-
9
+
10
10
  def eql?(other)
11
11
  self == other
12
12
  end
13
-
13
+
14
14
  def hash
15
15
  name.hash ^ operator.hash
16
16
  end
@@ -1,15 +1,15 @@
1
1
  module MongoModel
2
2
  module AbstractClass
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  def inherited(subclass)
6
6
  super
7
7
  subclass.abstract_class = false
8
8
  end
9
-
9
+
10
10
  module ClassMethods
11
11
  attr_accessor :abstract_class
12
-
12
+
13
13
  def abstract_class?
14
14
  abstract_class == true
15
15
  end
@@ -1,17 +1,17 @@
1
1
  module MongoModel
2
2
  module ActiveModelCompatibility
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  include ActiveModel::Conversion
6
-
6
+
7
7
  def persisted?
8
8
  !new_record?
9
9
  end
10
-
10
+
11
11
  def to_key
12
12
  persisted? ? super : nil
13
13
  end
14
-
14
+
15
15
  module ClassMethods
16
16
  include ActiveModel::Naming
17
17
  end
@@ -1,36 +1,36 @@
1
1
  module MongoModel
2
2
  module Associations
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  def associations
6
6
  @_associations ||= self.class.associations.inject({}) do |result, (name, association)|
7
7
  result[name] = association.for(self)
8
8
  result
9
9
  end
10
10
  end
11
-
11
+
12
12
  module ClassMethods
13
13
  def associations
14
14
  @_associations ||= {}
15
15
  end
16
-
16
+
17
17
  def associations=(associations)
18
18
  @_associations = associations
19
19
  end
20
-
20
+
21
21
  def belongs_to(name, options={})
22
22
  associations[name] = create_association(BelongsTo, name, options)
23
23
  end
24
-
24
+
25
25
  def has_many(name, options={})
26
26
  associations[name] = create_association(has_many_type(options), name, options)
27
27
  end
28
-
28
+
29
29
  def inherited(subclass)
30
30
  super
31
31
  subclass.associations = associations.dup
32
32
  end
33
-
33
+
34
34
  private
35
35
  def has_many_type(options)
36
36
  case options[:by]
@@ -42,7 +42,7 @@ module MongoModel
42
42
  ancestors.include?(Document) ? HasManyByForeignKey : HasManyByIds
43
43
  end
44
44
  end
45
-
45
+
46
46
  def create_association(type, name, options={})
47
47
  type.new(self, name, options).define!
48
48
  end