rackjson 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rackjson/document.rb +1 -1
- data/lib/rackjson/json_document.rb +2 -2
- data/lib/rackjson/mongo_document.rb +2 -2
- data/lib/rackjson/request.rb +2 -2
- data/rackjson.gemspec +2 -2
- data/test/test_document.rb +1 -1
- data/test/test_json_document.rb +1 -1
- data/test/test_mongo_document.rb +3 -3
- metadata +43 -20
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/rackjson/document.rb
CHANGED
@@ -27,8 +27,8 @@ module Rack::JSON
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def set_attribute_ids
|
30
|
-
@attributes["_id"] =
|
31
|
-
rescue
|
30
|
+
@attributes["_id"] = BSON::ObjectID.from_string(@attributes["_id"].to_s)
|
31
|
+
rescue BSON::InvalidObjectID
|
32
32
|
return false
|
33
33
|
end
|
34
34
|
|
@@ -12,11 +12,11 @@ module Rack::JSON
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def set_attribute_ids
|
15
|
-
@attributes["_id"] = @attributes["_id"].to_s if (@attributes["_id"].is_a?
|
15
|
+
@attributes["_id"] = @attributes["_id"].to_s if (@attributes["_id"].is_a? BSON::ObjectID)
|
16
16
|
end
|
17
17
|
|
18
18
|
def set_created_at
|
19
|
-
if @attributes["_id"].is_a?
|
19
|
+
if @attributes["_id"].is_a? BSON::ObjectID
|
20
20
|
@attributes["created_at"] = @attributes["_id"].generation_time unless @attributes["created_at"]
|
21
21
|
end
|
22
22
|
end
|
data/lib/rackjson/request.rb
CHANGED
@@ -29,8 +29,8 @@ module Rack::JSON
|
|
29
29
|
def resource_id
|
30
30
|
id_string = self.path_info.split('/').last.to_s
|
31
31
|
begin
|
32
|
-
|
33
|
-
rescue
|
32
|
+
BSON::ObjectID.from_string(id_string)
|
33
|
+
rescue BSON::InvalidObjectID
|
34
34
|
id_string.match(/^\d+$/) ? id_string.to_i : id_string
|
35
35
|
end
|
36
36
|
end
|
data/rackjson.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rackjson}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oliver Nightingale"]
|
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.homepage = %q{http://github.com/olivernn/rackjson}
|
45
45
|
s.rdoc_options = ["--charset=UTF-8"]
|
46
46
|
s.require_paths = ["lib"]
|
47
|
-
s.rubygems_version = %q{1.3.
|
47
|
+
s.rubygems_version = %q{1.3.6}
|
48
48
|
s.summary = %q{A rack end point for storing json documents.}
|
49
49
|
s.test_files = [
|
50
50
|
"test/helper.rb",
|
data/test/test_document.rb
CHANGED
@@ -22,7 +22,7 @@ class DocumentTest < Test::Unit::TestCase
|
|
22
22
|
def test_creating_from_json_with_id
|
23
23
|
json = '{"_id": "4b9f783ba040140525000001", "test":"hello"}'
|
24
24
|
document = Rack::JSON::Document.new(json)
|
25
|
-
assert_equal(
|
25
|
+
assert_equal(BSON::ObjectID.from_string('4b9f783ba040140525000001'), document.attributes["_id"])
|
26
26
|
assert_equal("hello", document.attributes["test"])
|
27
27
|
assert_equal(Time.now.to_s, document.attributes["created_at"].to_s)
|
28
28
|
assert_equal(Time.now.to_s, document.attributes["updated_at"].to_s)
|
data/test/test_json_document.rb
CHANGED
@@ -24,7 +24,7 @@ class JSONDocumentTest < Test::Unit::TestCase
|
|
24
24
|
def test_parsing_mongo_object_id
|
25
25
|
hash = { "_id" => "4ba7e82ca04014011c000001" }
|
26
26
|
doc = JSON.generate hash
|
27
|
-
assert_equal(
|
27
|
+
assert_equal(BSON::ObjectID.from_string("4ba7e82ca04014011c000001"), Rack::JSON::JSONDocument.new(doc).attributes["_id"])
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_parsing_non_mongo_object_ids
|
data/test/test_mongo_document.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
class MongoDocumentTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_stringifying_mongo_object_ids
|
6
|
-
hash = { "_id" =>
|
6
|
+
hash = { "_id" => BSON::ObjectID.from_string("4ba7e82ca04014011c000001") }
|
7
7
|
doc = Rack::JSON::MongoDocument.new(hash).attributes
|
8
8
|
assert_equal("4ba7e82ca04014011c000001", doc["_id"])
|
9
9
|
end
|
@@ -15,10 +15,10 @@ class MongoDocumentTest < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_setting_the_created_at_stamp
|
18
|
-
hash = { "_id" =>
|
18
|
+
hash = { "_id" => BSON::ObjectID.from_string("4ba7e82ca04014011c000001") }
|
19
19
|
doc = Rack::JSON::MongoDocument.new(hash).attributes
|
20
20
|
assert_equal({ "_id" => "4ba7e82ca04014011c000001",
|
21
|
-
"created_at" =>
|
21
|
+
"created_at" => BSON::ObjectID.from_string("4ba7e82ca04014011c000001").generation_time
|
22
22
|
}, doc)
|
23
23
|
end
|
24
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackjson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Oliver Nightingale
|
@@ -14,44 +19,60 @@ default_executable:
|
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: mongo
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 19
|
30
|
+
- 1
|
23
31
|
version: 0.19.1
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: mongo_ext
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 19
|
44
|
+
- 1
|
33
45
|
version: 0.19.1
|
34
|
-
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: json
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 2
|
58
|
+
- 3
|
43
59
|
version: 1.2.3
|
44
|
-
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
45
62
|
- !ruby/object:Gem::Dependency
|
46
63
|
name: rack
|
47
|
-
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
66
|
requirements:
|
51
67
|
- - ">="
|
52
68
|
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 0
|
72
|
+
- 1
|
53
73
|
version: 1.0.1
|
54
|
-
|
74
|
+
type: :runtime
|
75
|
+
version_requirements: *id004
|
55
76
|
description: A rack end point for storing json documents.
|
56
77
|
email: oliver.n@new-bamboo.co.uk
|
57
78
|
executables: []
|
@@ -98,18 +119,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
119
|
requirements:
|
99
120
|
- - ">="
|
100
121
|
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
101
124
|
version: "0"
|
102
|
-
version:
|
103
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
126
|
requirements:
|
105
127
|
- - ">="
|
106
128
|
- !ruby/object:Gem::Version
|
129
|
+
segments:
|
130
|
+
- 0
|
107
131
|
version: "0"
|
108
|
-
version:
|
109
132
|
requirements: []
|
110
133
|
|
111
134
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.3.
|
135
|
+
rubygems_version: 1.3.6
|
113
136
|
signing_key:
|
114
137
|
specification_version: 3
|
115
138
|
summary: A rack end point for storing json documents.
|