stores_in_mongo 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stores_in_mongo/base.rb +2 -2
- data/lib/stores_in_mongo/builder.rb +4 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6856d777caa8595d0a7275b01172316b298e28b9
|
4
|
+
data.tar.gz: 81c9d9781759dbb2057761d3c316263f669c0530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b8c1cb6a323842b79f81f0f72ff71a360ac592392aa4835345b4c27b07071a3d5e6945e02c1648b9424d42b3c486d3b6db0abb5d1d51b254508ab2c17244ae6
|
7
|
+
data.tar.gz: 032ffad1baf8ea46681ac7e0ec32d70d4c1e42c56e1a5a1656eddb6a09e914615de2739933fe9683af10552c9e10fc19585319e170ecc08ab2b47afb07c8e3e6
|
data/lib/stores_in_mongo/base.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module StoresInMongo
|
2
2
|
class Builder
|
3
3
|
|
4
|
-
def initialize(model, field)
|
4
|
+
def initialize(model, field, data_type)
|
5
5
|
@model = model
|
6
6
|
@field = field.to_s
|
7
|
+
@data_type = data_type
|
7
8
|
end
|
8
9
|
|
9
10
|
def build
|
@@ -11,7 +12,7 @@ module StoresInMongo
|
|
11
12
|
@model.mongo_data_field = @field
|
12
13
|
|
13
14
|
document_methods = build_document_methods_module
|
14
|
-
@model.instance_exec(document_methods) do |document_methods|
|
15
|
+
@model.instance_exec(document_methods, @data_type) do |document_methods, data_type|
|
15
16
|
const_set("MongoDocumentMethods", document_methods)
|
16
17
|
include self::MongoDocumentMethods
|
17
18
|
|
@@ -21,7 +22,7 @@ module StoresInMongo
|
|
21
22
|
mongo_klass = const_set("MongoDocument", Class.new)
|
22
23
|
mongo_klass.include Mongoid::Document
|
23
24
|
mongo_klass.include Mongoid::Timestamps
|
24
|
-
mongo_klass.field self.mongo_data_field.to_sym, :type =>
|
25
|
+
mongo_klass.field self.mongo_data_field.to_sym, :type => data_type, default: data_type.try(:new)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|