mongocore 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/config/db/schema/model.yml +7 -0
- data/lib/mongocore/document.rb +5 -5
- data/lib/mongocore/query.rb +1 -23
- data/lib/mongocore/schema.rb +31 -14
- data/lib/mongocore.rb +1 -1
- data/mongocore.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc69ea47a26f1a85fd3519180999a21710800a44
|
4
|
+
data.tar.gz: 523eaba0048b6d6f887bf4b1647f2f6f1ba8ecb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1129eb75394fa108c0c701bf2c8722c8cca9b886c4e3ff2d8eb1c9d496e98b46bb69af066489ae0f4158eb67394f2e1ea193a222544bed0f7f16831224db803d
|
7
|
+
data.tar.gz: 05f1db2a8a7077981fb1690906e8c0e328fc531ff740a2ad226b6fb3d819347e9fb4b1426edaa91da8d945656d39f1bab347d77fc447159df857962162b8259f
|
data/README.md
CHANGED
@@ -239,6 +239,7 @@ keys:
|
|
239
239
|
|
240
240
|
# Define the _id field for all your models. The id field (without _)
|
241
241
|
# is an alias to _id, but always returns a string instead of a BSON::ObjectId
|
242
|
+
# Any object ids as strings will be automatically converted into ObjectIds
|
242
243
|
# @desc: Describes the key, can be used for documentation.
|
243
244
|
# @type: object_id, string, integer, float, boolean, time, hash, array
|
244
245
|
# @default: the default value for the key when you call .new
|
data/config/db/schema/model.yml
CHANGED
data/lib/mongocore/document.rb
CHANGED
@@ -221,11 +221,6 @@ module Mongocore
|
|
221
221
|
@_id ? @_id.to_s : nil
|
222
222
|
end
|
223
223
|
|
224
|
-
# Replace _id with id, takes a hash
|
225
|
-
def string_id(a)
|
226
|
-
a.each{|k, v| a[k] = v.to_s if v.is_a?(BSON::ObjectId)}; a.delete(:_id); {:id => id}.merge(a)
|
227
|
-
end
|
228
|
-
|
229
224
|
# Print info about the instance
|
230
225
|
def inspect
|
231
226
|
"#<#{self.class} #{attributes.sort.map{|r| %{#{r[0]}: #{r[1].inspect}}}.join(', ')}>"
|
@@ -242,6 +237,11 @@ module Mongocore
|
|
242
237
|
filter(type){one.send((@saved ? :update : :insert), attributes).ok?}
|
243
238
|
end
|
244
239
|
|
240
|
+
# Replace _id with id, takes a hash
|
241
|
+
def string_id(a)
|
242
|
+
a.delete(:_id); {:id => id}.merge(a)
|
243
|
+
end
|
244
|
+
|
245
245
|
end
|
246
246
|
|
247
247
|
|
data/lib/mongocore/query.rb
CHANGED
@@ -26,7 +26,7 @@ module Mongocore
|
|
26
26
|
|
27
27
|
# Storing query and options. Sort and limit is stored in options
|
28
28
|
s[:sort] ||= {}; s[:limit] ||= 0; s[:chain] ||= []; s[:source] ||= nil; s[:fields] ||= {}; s[:skip] ||= 0
|
29
|
-
@query, @options, @store = ids(
|
29
|
+
@query, @options, @store = @model.schema.ids(hashify(q)), o, s
|
30
30
|
|
31
31
|
# Set up cache
|
32
32
|
@cache = Mongocore::Cache.new(self)
|
@@ -43,28 +43,6 @@ module Mongocore
|
|
43
43
|
q.is_a?(Hash) ? q : {:_id => q}
|
44
44
|
end
|
45
45
|
|
46
|
-
# Setup query, replace :id with :_id, set up ObjectIds
|
47
|
-
def ids(h)
|
48
|
-
h.each do |k, v|
|
49
|
-
case v
|
50
|
-
when Hash
|
51
|
-
# Call hashes recursively
|
52
|
-
ids(transform(v))
|
53
|
-
when Array
|
54
|
-
# Return mapped array or recurse hashes
|
55
|
-
h[k] = v.map{|r| r.is_a?(Hash) ? ids(transform(r)) : @model.schema.oid(r)}
|
56
|
-
else
|
57
|
-
# Convert to object ID if applicable
|
58
|
-
h[k] = @model.schema.oid(v) if v.is_a?(String)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Transform :id to :_id
|
64
|
-
def transform(h)
|
65
|
-
h.transform_keys!{|k| k == :id ? :_id : k}
|
66
|
-
end
|
67
|
-
|
68
46
|
# Cursor
|
69
47
|
def cursor
|
70
48
|
@collection.find(@query, @options).projection(@store[:fields]).skip(@store[:skip]).sort(@store[:sort]).limit(@store[:limit])
|
data/lib/mongocore/schema.rb
CHANGED
@@ -46,24 +46,41 @@ module Mongocore
|
|
46
46
|
# Convert type if val and schema type is set
|
47
47
|
def convert(key, val)
|
48
48
|
return nil if val.nil?
|
49
|
-
case
|
50
|
-
when :string
|
51
|
-
|
52
|
-
when :
|
53
|
-
|
54
|
-
when :
|
55
|
-
|
56
|
-
|
57
|
-
val.to_s.to_bool
|
58
|
-
when :object_id
|
59
|
-
oid(val)
|
60
|
-
else
|
61
|
-
val
|
49
|
+
case type(key)
|
50
|
+
when :string then val.to_s
|
51
|
+
when :integer then val.to_i
|
52
|
+
when :float then val.to_f
|
53
|
+
when :boolean then val.to_s.to_bool
|
54
|
+
when :object_id then oid(val)
|
55
|
+
when :array, :hash then ids(val)
|
56
|
+
else val
|
62
57
|
end
|
63
58
|
end
|
64
59
|
|
60
|
+
# Setup query, replace :id with :_id, set up object ids
|
61
|
+
def ids(h)
|
62
|
+
transform(h).each do |k, v|
|
63
|
+
case v
|
64
|
+
when Hash
|
65
|
+
# Call hashes recursively
|
66
|
+
ids(v)
|
67
|
+
when Array
|
68
|
+
# Return mapped array or recurse hashes
|
69
|
+
v.map!{|r| r.is_a?(Hash) ? ids(r) : oid(r)}
|
70
|
+
else
|
71
|
+
# Convert to object ID if applicable
|
72
|
+
h[k] = oid(v) if v.is_a?(String)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Transform :id to _id or id to object id
|
78
|
+
def transform(e)
|
79
|
+
e.is_a?(Hash) ? e.transform_keys!{|k| k == :id ? :_id : k} : e.map!{|r| oid(r)}
|
80
|
+
end
|
81
|
+
|
65
82
|
# Find type as defined in schema
|
66
|
-
def
|
83
|
+
def type(key)
|
67
84
|
@keys[key][:type].to_sym rescue :string
|
68
85
|
end
|
69
86
|
|
data/lib/mongocore.rb
CHANGED
data/mongocore.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mongocore'
|
3
|
-
s.version = '0.2.
|
4
|
-
s.date = '2017-10-
|
3
|
+
s.version = '0.2.3'
|
4
|
+
s.date = '2017-10-28'
|
5
5
|
s.summary = "MongoDB ORM implementation on top of the Ruby MongoDB driver"
|
6
6
|
s.description = "Does validations, associations, scopes, filters, pagination, counter cache, request cache, and nested queries. Using a YAML schema file, which supports default values, data types, and security levels for each key."
|
7
7
|
s.authors = ["Fugroup Limited"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongocore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fugroup Limited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|