related 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,6 +3,16 @@ Related
3
3
 
4
4
  Related is a Redis-backed high performance graph database.
5
5
 
6
+ Raison d'être
7
+ -------------
8
+
9
+ Related is meant to be a simple graph database that is fun, free and easy to
10
+ use. The intention is not to compete with industrial grade graph databases
11
+ like Neo4j, but rather to be a replacement for a relational database when your
12
+ data is better described as a graph. For example when building social
13
+ software. Related is meant to be web scale, but ultimately relies on the
14
+ ability of Redis to scale (using Redis cluster for example).
15
+
6
16
  Setup
7
17
  -----
8
18
 
@@ -49,6 +49,14 @@ module Related
49
49
  find_many(args.flatten, options)
50
50
  end
51
51
 
52
+ def as_json(options = {})
53
+ (attributes || {}).merge(:id => self.id)
54
+ end
55
+
56
+ def to_json(options = {})
57
+ as_json.to_json(options)
58
+ end
59
+
52
60
  private
53
61
 
54
62
  def create_or_update
@@ -57,13 +65,13 @@ module Related
57
65
 
58
66
  def create
59
67
  @id = Related.generate_id
60
- @attributes.merge!(:created_at => Time.now.utc)
68
+ @attributes.merge!(:created_at => Time.now.utc.iso8601)
61
69
  Related.redis.hmset(@id, *@attributes.to_a.flatten)
62
70
  self
63
71
  end
64
72
 
65
73
  def update
66
- @attributes.merge!(:updated_at => Time.now.utc)
74
+ @attributes.merge!(:updated_at => Time.now.utc.iso8601)
67
75
  Related.redis.hmset(@id, *@attributes.to_a.flatten)
68
76
  self
69
77
  end
@@ -1,3 +1,3 @@
1
1
  module Related
2
- Version = VERSION = '0.2'
2
+ Version = VERSION = '0.2.1'
3
3
  end
data/lib/related.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'redis'
2
2
  require 'redis/namespace'
3
+ require 'json'
3
4
 
4
5
  require 'related/version'
5
6
  require 'related/helpers'
data/test/related_test.rb CHANGED
@@ -265,4 +265,19 @@ class RelatedTest < Test::Unit::TestCase
265
265
  assert_equal [node1], node2.incoming(:friends).intersect(node3.incoming(:friends)).to_a
266
266
  end
267
267
 
268
- end
268
+ def test_can_return_json
269
+ node = Related::Node.create(:name => 'test')
270
+ json = { :node => node }.to_json
271
+ json = JSON.parse(json)
272
+ assert_equal node.id, json['node']['id']
273
+ assert_equal node.name, json['node']['name']
274
+ end
275
+
276
+ def test_timestamps
277
+ node = Related::Node.create.save
278
+ node = Related::Node.find(node.id)
279
+ assert_match /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/, node.created_at
280
+ assert_match /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ$/, node.updated_at
281
+ end
282
+
283
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: related
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- version: "0.2"
9
+ - 1
10
+ version: 0.2.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Niklas Holmgren
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-09-14 00:00:00 +02:00
18
+ date: 2011-09-23 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -49,6 +50,22 @@ dependencies:
49
50
  version: 0.8.0
50
51
  type: :runtime
51
52
  version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 0
66
+ version: 1.0.0
67
+ type: :runtime
68
+ version_requirements: *id003
52
69
  description: Related is a Redis-backed high performance graph database.
53
70
  email: niklas@sutajio.se
54
71
  executables: []