orientdb 0.0.15-jruby → 0.0.16-jruby
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/VERSION +1 -1
- data/lib/orientdb.rb +1 -0
- data/lib/orientdb/oclass.rb +21 -13
- data/lib/orientdb/rid.rb +46 -0
- data/orientdb.gemspec +3 -2
- data/spec/document_spec.rb +28 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.16
|
data/lib/orientdb.rb
CHANGED
data/lib/orientdb/oclass.rb
CHANGED
@@ -3,25 +3,33 @@ module OrientDB
|
|
3
3
|
class OClass
|
4
4
|
|
5
5
|
def type_for(value)
|
6
|
+
value = value.oclass if value.respond_to?(:oclass)
|
6
7
|
type = case value
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
when OrientDB::SchemaType, OrientDB::OClass
|
9
|
+
value
|
10
|
+
when String
|
11
|
+
if schema.exists_class?(value)
|
12
|
+
schema.get_class(value)
|
13
|
+
else
|
14
|
+
FIELD_TYPES[value.to_sym]
|
15
|
+
end
|
16
|
+
when Symbol
|
17
|
+
FIELD_TYPES[value]
|
18
|
+
else
|
19
|
+
FIELD_TYPES[value.to_s.to_sym]
|
20
|
+
end
|
21
|
+
raise "Uknown schema type for [#{value}] (#{value.class.name})" unless type
|
15
22
|
type
|
16
23
|
end
|
17
24
|
|
18
|
-
def add(property_name, type, options = {})
|
25
|
+
def add(property_name, type, options = { })
|
19
26
|
property_name = property_name.to_s
|
20
27
|
if exists_property(property_name)
|
21
28
|
puts "We already have that property name [#{property_name}]"
|
22
29
|
return false
|
23
30
|
end
|
24
31
|
|
32
|
+
type = type.oclass if type.respond_to?(:oclass)
|
25
33
|
case type
|
26
34
|
when SchemaType
|
27
35
|
prop = create_property property_name, type
|
@@ -73,7 +81,7 @@ module OrientDB
|
|
73
81
|
|
74
82
|
class << self
|
75
83
|
|
76
|
-
def create(db, name, fields = {})
|
84
|
+
def create(db, name, fields = { })
|
77
85
|
name = name.to_s
|
78
86
|
add_cluster = fields.delete :add_cluster
|
79
87
|
add_cluster = true if add_cluster.nil?
|
@@ -83,12 +91,12 @@ module OrientDB
|
|
83
91
|
klass = db.get_class name
|
84
92
|
else
|
85
93
|
if use_cluster
|
86
|
-
klass
|
94
|
+
klass = db.schema.create_class name, use_cluster
|
87
95
|
elsif add_cluster && !db.storage.cluster_names.include?(name.downcase)
|
88
96
|
cluster = db.storage.add_cluster name.downcase, STORAGE_TYPES[:physical]
|
89
97
|
klass = db.schema.create_class name, cluster
|
90
98
|
else
|
91
|
-
klass
|
99
|
+
klass = db.schema.create_class name
|
92
100
|
end
|
93
101
|
end
|
94
102
|
|
@@ -104,7 +112,7 @@ module OrientDB
|
|
104
112
|
klass.add property_name, type
|
105
113
|
when Hash
|
106
114
|
options = type.dup
|
107
|
-
type
|
115
|
+
type = options.delete :type
|
108
116
|
klass.add property_name, type, options
|
109
117
|
else
|
110
118
|
raise "Unknown field options [#{type.inspect}]"
|
data/lib/orientdb/rid.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
class OrientDB::RID
|
2
|
+
|
3
|
+
attr_reader :cluster_id, :document_id
|
4
|
+
|
5
|
+
def initialize(rid_str = '-1:-1')
|
6
|
+
idx = rid_str.index(':')
|
7
|
+
if idx
|
8
|
+
self.cluster_id = rid_str[0, idx]
|
9
|
+
self.document_id = rid_str[idx+1..-1]
|
10
|
+
else
|
11
|
+
raise "Unknown parameters #{args.inspect}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def cluster_id=(value)
|
16
|
+
@cluster_id = value.to_s.strip.to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def document_id=(value)
|
20
|
+
@document_id = value.to_s.strip.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
"#{cluster_id}:#{@document_id}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def unsaved?
|
28
|
+
to_s == '-1:-1'
|
29
|
+
end
|
30
|
+
|
31
|
+
def saved?
|
32
|
+
cluster_id > 0 && document_id >= 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid?
|
36
|
+
saved? || unsaved?
|
37
|
+
end
|
38
|
+
|
39
|
+
alias :to_s :inspect
|
40
|
+
end
|
41
|
+
|
42
|
+
class String
|
43
|
+
def valid_orientdb_rid?
|
44
|
+
OrientDB::RID.new(self).valid?
|
45
|
+
end
|
46
|
+
end
|
data/orientdb.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{orientdb}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.16"
|
9
9
|
s.platform = %q{jruby}
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Adrian Madrid"]
|
13
|
-
s.date = %q{2011-01
|
13
|
+
s.date = %q{2011-02-01}
|
14
14
|
s.default_executable = %q{orientdb_console}
|
15
15
|
s.description = %q{Simple JRuby wrapper for the OrientDB.}
|
16
16
|
s.email = ["aemadrid@gmail.com"]
|
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
"lib/orientdb/oclass.rb",
|
44
44
|
"lib/orientdb/property.rb",
|
45
45
|
"lib/orientdb/record.rb",
|
46
|
+
"lib/orientdb/rid.rb",
|
46
47
|
"lib/orientdb/schema.rb",
|
47
48
|
"lib/orientdb/sql.rb",
|
48
49
|
"lib/orientdb/sql/common.rb",
|
data/spec/document_spec.rb
CHANGED
@@ -2,6 +2,34 @@ require File.expand_path("../spec_helper", __FILE__)
|
|
2
2
|
|
3
3
|
describe "OrientDB" do
|
4
4
|
|
5
|
+
describe "RID" do
|
6
|
+
it "should create valid empty" do
|
7
|
+
rid = OrientDB::RID.new
|
8
|
+
rid.to_s == '-1:-1'
|
9
|
+
rid.valid?.should == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create valid saved" do
|
13
|
+
rid = OrientDB::RID.new '5:40'
|
14
|
+
rid.to_s == '5:40'
|
15
|
+
rid.valid?.should == true
|
16
|
+
rid.saved?.should == true
|
17
|
+
rid.unsaved?.should == false
|
18
|
+
rid.cluster_id.should == 5
|
19
|
+
rid.document_id.should == 40
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should create valid unsaved" do
|
23
|
+
rid = OrientDB::RID.new '-1:-1'
|
24
|
+
rid.to_s == '5:40'
|
25
|
+
rid.valid?.should == true
|
26
|
+
rid.saved?.should == false
|
27
|
+
rid.unsaved?.should == true
|
28
|
+
rid.cluster_id.should == -1
|
29
|
+
rid.document_id.should == -1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
5
33
|
describe "Document" do
|
6
34
|
|
7
35
|
before :all do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: orientdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.16
|
6
6
|
platform: jruby
|
7
7
|
authors:
|
8
8
|
- Adrian Madrid
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-01
|
13
|
+
date: 2011-02-01 00:00:00 -07:00
|
14
14
|
default_executable: orientdb_console
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/orientdb/oclass.rb
|
70
70
|
- lib/orientdb/property.rb
|
71
71
|
- lib/orientdb/record.rb
|
72
|
+
- lib/orientdb/rid.rb
|
72
73
|
- lib/orientdb/schema.rb
|
73
74
|
- lib/orientdb/sql.rb
|
74
75
|
- lib/orientdb/sql/common.rb
|