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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ff192d91a6dfaf4350bec27e4e7d38fe7e09977
4
- data.tar.gz: 051ecb04e44346713c928d3c1be36cdf479e7d64
3
+ metadata.gz: 6856d777caa8595d0a7275b01172316b298e28b9
4
+ data.tar.gz: 81c9d9781759dbb2057761d3c316263f669c0530
5
5
  SHA512:
6
- metadata.gz: a6738367cfc8453bd6d0ecbc902d459694fe811f35dad39c5c5213ba9d688b049cdb36c45e12371db6c60b99bbc87296cedcbd1935429c7a74d68af4a7866cc4
7
- data.tar.gz: 6e4fd6c84be158b4e8c516189100d57a0d2ea5ef548dae8fb34f04fc4fd7898db0b35e62f9ff57bd3a70dd5dfdde17a16bd766555185daf083fa9f4b51ac25dc
6
+ metadata.gz: 9b8c1cb6a323842b79f81f0f72ff71a360ac592392aa4835345b4c27b07071a3d5e6945e02c1648b9424d42b3c486d3b6db0abb5d1d51b254508ab2c17244ae6
7
+ data.tar.gz: 032ffad1baf8ea46681ac7e0ec32d70d4c1e42c56e1a5a1656eddb6a09e914615de2739933fe9683af10552c9e10fc19585319e170ecc08ab2b47afb07c8e3e6
@@ -1,7 +1,7 @@
1
1
  module StoresInMongo
2
2
  module Base
3
- def stores_in_mongo(field)
4
- ::StoresInMongo::Builder.new(self, field).build
3
+ def stores_in_mongo(field, data_type = Hash)
4
+ ::StoresInMongo::Builder.new(self, field, data_type).build
5
5
  end
6
6
  end
7
7
  end
@@ -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 => Hash, default: {}
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stores_in_mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Schwartz