skydb 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.md +4 -0
  2. data/lib/ext/string.rb +11 -0
  3. data/lib/skydb.rb +88 -0
  4. data/lib/skydb/action.rb +57 -0
  5. data/lib/skydb/client.rb +216 -0
  6. data/lib/skydb/event.rb +114 -0
  7. data/lib/skydb/message.rb +134 -0
  8. data/lib/skydb/message/add_action.rb +53 -0
  9. data/lib/skydb/message/add_event.rb +72 -0
  10. data/lib/skydb/message/add_property.rb +55 -0
  11. data/lib/skydb/message/get_action.rb +55 -0
  12. data/lib/skydb/message/get_actions.rb +34 -0
  13. data/lib/skydb/message/get_properties.rb +34 -0
  14. data/lib/skydb/message/get_property.rb +55 -0
  15. data/lib/skydb/message/lua/map_reduce.rb +59 -0
  16. data/lib/skydb/message/multi.rb +57 -0
  17. data/lib/skydb/message/next_actions.rb +55 -0
  18. data/lib/skydb/property.rb +93 -0
  19. data/lib/skydb/property/type.rb +40 -0
  20. data/lib/skydb/timestamp.rb +22 -0
  21. data/lib/skydb/version.rb +3 -0
  22. data/test/client_test.rb +71 -0
  23. data/test/event_test.rb +37 -0
  24. data/test/message/add_action_message_test.rb +34 -0
  25. data/test/message/add_event_message_test.rb +35 -0
  26. data/test/message/add_property_message_test.rb +41 -0
  27. data/test/message/get_action_message_test.rb +34 -0
  28. data/test/message/get_actions_message_test.rb +18 -0
  29. data/test/message/get_properties_message_test.rb +18 -0
  30. data/test/message/get_property_message_test.rb +34 -0
  31. data/test/message/lua_map_reduce_message_test.rb +19 -0
  32. data/test/message/multi_message_test.rb +22 -0
  33. data/test/message/next_action_message_test.rb +34 -0
  34. data/test/message_test.rb +15 -0
  35. data/test/skydb_test.rb +20 -0
  36. data/test/test_helper.rb +12 -0
  37. metadata +166 -0
@@ -0,0 +1,34 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageAddAction < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::AddAction.new()
7
+ end
8
+
9
+ ######################################
10
+ # Action
11
+ ######################################
12
+
13
+ def test_action
14
+ @message.action = SkyDB::Action.new
15
+ refute_nil @message.action
16
+ end
17
+
18
+ def test_invalid_action
19
+ @message.action = "foo"
20
+ assert_nil @message.action
21
+ end
22
+
23
+
24
+ ######################################
25
+ # Encoding
26
+ ######################################
27
+
28
+ def test_encode
29
+ buffer = StringIO.new
30
+ @message.action = SkyDB::Action.new(:id => 0, :name => "foo")
31
+ @message.encode(buffer)
32
+ assert_bytes "\x93\x01\xaaadd_action\xa0\x82\xa2id\x00\xa4name\xa3foo", buffer
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageAddEvent < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::AddEvent.new()
7
+ end
8
+
9
+ ######################################
10
+ # Encoding
11
+ ######################################
12
+
13
+ def test_encode
14
+ buffer = StringIO.new
15
+ @message.table = "users"
16
+ @message.event = SkyDB::Event.new(
17
+ object_id: 12,
18
+ timestamp:DateTime.parse('2010-01-02T10:30:20Z'),
19
+ action: {
20
+ name:"/index.html",
21
+ astring:"foo",
22
+ aint:20
23
+ },
24
+ data: {
25
+ ostring: "bar",
26
+ oint: 10,
27
+ odouble: 100.1,
28
+ otrue: true,
29
+ ofalse: false
30
+ }
31
+ )
32
+ @message.encode(buffer)
33
+ assert_bytes "\x93\x01\xa9add_event\xa5users\x84\xa8objectId\x0c\xa9timestamp\xcf\x00\x04\x7c\x2b\xf9\x9b\x87\x00\xa6action\x83\xa4name\xab\x2findex\x2ehtml\xa7astring\xa3foo\xa4aint\x14\xa4data\x85\xa7ostring\xa3bar\xa4oint\x0a\xa7odouble\xcb\x40Y\x06fffff\xa5otrue\xc3\xa6ofalse\xc2", buffer
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageAddProperty < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::AddProperty.new()
7
+ end
8
+
9
+ ######################################
10
+ # Property
11
+ ######################################
12
+
13
+ def test_property
14
+ @message.property = SkyDB::Property.new
15
+ refute_nil @message.property
16
+ end
17
+
18
+ def test_invalid_property
19
+ @message.property = "foo"
20
+ assert_nil @message.property
21
+ end
22
+
23
+
24
+ ######################################
25
+ # Encoding
26
+ ######################################
27
+
28
+ def test_encode_object_property
29
+ buffer = StringIO.new
30
+ @message.property = SkyDB::Property.new(0, :object, 'Int', 'foo')
31
+ @message.encode(buffer)
32
+ assert_bytes "\x93\x01\xacadd_property\xa0\x84\xa2id\x00\xa4type\x01\xa8dataType\xa3Int\xa4name\xa3foo", buffer
33
+ end
34
+
35
+ def test_encode_action_property
36
+ buffer = StringIO.new
37
+ @message.property = SkyDB::Property.new(0, :action, 'Boolean', 'foo')
38
+ @message.encode(buffer)
39
+ assert_bytes "\x93\x01\xacadd_property\xa0\x84\xa2id\x00\xa4type\x02\xa8dataType\xa7Boolean\xa4name\xa3foo", buffer
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageGetAction < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::GetAction.new()
7
+ end
8
+
9
+ ######################################
10
+ # Action
11
+ ######################################
12
+
13
+ def test_action_id
14
+ @message.action_id = 12
15
+ assert_equal 12, @message.action_id
16
+ end
17
+
18
+ def test_invalid_action_id
19
+ @message.action_id = "foo"
20
+ assert_equal 0, @message.action_id
21
+ end
22
+
23
+
24
+ ######################################
25
+ # Encoding
26
+ ######################################
27
+
28
+ def test_encode
29
+ buffer = StringIO.new
30
+ @message.action_id = 10
31
+ @message.encode(buffer)
32
+ assert_bytes "\x93\x01\xaaget_action\xa0\x0a", buffer
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageGetActions < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::GetActions.new()
7
+ end
8
+
9
+ ######################################
10
+ # Encoding
11
+ ######################################
12
+
13
+ def test_encode
14
+ buffer = StringIO.new
15
+ @message.encode(buffer)
16
+ assert_bytes "\x93\x01\xabget_actions\xa0", buffer
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageGetProperties < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::GetProperties.new()
7
+ end
8
+
9
+ ######################################
10
+ # Encoding
11
+ ######################################
12
+
13
+ def test_encode
14
+ buffer = StringIO.new
15
+ @message.encode(buffer)
16
+ assert_bytes "\x93\x01\xaeget_properties\xa0", buffer
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageGetProperty < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::GetProperty.new()
7
+ end
8
+
9
+ ######################################
10
+ # Property ID
11
+ ######################################
12
+
13
+ def test_property_id
14
+ @message.property_id = 12
15
+ assert_equal 12, @message.property_id
16
+ end
17
+
18
+ def test_invalid_property_id
19
+ @message.property_id = "foo"
20
+ assert_equal 0, @message.property_id
21
+ end
22
+
23
+
24
+ ######################################
25
+ # Encoding
26
+ ######################################
27
+
28
+ def test_encode
29
+ buffer = StringIO.new
30
+ @message.property_id = 10
31
+ @message.encode(buffer)
32
+ assert_bytes "\x93\x01\xacget_property\xa0\x0a", buffer
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageLuaMapReduce < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::Lua::MapReduce.new()
7
+ end
8
+
9
+ ######################################
10
+ # Encoding
11
+ ######################################
12
+
13
+ def test_encode
14
+ buffer = StringIO.new
15
+ @message.source = "function map(cursor) return {} end"
16
+ @message.encode(buffer)
17
+ assert_bytes "\x93\x01\xaflua::map_reduce\xa0\x81\xa6source\xda\x00\x22" + "function map(cursor) return {} end", buffer
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageMulti < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::Multi.new()
7
+ end
8
+
9
+ ######################################
10
+ # Encoding
11
+ ######################################
12
+
13
+ def test_encode
14
+ buffer = StringIO.new
15
+ @message.messages = [
16
+ SkyDB::Message::GetProperty.new(12),
17
+ SkyDB::Message::GetAction.new(200)
18
+ ]
19
+ @message.encode(buffer)
20
+ assert_bytes "\x93\x01\xa5multi\xa0\x81\xa5count\x02" + "\x93\x01\xacget_property\xa0\x0c" + "\x93\x01\xaaget_action\xa0\xcc\xc8", buffer
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessageNextActions < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message::NextActions.new()
7
+ end
8
+
9
+ ######################################
10
+ # Object ID
11
+ ######################################
12
+
13
+ def test_prior_action_ids
14
+ @message.prior_action_ids = [1, 2, 3]
15
+ assert_equal [1, 2, 3], @message.prior_action_ids
16
+ end
17
+
18
+ def test_invalid_prior_action_ids
19
+ @message.prior_action_ids = 12
20
+ assert_equal [], @message.prior_action_ids
21
+ end
22
+
23
+
24
+ ######################################
25
+ # Encoding
26
+ ######################################
27
+
28
+ def test_encode
29
+ buffer = StringIO.new
30
+ @message.prior_action_ids = [1, 2]
31
+ @message.encode(buffer)
32
+ assert_bytes "\x93\x01\xacnext_actions\xa0\x92\x01\x02", buffer
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestMessage < MiniTest::Unit::TestCase
5
+ def setup
6
+ @message = SkyDB::Message.new('xyz')
7
+ end
8
+
9
+ def test_encode
10
+ buffer = StringIO.new
11
+ @message.table = "users"
12
+ @message.encode(buffer)
13
+ assert_bytes "\x93\x01\xa3xyz\xa5users", buffer
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: binary
2
+ require 'test_helper'
3
+
4
+ class TestEvent < MiniTest::Unit::TestCase
5
+ ######################################
6
+ # Missing method
7
+ ######################################
8
+
9
+ def test_missing_method
10
+ message = mock(message)
11
+ SkyDB::Client.any_instance.expects(:add_event).with(message)
12
+ SkyDB.add_event(message)
13
+ end
14
+
15
+ def test_invalid_missing_method
16
+ assert_raises NoMethodError do
17
+ SkyDB.no_such_msg_type
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+ require 'mocha'
3
+ require 'skydb'
4
+
5
+ class MiniTest::Unit::TestCase
6
+ def assert_bytes exp, act, msg = nil
7
+ exp = exp.to_hex
8
+ act = act.string.to_hex
9
+ assert_equal(exp, act, msg)
10
+ end
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skydb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Johnson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: msgpack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.2.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.5.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.5.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.12.5
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.12.5
78
+ description:
79
+ email:
80
+ - benbjohnson@yahoo.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - lib/ext/string.rb
86
+ - lib/skydb/action.rb
87
+ - lib/skydb/client.rb
88
+ - lib/skydb/event.rb
89
+ - lib/skydb/message/add_action.rb
90
+ - lib/skydb/message/add_event.rb
91
+ - lib/skydb/message/add_property.rb
92
+ - lib/skydb/message/get_action.rb
93
+ - lib/skydb/message/get_actions.rb
94
+ - lib/skydb/message/get_properties.rb
95
+ - lib/skydb/message/get_property.rb
96
+ - lib/skydb/message/lua/map_reduce.rb
97
+ - lib/skydb/message/multi.rb
98
+ - lib/skydb/message/next_actions.rb
99
+ - lib/skydb/message.rb
100
+ - lib/skydb/property/type.rb
101
+ - lib/skydb/property.rb
102
+ - lib/skydb/timestamp.rb
103
+ - lib/skydb/version.rb
104
+ - lib/skydb.rb
105
+ - README.md
106
+ - test/client_test.rb
107
+ - test/event_test.rb
108
+ - test/message/add_action_message_test.rb
109
+ - test/message/add_event_message_test.rb
110
+ - test/message/add_property_message_test.rb
111
+ - test/message/get_action_message_test.rb
112
+ - test/message/get_actions_message_test.rb
113
+ - test/message/get_properties_message_test.rb
114
+ - test/message/get_property_message_test.rb
115
+ - test/message/lua_map_reduce_message_test.rb
116
+ - test/message/multi_message_test.rb
117
+ - test/message/next_action_message_test.rb
118
+ - test/message_test.rb
119
+ - test/skydb_test.rb
120
+ - test/test_helper.rb
121
+ homepage: http://github.com/skydb/sky.rb
122
+ licenses: []
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
134
+ - 0
135
+ hash: 521903292973127112
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: 521903292973127112
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.24
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: A Ruby client for the Sky database
151
+ test_files:
152
+ - test/client_test.rb
153
+ - test/event_test.rb
154
+ - test/message/add_action_message_test.rb
155
+ - test/message/add_event_message_test.rb
156
+ - test/message/add_property_message_test.rb
157
+ - test/message/get_action_message_test.rb
158
+ - test/message/get_actions_message_test.rb
159
+ - test/message/get_properties_message_test.rb
160
+ - test/message/get_property_message_test.rb
161
+ - test/message/lua_map_reduce_message_test.rb
162
+ - test/message/multi_message_test.rb
163
+ - test/message/next_action_message_test.rb
164
+ - test/message_test.rb
165
+ - test/skydb_test.rb
166
+ - test/test_helper.rb