mongocore 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mongocore/document.rb +5 -3
- data/lib/mongocore/query.rb +12 -6
- 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: '0926f21e762a1dfd60a63bc58ba12c9fc9dccf1e'
|
4
|
+
data.tar.gz: c933d56aa6bff657ccefd65611dfc11199aa276b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c1ee0350b7569e1e2883701710834df7612a78f687c6607e7091053892e7bd76cebd2f5590bded66a5fec3f7b0f5719248b1a8d9406ca77af54ba4fcba1aabe
|
7
|
+
data.tar.gz: 72139c91f9d3291ad023bce34cb8c786a2d26e417a171e7b438fdf28c41db99a9615432cb90743a3372769aae5ec6a110dbf5329d4d8e6e454435a767c1e21b8
|
data/lib/mongocore/document.rb
CHANGED
@@ -121,11 +121,10 @@ module Mongocore
|
|
121
121
|
end
|
122
122
|
|
123
123
|
# JSON format
|
124
|
-
def as_json(
|
125
|
-
string_id(attributes)
|
124
|
+
def as_json(o = {})
|
125
|
+
string_id(attributes(*o[:data]))
|
126
126
|
end
|
127
127
|
|
128
|
-
|
129
128
|
# # # # # # # # # # # # # # # #
|
130
129
|
# Validation methods
|
131
130
|
#
|
@@ -147,9 +146,11 @@ module Mongocore
|
|
147
146
|
|
148
147
|
# Saved? Persisted?
|
149
148
|
def saved?; !!@saved; end
|
149
|
+
alias_method :persisted?, :saved?
|
150
150
|
|
151
151
|
# Unsaved? New record?
|
152
152
|
def unsaved?; !@saved; end
|
153
|
+
alias_method :new_record?, :unsaved?
|
153
154
|
|
154
155
|
# Short cut for setting up a Mongocore::Query object
|
155
156
|
def mq(m, q = {}, o = {}, s = {})
|
@@ -250,6 +251,7 @@ module Mongocore
|
|
250
251
|
def find(*args)
|
251
252
|
mq(self, *args)
|
252
253
|
end
|
254
|
+
alias_method :where, :find
|
253
255
|
|
254
256
|
# Count
|
255
257
|
def count(*args)
|
data/lib/mongocore/query.rb
CHANGED
@@ -36,6 +36,7 @@ module Mongocore
|
|
36
36
|
def find(q = {}, o = {}, s = {})
|
37
37
|
self.class.new(@model, @query.merge(q.is_a?(Hash) ? q : {:_id => q}), @options.merge(o), @store.merge(s))
|
38
38
|
end
|
39
|
+
alias_method :where, :find
|
39
40
|
|
40
41
|
# Normalize query
|
41
42
|
def normalize(q)
|
@@ -102,11 +103,6 @@ module Mongocore
|
|
102
103
|
fetch(:to_a).map{|d| modelize(d)}
|
103
104
|
end
|
104
105
|
|
105
|
-
# Doc to model
|
106
|
-
def modelize(doc)
|
107
|
-
doc ? @model.new(doc.to_hash) : nil
|
108
|
-
end
|
109
|
-
|
110
106
|
# Paginate
|
111
107
|
def paginate(o = {})
|
112
108
|
# Get total count before applying pagination
|
@@ -125,7 +121,12 @@ module Mongocore
|
|
125
121
|
store[:limit] = o[:per_page]
|
126
122
|
|
127
123
|
# Fetch the result as array
|
128
|
-
|
124
|
+
all.tap{|r| r.total = total}
|
125
|
+
end
|
126
|
+
|
127
|
+
# BSON::Document to model
|
128
|
+
def modelize(doc)
|
129
|
+
doc ? @model.new(doc.to_hash) : nil
|
129
130
|
end
|
130
131
|
|
131
132
|
# Fetch docs, pass type :first, :to_a or :count
|
@@ -161,6 +162,11 @@ module Mongocore
|
|
161
162
|
find(@query, @options, @store.tap{store[:fields].merge!(o)})
|
162
163
|
end
|
163
164
|
|
165
|
+
# JSON format
|
166
|
+
def as_json(o = {})
|
167
|
+
all
|
168
|
+
end
|
169
|
+
|
164
170
|
# Cache key
|
165
171
|
def key
|
166
172
|
@key ||= "#{@model}#{@query.sort}#{@options.sort}#{@store.values}"
|
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.1.
|
4
|
-
s.date = '2017-10-
|
3
|
+
s.version = '0.1.9'
|
4
|
+
s.date = '2017-10-25'
|
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.1.
|
4
|
+
version: 0.1.9
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|