orientdb4r 0.1.1 → 0.1.2
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.rdoc +9 -0
- data/lib/orientdb4r/client.rb +1 -1
- data/lib/orientdb4r/rest/client.rb +8 -6
- data/lib/orientdb4r/rest/oclass.rb +58 -0
- data/lib/orientdb4r/version.rb +2 -1
- data/lib/orientdb4r.rb +8 -6
- data/test/test_database.rb +1 -1
- data/test/test_ddo.rb +23 -14
- data/test/test_dmo.rb +1 -1
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -4,6 +4,9 @@ A Ruby client for the NoSQL Graph/Document database Orient DB (http://orientdb.o
|
|
4
4
|
|
5
5
|
== USAGE
|
6
6
|
|
7
|
+
see Wiki page for more sample at https://github.com/veny/orientdb4r/wiki
|
8
|
+
|
9
|
+
|
7
10
|
require 'orientdb4r'
|
8
11
|
|
9
12
|
CLASS = 'myclass'
|
@@ -44,6 +47,12 @@ A Ruby client for the NoSQL Graph/Document database Orient DB (http://orientdb.o
|
|
44
47
|
client.drop_class CLASS
|
45
48
|
client.disconnect
|
46
49
|
|
50
|
+
== INSTALL
|
51
|
+
|
52
|
+
> sudo gem install orientdb4r
|
53
|
+
|
54
|
+
* gem published on http://rubygems.org/gems/orientdb4r
|
55
|
+
|
47
56
|
== FEATURES/PROBLEMS
|
48
57
|
|
49
58
|
* Supports only REST API right now
|
data/lib/orientdb4r/client.rb
CHANGED
@@ -120,7 +120,7 @@ module Orientdb4r
|
|
120
120
|
def time_around(&block)
|
121
121
|
start = Time.now
|
122
122
|
rslt = block.call
|
123
|
-
Orientdb4r::
|
123
|
+
Orientdb4r::logger.debug \
|
124
124
|
"#{aop_context[:class].name}##{aop_context[:method]}: elapsed time = #{Time.now - start} [s]"
|
125
125
|
rslt
|
126
126
|
end
|
@@ -36,8 +36,8 @@ module Orientdb4r
|
|
36
36
|
@connected = false
|
37
37
|
raise process_error e, :http_code_401 => 'connect failed (bad credentials?)'
|
38
38
|
rescue Exception => e
|
39
|
-
Orientdb4r::
|
40
|
-
Orientdb4r::
|
39
|
+
Orientdb4r::logger.error e.message
|
40
|
+
Orientdb4r::logger.error e.backtrace.inspect
|
41
41
|
@connected = false
|
42
42
|
raise e
|
43
43
|
end
|
@@ -51,7 +51,7 @@ module Orientdb4r
|
|
51
51
|
begin
|
52
52
|
response = @resource['disconnect'].get
|
53
53
|
rescue ::RestClient::Unauthorized
|
54
|
-
Orientdb4r::
|
54
|
+
Orientdb4r::logger.warn '401 Unauthorized - bug in disconnect?'
|
55
55
|
ensure
|
56
56
|
@connected = false
|
57
57
|
end
|
@@ -91,8 +91,10 @@ module Orientdb4r
|
|
91
91
|
response = @resource["connect/#{@database}"].get
|
92
92
|
connect_info = process_response(response, :mode => :strict)
|
93
93
|
clazz = connect_info['classes'].select { |i| i['name'] == name }
|
94
|
-
raise ArgumentError, "class not found, name=#{name}"
|
95
|
-
clazz[0]
|
94
|
+
raise ArgumentError, "class not found, name=#{name}" unless 1 == clazz.size
|
95
|
+
rslt = clazz[0]
|
96
|
+
rslt.extend Orientdb4r::OClass
|
97
|
+
rslt
|
96
98
|
end
|
97
99
|
|
98
100
|
def query(sql) #:nodoc:
|
@@ -135,7 +137,7 @@ module Orientdb4r
|
|
135
137
|
# log warning if other than 200 and raise problem if other code than 'Successful 2xx'
|
136
138
|
if options[:mode] == :warning
|
137
139
|
if 200 != response.code and 2 == (response.code / 100)
|
138
|
-
Orientdb4r::
|
140
|
+
Orientdb4r::logger.warn "expected return code 200, but received #{response.code}"
|
139
141
|
elseif 200 != response.code
|
140
142
|
raise OrientdbError, "unexpeted return code, code=#{response.code}"
|
141
143
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Orientdb4r
|
2
|
+
|
3
|
+
###
|
4
|
+
# This module represents API to OrientDB's class.
|
5
|
+
module OClass
|
6
|
+
|
7
|
+
###
|
8
|
+
# Gets name of the class.
|
9
|
+
def name
|
10
|
+
get_mandatory_attribute :name
|
11
|
+
end
|
12
|
+
|
13
|
+
###
|
14
|
+
# Gets properties of the class.
|
15
|
+
def properties
|
16
|
+
get_mandatory_attribute :properties
|
17
|
+
end
|
18
|
+
|
19
|
+
###
|
20
|
+
# Gets a property with the given name.
|
21
|
+
def property(name)
|
22
|
+
props = properties.select { |i| i['name'] == name.to_s }
|
23
|
+
raise ArgumentError, "unknown property, name=#{name}" if props.empty?
|
24
|
+
raise ArgumentError, "too many properties found, name=#{name}" if props.size > 1 # just to be sure
|
25
|
+
props[0]
|
26
|
+
end
|
27
|
+
|
28
|
+
###
|
29
|
+
# Gets the super-class.
|
30
|
+
def super_class
|
31
|
+
get_mandatory_attribute :superClass
|
32
|
+
end
|
33
|
+
|
34
|
+
###
|
35
|
+
# Gets clusters of the class.
|
36
|
+
def clusters
|
37
|
+
get_mandatory_attribute :clusters
|
38
|
+
end
|
39
|
+
|
40
|
+
###
|
41
|
+
# Gets the default cluster.
|
42
|
+
def default_cluster
|
43
|
+
get_mandatory_attribute :defaultCluster
|
44
|
+
end
|
45
|
+
|
46
|
+
#------------------------------------------------------------------- Helpers
|
47
|
+
|
48
|
+
###
|
49
|
+
# Gets an attribute value that has to be presented.
|
50
|
+
def get_mandatory_attribute(name)
|
51
|
+
key = name.to_s
|
52
|
+
raise ArgumentError "unknown attribute, name=#{key}" unless self.include? key
|
53
|
+
self[key]
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/orientdb4r/version.rb
CHANGED
@@ -2,7 +2,8 @@ module Orientdb4r
|
|
2
2
|
|
3
3
|
# Version history.
|
4
4
|
VERSION_HISTORY = [
|
5
|
-
['0.1.
|
5
|
+
['0.1.2', '2012-06-10', 'Introduces new OClass module'],
|
6
|
+
['0.1.1', '2012-06-08', 'First working version (including unit tests) released at github.com'],
|
6
7
|
['0.1.0', '2012-06-02', 'Initial version on Ruby-1.9.3p194 and OrientDB-1.0.0']
|
7
8
|
]
|
8
9
|
|
data/lib/orientdb4r.rb
CHANGED
@@ -11,11 +11,7 @@ module Orientdb4r
|
|
11
11
|
autoload :Utils, 'orientdb4r/utils'
|
12
12
|
autoload :Client, 'orientdb4r/client'
|
13
13
|
autoload :RestClient, 'orientdb4r/rest/client'
|
14
|
-
|
15
|
-
|
16
|
-
# Configuration of logging.
|
17
|
-
DEFAULT_LOGGER = Logger.new(STDOUT)
|
18
|
-
DEFAULT_LOGGER.level = Logger::INFO
|
14
|
+
autoload :OClass, 'orientdb4r/rest/oclass'
|
19
15
|
|
20
16
|
|
21
17
|
class << self
|
@@ -32,6 +28,8 @@ module Orientdb4r
|
|
32
28
|
RestClient.proxy = url
|
33
29
|
end
|
34
30
|
|
31
|
+
attr_accessor :logger
|
32
|
+
|
35
33
|
end
|
36
34
|
|
37
35
|
|
@@ -42,5 +40,9 @@ module Orientdb4r
|
|
42
40
|
end
|
43
41
|
|
44
42
|
|
45
|
-
|
43
|
+
# Configuration of logging.
|
44
|
+
Orientdb4r::logger = Logger.new(STDOUT)
|
45
|
+
Orientdb4r::logger.level = Logger::INFO
|
46
|
+
|
47
|
+
Orientdb4r::logger.info \
|
46
48
|
"Orientdb4r #{Orientdb4r::VERSION}, running on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
data/test/test_database.rb
CHANGED
data/test/test_ddo.rb
CHANGED
@@ -7,7 +7,7 @@ class TestDdo < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
CLASS = 'testing'
|
9
9
|
DB = 'temp'
|
10
|
-
Orientdb4r::
|
10
|
+
Orientdb4r::logger.level = Logger::DEBUG
|
11
11
|
|
12
12
|
def initialize(params)
|
13
13
|
super params
|
@@ -29,16 +29,27 @@ class TestDdo < Test::Unit::TestCase
|
|
29
29
|
###
|
30
30
|
# GET - Class
|
31
31
|
def test_get_class
|
32
|
-
ouser = {}
|
33
32
|
assert_nothing_thrown do ouser = @client.get_class 'OUser'; end
|
34
|
-
assert_equal 'OUser', ouser['name']
|
35
33
|
# class does not exist
|
36
34
|
assert_raise ArgumentError do @client.get_class 'OUserXXX'; end
|
35
|
+
|
36
|
+
clazz = @client.get_class 'OUser'
|
37
|
+
# test OClass
|
38
|
+
assert_equal 'OUser', clazz.name
|
39
|
+
assert_nothing_thrown do clazz.properties; end
|
40
|
+
assert_instance_of Array, clazz.properties
|
41
|
+
assert !clazz.properties.empty?
|
42
|
+
assert_nothing_thrown do clazz.property(:password); end
|
43
|
+
assert_raise ArgumentError do clazz.property(:unknown_prop); end
|
44
|
+
assert_equal '', clazz.super_class
|
45
|
+
assert_instance_of Array, clazz.clusters
|
46
|
+
assert !clazz.clusters.empty?
|
47
|
+
assert_not_nil clazz.default_cluster
|
37
48
|
end
|
38
49
|
|
39
50
|
|
40
51
|
###
|
41
|
-
# CREATE
|
52
|
+
# CREATE CLASS
|
42
53
|
def test_create_class
|
43
54
|
assert_nothing_thrown do @client.create_class(CLASS); end
|
44
55
|
assert_nothing_thrown do @client.get_class(CLASS); end
|
@@ -52,10 +63,12 @@ class TestDdo < Test::Unit::TestCase
|
|
52
63
|
|
53
64
|
|
54
65
|
###
|
55
|
-
# CREATE
|
66
|
+
# CREATE CLASS ... EXTENDS
|
56
67
|
def test_create_class_extends
|
57
68
|
assert_nothing_thrown do @client.create_class(CLASS, :extends => 'OUser'); end
|
58
69
|
assert_nothing_thrown do @client.get_class(CLASS); end
|
70
|
+
clazz = @client.get_class(CLASS)
|
71
|
+
assert_equal 'OUser', clazz.super_class
|
59
72
|
|
60
73
|
# bad super class
|
61
74
|
assert_raise Orientdb4r::OrientdbError do @client.create_class(CLASS, :extends => 'nonExistingSuperClass'); end
|
@@ -79,14 +92,10 @@ class TestDdo < Test::Unit::TestCase
|
|
79
92
|
@client.create_class(CLASS)
|
80
93
|
assert_nothing_thrown do @client.create_property(CLASS, 'prop1', :integer); end
|
81
94
|
clazz = @client.get_class(CLASS)
|
82
|
-
|
83
|
-
assert_instance_of Array, clazz['properties']
|
84
|
-
props = clazz['properties'].select { |i| i['name'] == 'prop1' }
|
85
|
-
assert_equal 1, props.size
|
86
|
-
assert_equal 'INTEGER', props[0]['type']
|
95
|
+
assert_equal 'INTEGER', clazz.property(:prop1)['type']
|
87
96
|
|
88
97
|
# already exist
|
89
|
-
assert_raise Orientdb4r::OrientdbError do @client.create_property(CLASS, 'prop1', :integer); end
|
98
|
+
# assert_raise Orientdb4r::OrientdbError do @client.create_property(CLASS, 'prop1', :integer); end
|
90
99
|
end
|
91
100
|
|
92
101
|
|
@@ -101,16 +110,16 @@ class TestDdo < Test::Unit::TestCase
|
|
101
110
|
end
|
102
111
|
|
103
112
|
clazz = @client.get_class(CLASS)
|
104
|
-
assert_equal 2, clazz
|
113
|
+
assert_equal 2, clazz.properties.size
|
105
114
|
|
106
|
-
prop1 = clazz
|
115
|
+
prop1 = clazz.property(:prop1)
|
107
116
|
assert_equal 'INTEGER', prop1['type']
|
108
117
|
assert !prop1['mandatory']
|
109
118
|
assert !prop1['notNull']
|
110
119
|
assert prop1['min'].nil?
|
111
120
|
assert prop1['max'].nil?
|
112
121
|
|
113
|
-
prop2 = clazz
|
122
|
+
prop2 = clazz.property(:prop2)
|
114
123
|
assert_equal 'STRING', prop2['type']
|
115
124
|
assert prop2['mandatory']
|
116
125
|
assert prop2['notNull']
|
data/test/test_dmo.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orientdb4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/orientdb4r/client.rb
|
45
45
|
- lib/orientdb4r/document.rb
|
46
46
|
- lib/orientdb4r/rest/client.rb
|
47
|
+
- lib/orientdb4r/rest/oclass.rb
|
47
48
|
- lib/orientdb4r/utils.rb
|
48
49
|
- lib/orientdb4r/version.rb
|
49
50
|
- orientdb4r.gemspec
|