stores_in_mongo 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/base.rb +1 -20
- data/lib/builder.rb +44 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d133e1bb324308e0b917c2d02f529b2e45cfc4cb
|
4
|
+
data.tar.gz: 14728962506a368394f4f2154c78c56e8661aade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d71b54e687957bb3ba3768c754457e6e692821f4d2764a3544d266b12ab092f064ac6345ce1d3b0b44a2a042e072f6a863d86c0c1e686b96cfef5c61e323531
|
7
|
+
data.tar.gz: 8061cb775c3bbd4b0a142b20b23da0a5b1f9a3d842d89540b82c739605f936567ce588c297fad88e9d306954f343de99d45628b13d2a8fedb410dfe6bdfc8e0f
|
data/lib/base.rb
CHANGED
@@ -1,26 +1,7 @@
|
|
1
1
|
module StoresInMongo
|
2
2
|
module Base
|
3
3
|
def stores_in_mongo(field)
|
4
|
-
|
5
|
-
self.mongo_data_field = field.to_s
|
6
|
-
include StoresInMongo::DocumentMethods
|
7
|
-
|
8
|
-
before_save :save_document
|
9
|
-
before_destroy :destroy_document
|
10
|
-
|
11
|
-
klass = const_set("MongoDocument", Class.new)
|
12
|
-
klass.include Mongoid::Document
|
13
|
-
klass.include Mongoid::Timestamps
|
14
|
-
klass.field self.mongo_data_field.to_sym, :type => Hash, default: {}
|
15
|
-
|
16
|
-
# TODO: allow customization `document` name
|
17
|
-
define_method(self.mongo_data_field) do |reload = false|
|
18
|
-
document(reload)[self.mongo_data_field]
|
19
|
-
end
|
20
|
-
|
21
|
-
define_method(self.mongo_data_field + "=") do |data|
|
22
|
-
document[self.mongo_data_field] = data
|
23
|
-
end
|
4
|
+
::StoresInMongo::Builder.new(self, field).build
|
24
5
|
end
|
25
6
|
end
|
26
7
|
end
|
data/lib/builder.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module StoresInMongo
|
2
|
+
class Builder
|
3
|
+
|
4
|
+
def initialize(model, field)
|
5
|
+
@model = model
|
6
|
+
@field = field.to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def build
|
10
|
+
@model.class_attribute :mongo_data_field
|
11
|
+
@model.mongo_data_field = @field
|
12
|
+
|
13
|
+
document_methods = build_document_methods_module
|
14
|
+
@model.instance_exec(document_methods) do |document_methods|
|
15
|
+
const_set("MongoDocumentMethods", document_methods)
|
16
|
+
include self::MongoDocumentMethods
|
17
|
+
|
18
|
+
before_save :save_document
|
19
|
+
before_destroy :destroy_document
|
20
|
+
|
21
|
+
mongo_klass = const_set("MongoDocument", Class.new)
|
22
|
+
mongo_klass.include Mongoid::Document
|
23
|
+
mongo_klass.include Mongoid::Timestamps
|
24
|
+
mongo_klass.field self.mongo_data_field.to_sym, :type => Hash, default: {}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_document_methods_module
|
29
|
+
mod = Module.new
|
30
|
+
mod.include(StoresInMongo::DocumentMethods)
|
31
|
+
mod.instance_exec(@model) do |model|
|
32
|
+
define_method(model.mongo_data_field) do |reload = false|
|
33
|
+
document(reload)[model.mongo_data_field]
|
34
|
+
end
|
35
|
+
|
36
|
+
define_method(model.mongo_data_field + "=") do |data|
|
37
|
+
document[model.mongo_data_field] = data
|
38
|
+
end
|
39
|
+
end
|
40
|
+
return mod
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
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.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Schwartz
|
@@ -9,7 +9,27 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-05-04 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mongoid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.0.0
|
13
33
|
description: Use stores_in_mongo <field> in an ActiveRecord object, use it as if it
|
14
34
|
were local. Includes ActiveRecord-like caching behavior.
|
15
35
|
email: ozydingo@gmail.com
|
@@ -18,6 +38,7 @@ extensions: []
|
|
18
38
|
extra_rdoc_files: []
|
19
39
|
files:
|
20
40
|
- lib/base.rb
|
41
|
+
- lib/builder.rb
|
21
42
|
- lib/document_methods.rb
|
22
43
|
- lib/stores_in_mongo.rb
|
23
44
|
homepage: https://github.com/ozydingo/stores_in_mongo
|