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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f5279b423c7236ffb2ec14bd1e3a0452141ea85
4
- data.tar.gz: 4b14aa11206589e12ad7d300649a8908da0e01cb
3
+ metadata.gz: '0926f21e762a1dfd60a63bc58ba12c9fc9dccf1e'
4
+ data.tar.gz: c933d56aa6bff657ccefd65611dfc11199aa276b
5
5
  SHA512:
6
- metadata.gz: 51c7ccbd672e2eec11c19654c60fe424ea240699d9d5242a12840dbaccca49a5daa0cdcb41006f16b2f80d759a5745b1b44cb8310e41d793404721f64684b7f0
7
- data.tar.gz: 1a1c470e31454eede0c0c8bab19f8dcbeba44a76e3c654d379d4d1e874c683a8fc861595ffbbdb66cf77966ca834d963065745ccf953da0c1cef43e1b21f11cf
6
+ metadata.gz: 7c1ee0350b7569e1e2883701710834df7612a78f687c6607e7091053892e7bd76cebd2f5590bded66a5fec3f7b0f5719248b1a8d9406ca77af54ba4fcba1aabe
7
+ data.tar.gz: 72139c91f9d3291ad023bce34cb8c786a2d26e417a171e7b438fdf28c41db99a9615432cb90743a3372769aae5ec6a110dbf5329d4d8e6e454435a767c1e21b8
@@ -121,11 +121,10 @@ module Mongocore
121
121
  end
122
122
 
123
123
  # JSON format
124
- def as_json(options = {})
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)
@@ -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
- fetch(:to_a).map{|d| modelize(d)}.tap{|r| r.total = total}
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
@@ -7,7 +7,7 @@ require 'mongo'
7
7
  require 'request_store'
8
8
 
9
9
  module Mongocore
10
- VERSION = '0.1.8'
10
+ VERSION = '0.1.9'
11
11
 
12
12
  # # # # # #
13
13
  # Mongocore Ruby Database Driver.
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.8'
4
- s.date = '2017-10-24'
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.8
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-24 00:00:00.000000000 Z
11
+ date: 2017-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo