easymongo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +4 -7
- data/easymongo.gemspec +2 -2
- data/lib/easymongo/document.rb +10 -24
- 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: 358fd580d255a0fa18aec794cae7ea04a69b65f8
|
4
|
+
data.tar.gz: 1a2aa93b40bfbe10ee245f3ab7f997e8c9911351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22e087d5f0807696df516c6761876435d39a2cc9fdea360e9184892fe00ed6a06f018c9ff8f3d6ef992af8bad5ec8edae8eccc7a715d1d3d46f6f17f27f75a0b
|
7
|
+
data.tar.gz: 2f67a54e70d6fb0638dde10f5c163cf9220680e3cd0708b25f1684c1fcff5342f70f682b96fdd59b9da0976c760e738ff2ed657ca20f4375f70b792729241d61
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,13 +30,6 @@ user.bson_id => BSON::ObjectId('596675a40aec08bfe7271e14')
|
|
30
30
|
user.date => 2017-07-12 20:24:57 UTC
|
31
31
|
user.hello = 'Wake up' => Assign temporary value
|
32
32
|
|
33
|
-
# Hash annotation as well
|
34
|
-
user[:hello] => 'Wake up'
|
35
|
-
user.has_key?(:name) => true
|
36
|
-
|
37
|
-
# All these methods work on the document
|
38
|
-
http://www.rubydoc.info/github/mongodb/bson-ruby/master/BSON/Document
|
39
|
-
|
40
33
|
# Very flexible, also works like this for last and count
|
41
34
|
user = $db.users.first
|
42
35
|
user = $db.users.first(:id => '596675a40aec08bfe7271e14')
|
@@ -45,9 +38,13 @@ user = $db.users.first(:tv => 'tull')
|
|
45
38
|
user = $db.users.get(:food => 'healthy').first
|
46
39
|
|
47
40
|
# Last
|
41
|
+
$db.users.last
|
42
|
+
$db.users.last(:sun => 'close')
|
48
43
|
$db.users.get(:sun => 'close').last
|
49
44
|
|
50
45
|
# Count
|
46
|
+
$db.users.count
|
47
|
+
$db.users.count(:life => 'humancentric')
|
51
48
|
$db.users.get(:life => 'humancentric').count
|
52
49
|
|
53
50
|
# All
|
data/easymongo.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'easymongo'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2017-07-
|
3
|
+
s.version = '0.0.3'
|
4
|
+
s.date = '2017-07-13'
|
5
5
|
s.summary = "Super Easy MongoDB client"
|
6
6
|
s.description = "The way MongoDB for Ruby should be, can't get easier than this"
|
7
7
|
s.authors = ["Fugroup Limited"]
|
data/lib/easymongo/document.rb
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
module Easymongo
|
4
4
|
class Document
|
5
5
|
|
6
|
-
attr_accessor :doc, :values
|
7
|
-
|
8
6
|
# Takes a BSON::Document
|
9
7
|
def initialize(doc)
|
10
8
|
|
@@ -14,13 +12,13 @@ module Easymongo
|
|
14
12
|
# Convert all BSON::ObjectId to string
|
15
13
|
doc.each{|k, v| doc[k] = v.to_s if v.is_a?(BSON::ObjectId)}
|
16
14
|
|
17
|
-
#
|
18
|
-
|
15
|
+
# Write variables
|
16
|
+
doc.each{|k, v| attr(k, v)}
|
19
17
|
end
|
20
18
|
|
21
19
|
# Get bson id
|
22
20
|
def bson_id
|
23
|
-
@bson_id ||= BSON::ObjectId.from_string(
|
21
|
+
@bson_id ||= BSON::ObjectId.from_string(@id)
|
24
22
|
end
|
25
23
|
|
26
24
|
# Creation date
|
@@ -28,28 +26,16 @@ module Easymongo
|
|
28
26
|
bson_id.generation_time
|
29
27
|
end
|
30
28
|
|
31
|
-
#
|
32
|
-
def [](key)
|
33
|
-
doc[key.to_sym]
|
34
|
-
end
|
35
|
-
|
36
|
-
# Write value
|
37
|
-
def []=(key, value)
|
38
|
-
doc[key.to_sym] = value
|
39
|
-
end
|
40
|
-
|
41
|
-
# Make the doc user friendly with dot notation
|
42
|
-
# Provides access to doc object methods too
|
29
|
+
# Dynamically write value
|
43
30
|
def method_missing(name, *args, &block)
|
31
|
+
return attr(name[0..-2], args.first) if args.size == 1 and name[-1] == '='
|
32
|
+
end
|
44
33
|
|
45
|
-
|
46
|
-
return doc[name[0..-2].to_sym] = args.first if args.size == 1 and name[-1] == '='
|
47
|
-
|
48
|
-
# Read value
|
49
|
-
return doc[name] if doc.has_key?(name)
|
34
|
+
private
|
50
35
|
|
51
|
-
|
52
|
-
|
36
|
+
# Create accessor
|
37
|
+
def attr(k, v)
|
38
|
+
singleton_class.class_eval { attr_accessor k }; send("#{k}=", v)
|
53
39
|
end
|
54
40
|
|
55
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easymongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.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-07-
|
11
|
+
date: 2017-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|