skydb 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -0
- data/lib/ext/string.rb +11 -0
- data/lib/skydb.rb +88 -0
- data/lib/skydb/action.rb +57 -0
- data/lib/skydb/client.rb +216 -0
- data/lib/skydb/event.rb +114 -0
- data/lib/skydb/message.rb +134 -0
- data/lib/skydb/message/add_action.rb +53 -0
- data/lib/skydb/message/add_event.rb +72 -0
- data/lib/skydb/message/add_property.rb +55 -0
- data/lib/skydb/message/get_action.rb +55 -0
- data/lib/skydb/message/get_actions.rb +34 -0
- data/lib/skydb/message/get_properties.rb +34 -0
- data/lib/skydb/message/get_property.rb +55 -0
- data/lib/skydb/message/lua/map_reduce.rb +59 -0
- data/lib/skydb/message/multi.rb +57 -0
- data/lib/skydb/message/next_actions.rb +55 -0
- data/lib/skydb/property.rb +93 -0
- data/lib/skydb/property/type.rb +40 -0
- data/lib/skydb/timestamp.rb +22 -0
- data/lib/skydb/version.rb +3 -0
- data/test/client_test.rb +71 -0
- data/test/event_test.rb +37 -0
- data/test/message/add_action_message_test.rb +34 -0
- data/test/message/add_event_message_test.rb +35 -0
- data/test/message/add_property_message_test.rb +41 -0
- data/test/message/get_action_message_test.rb +34 -0
- data/test/message/get_actions_message_test.rb +18 -0
- data/test/message/get_properties_message_test.rb +18 -0
- data/test/message/get_property_message_test.rb +34 -0
- data/test/message/lua_map_reduce_message_test.rb +19 -0
- data/test/message/multi_message_test.rb +22 -0
- data/test/message/next_action_message_test.rb +34 -0
- data/test/message_test.rb +15 -0
- data/test/skydb_test.rb +20 -0
- data/test/test_helper.rb +12 -0
- metadata +166 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
##########################################################################
|
4
|
+
#
|
5
|
+
# Constants
|
6
|
+
#
|
7
|
+
##########################################################################
|
8
|
+
|
9
|
+
# The version of the message. This must be compatible with the server's
|
10
|
+
# version for the client to work.
|
11
|
+
VERSION = 1
|
12
|
+
|
13
|
+
|
14
|
+
##########################################################################
|
15
|
+
#
|
16
|
+
# Constructor
|
17
|
+
#
|
18
|
+
##########################################################################
|
19
|
+
|
20
|
+
# Initializes the message.
|
21
|
+
def initialize(name)
|
22
|
+
@name = name
|
23
|
+
@table = ""
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
##########################################################################
|
28
|
+
#
|
29
|
+
# Attributes
|
30
|
+
#
|
31
|
+
##########################################################################
|
32
|
+
|
33
|
+
####################################
|
34
|
+
# Name
|
35
|
+
####################################
|
36
|
+
|
37
|
+
# The name of message being sent. This is defined by the subclass.
|
38
|
+
attr_reader :name
|
39
|
+
|
40
|
+
|
41
|
+
####################################
|
42
|
+
# Table
|
43
|
+
####################################
|
44
|
+
|
45
|
+
# The name of the table the message is being sent to/from.
|
46
|
+
attr_accessor :table
|
47
|
+
|
48
|
+
def table=(value)
|
49
|
+
@table = value.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
##########################################################################
|
54
|
+
#
|
55
|
+
# Methods
|
56
|
+
#
|
57
|
+
##########################################################################
|
58
|
+
|
59
|
+
####################################
|
60
|
+
# Validation
|
61
|
+
####################################
|
62
|
+
|
63
|
+
# Validates that the message is ready to be sent. If any validation issues
|
64
|
+
# are found then an error is raised.
|
65
|
+
def validate!
|
66
|
+
if table.nil? || table.empty?
|
67
|
+
raise SkyDB::TableRequiredError.new('Table required')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
####################################
|
73
|
+
# Encoding
|
74
|
+
####################################
|
75
|
+
|
76
|
+
# Encodes the message contents to a buffer.
|
77
|
+
#
|
78
|
+
# @param [IO] buffer the buffer to write to.
|
79
|
+
def encode(buffer)
|
80
|
+
buffer.set_encoding(Encoding::BINARY, Encoding::BINARY)
|
81
|
+
|
82
|
+
# Encode the header and body.
|
83
|
+
encode_header(buffer)
|
84
|
+
encode_body(buffer)
|
85
|
+
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
|
89
|
+
# Encodes the message header.
|
90
|
+
#
|
91
|
+
# @param [IO] buffer the buffer to write the header to.
|
92
|
+
def encode_header(buffer)
|
93
|
+
buffer << [
|
94
|
+
SkyDB::Message::VERSION,
|
95
|
+
name,
|
96
|
+
table
|
97
|
+
].to_msgpack
|
98
|
+
end
|
99
|
+
|
100
|
+
# Encodes the message body.
|
101
|
+
#
|
102
|
+
# @param [IO] buffer the buffer to write the header to.
|
103
|
+
def encode_body(buffer)
|
104
|
+
# To be implemented by the subclass.
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
####################################
|
109
|
+
# Response processing
|
110
|
+
####################################
|
111
|
+
|
112
|
+
# Performs any necessary post-processing on the response.
|
113
|
+
#
|
114
|
+
# @param [Object] response
|
115
|
+
def process_response(response)
|
116
|
+
return response
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
require 'skydb/message/add_action'
|
122
|
+
require 'skydb/message/get_action'
|
123
|
+
require 'skydb/message/get_actions'
|
124
|
+
|
125
|
+
require 'skydb/message/add_property'
|
126
|
+
require 'skydb/message/get_property'
|
127
|
+
require 'skydb/message/get_properties'
|
128
|
+
|
129
|
+
require 'skydb/message/add_event'
|
130
|
+
require 'skydb/message/next_actions'
|
131
|
+
|
132
|
+
require 'skydb/message/lua/map_reduce'
|
133
|
+
|
134
|
+
require 'skydb/message/multi'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
class AddAction < SkyDB::Message
|
4
|
+
########################################################################
|
5
|
+
#
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
# Initializes the 'action add' message.
|
11
|
+
def initialize(action=nil, options={})
|
12
|
+
super('add_action')
|
13
|
+
self.action = action
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
##########################################################################
|
18
|
+
#
|
19
|
+
# Attributes
|
20
|
+
#
|
21
|
+
##########################################################################
|
22
|
+
|
23
|
+
##################################
|
24
|
+
# Action
|
25
|
+
##################################
|
26
|
+
|
27
|
+
# The action to add.
|
28
|
+
attr_reader :action
|
29
|
+
|
30
|
+
def action=(value)
|
31
|
+
@action = value if value.is_a?(Action)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
##########################################################################
|
36
|
+
#
|
37
|
+
# Methods
|
38
|
+
#
|
39
|
+
##########################################################################
|
40
|
+
|
41
|
+
####################################
|
42
|
+
# Encoding
|
43
|
+
####################################
|
44
|
+
|
45
|
+
# Encodes the message body.
|
46
|
+
#
|
47
|
+
# @param [IO] buffer the buffer to write the header to.
|
48
|
+
def encode_body(buffer)
|
49
|
+
buffer << action.to_msgpack
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
class AddEvent < SkyDB::Message
|
4
|
+
########################################################################
|
5
|
+
#
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
# Initializes the 'event add' message.
|
11
|
+
#
|
12
|
+
# @param [Event] event the event to add.
|
13
|
+
def initialize(event=nil, options={})
|
14
|
+
super('add_event')
|
15
|
+
self.event = event
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
##########################################################################
|
20
|
+
#
|
21
|
+
# Attributes
|
22
|
+
#
|
23
|
+
##########################################################################
|
24
|
+
|
25
|
+
##################################
|
26
|
+
# Event
|
27
|
+
##################################
|
28
|
+
|
29
|
+
# The event to add.
|
30
|
+
attr_reader :event
|
31
|
+
|
32
|
+
def event=(value)
|
33
|
+
@event = value if value.is_a?(Event)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
##########################################################################
|
38
|
+
#
|
39
|
+
# Methods
|
40
|
+
#
|
41
|
+
##########################################################################
|
42
|
+
|
43
|
+
####################################
|
44
|
+
# Validation
|
45
|
+
####################################
|
46
|
+
|
47
|
+
def validate!
|
48
|
+
super
|
49
|
+
|
50
|
+
if !(event.object_id > 0)
|
51
|
+
raise SkyDB::ObjectIdRequiredError.new('Object ID required')
|
52
|
+
end
|
53
|
+
|
54
|
+
if event.timestamp.nil?
|
55
|
+
raise SkyDB::TimestampRequiredError.new('Timestamp required')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
####################################
|
61
|
+
# Encoding
|
62
|
+
####################################
|
63
|
+
|
64
|
+
# Encodes the message body.
|
65
|
+
#
|
66
|
+
# @param [IO] buffer the buffer to write the header to.
|
67
|
+
def encode_body(buffer)
|
68
|
+
buffer << event.to_msgpack
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
class AddProperty < SkyDB::Message
|
4
|
+
########################################################################
|
5
|
+
#
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
# Initializes the 'property add' message.
|
11
|
+
#
|
12
|
+
# @param [Property] property the property to add.
|
13
|
+
def initialize(property=nil, options={})
|
14
|
+
super('add_property')
|
15
|
+
self.property = property
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
##########################################################################
|
20
|
+
#
|
21
|
+
# Attributes
|
22
|
+
#
|
23
|
+
##########################################################################
|
24
|
+
|
25
|
+
##################################
|
26
|
+
# Property
|
27
|
+
##################################
|
28
|
+
|
29
|
+
# The property to add.
|
30
|
+
attr_reader :property
|
31
|
+
|
32
|
+
def property=(value)
|
33
|
+
@property = value if value.is_a?(Property)
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
##########################################################################
|
38
|
+
#
|
39
|
+
# Methods
|
40
|
+
#
|
41
|
+
##########################################################################
|
42
|
+
|
43
|
+
####################################
|
44
|
+
# Encoding
|
45
|
+
####################################
|
46
|
+
|
47
|
+
# Encodes the message body.
|
48
|
+
#
|
49
|
+
# @param [IO] buffer the buffer to write the header to.
|
50
|
+
def encode_body(buffer)
|
51
|
+
buffer << property.to_msgpack
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
class GetAction < SkyDB::Message
|
4
|
+
########################################################################
|
5
|
+
#
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
# Initializes the 'action get' message.
|
11
|
+
#
|
12
|
+
# @param [Fixnum] action_id the identifier of the action to retrieve.
|
13
|
+
def initialize(action_id=nil, options={})
|
14
|
+
super('get_action')
|
15
|
+
self.action_id = action_id
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
##########################################################################
|
20
|
+
#
|
21
|
+
# Attributes
|
22
|
+
#
|
23
|
+
##########################################################################
|
24
|
+
|
25
|
+
##################################
|
26
|
+
# Action ID
|
27
|
+
##################################
|
28
|
+
|
29
|
+
# The action identifier to retrieve.
|
30
|
+
attr_reader :action_id
|
31
|
+
|
32
|
+
def action_id=(value)
|
33
|
+
@action_id = value.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
##########################################################################
|
38
|
+
#
|
39
|
+
# Methods
|
40
|
+
#
|
41
|
+
##########################################################################
|
42
|
+
|
43
|
+
####################################
|
44
|
+
# Encoding
|
45
|
+
####################################
|
46
|
+
|
47
|
+
# Encodes the message body.
|
48
|
+
#
|
49
|
+
# @param [IO] buffer the buffer to write the header to.
|
50
|
+
def encode_body(buffer)
|
51
|
+
buffer << action_id.to_msgpack
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
class GetActions < SkyDB::Message
|
4
|
+
########################################################################
|
5
|
+
#
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
# Initializes the 'action all' message.
|
11
|
+
def initialize(options={})
|
12
|
+
super('get_actions')
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
##########################################################################
|
17
|
+
#
|
18
|
+
# Methods
|
19
|
+
#
|
20
|
+
##########################################################################
|
21
|
+
|
22
|
+
####################################
|
23
|
+
# Encoding
|
24
|
+
####################################
|
25
|
+
|
26
|
+
# Encodes the message body.
|
27
|
+
#
|
28
|
+
# @param [IO] buffer the buffer to write the header to.
|
29
|
+
def encode_body(buffer)
|
30
|
+
# Do nothing.
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
class GetProperties < SkyDB::Message
|
4
|
+
########################################################################
|
5
|
+
#
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
# Initializes the 'property all' message.
|
11
|
+
def initialize(options={})
|
12
|
+
super('get_properties')
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
##########################################################################
|
17
|
+
#
|
18
|
+
# Methods
|
19
|
+
#
|
20
|
+
##########################################################################
|
21
|
+
|
22
|
+
####################################
|
23
|
+
# Encoding
|
24
|
+
####################################
|
25
|
+
|
26
|
+
# Encodes the message body.
|
27
|
+
#
|
28
|
+
# @param [IO] buffer the buffer to write the header to.
|
29
|
+
def encode_body(buffer)
|
30
|
+
# Do nothing.
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class SkyDB
|
2
|
+
class Message
|
3
|
+
class GetProperty < SkyDB::Message
|
4
|
+
########################################################################
|
5
|
+
#
|
6
|
+
# Constructor
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
|
10
|
+
# Initializes the 'property get' message.
|
11
|
+
#
|
12
|
+
# @param [Fixnum] property_id The identifier for the property to retrieve.
|
13
|
+
def initialize(property_id=nil, options={})
|
14
|
+
super('get_property')
|
15
|
+
self.property_id = property_id
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
##########################################################################
|
20
|
+
#
|
21
|
+
# Attributes
|
22
|
+
#
|
23
|
+
##########################################################################
|
24
|
+
|
25
|
+
##################################
|
26
|
+
# Property ID
|
27
|
+
##################################
|
28
|
+
|
29
|
+
# The property identifier to retrieve.
|
30
|
+
attr_reader :property_id
|
31
|
+
|
32
|
+
def property_id=(value)
|
33
|
+
@property_id = value.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
##########################################################################
|
38
|
+
#
|
39
|
+
# Methods
|
40
|
+
#
|
41
|
+
##########################################################################
|
42
|
+
|
43
|
+
####################################
|
44
|
+
# Encoding
|
45
|
+
####################################
|
46
|
+
|
47
|
+
# Encodes the message body.
|
48
|
+
#
|
49
|
+
# @param [IO] buffer the buffer to write the header to.
|
50
|
+
def encode_body(buffer)
|
51
|
+
buffer << property_id.to_msgpack
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|