orientdb 0.0.2-jruby → 0.0.4-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/Gemfile.lock CHANGED
@@ -1,14 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orientdb (0.0.1-java)
4
+ orientdb (0.0.2-java)
5
5
  hashie
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  awesome_print (0.2.1)
11
+ diff-lcs (1.1.2)
11
12
  hashie (0.4.0)
13
+ rspec (2.1.0)
14
+ rspec-core (~> 2.1.0)
15
+ rspec-expectations (~> 2.1.0)
16
+ rspec-mocks (~> 2.1.0)
17
+ rspec-core (2.1.0)
18
+ rspec-expectations (2.1.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.1.0)
12
21
 
13
22
  PLATFORMS
14
23
  java
@@ -18,3 +27,4 @@ DEPENDENCIES
18
27
  bundler (>= 1.0.0)
19
28
  hashie
20
29
  orientdb!
30
+ rspec (>= 2.1)
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'spec/rake/spectask'
5
+
6
+ Spec::Rake::SpecTask.new(:spec) do |t|
7
+ t.spec_files = Dir.glob('spec/**/*_spec.rb')
8
+ t.spec_opts << '--format specdoc'
9
+ # t.rcov = true
10
+ end
data/bin/orientdb_console CHANGED
@@ -1,6 +1,22 @@
1
1
  #!/usr/bin/env jruby
2
2
  require File.expand_path(File.dirname(__FILE__) + "/../lib/orientdb")
3
3
 
4
+ if ARGV.include?('test:db')
5
+ GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
6
+ TEMP_DIR = Dir.pwd + '/tmp'
7
+
8
+ TEST_DB_PATH = "#{TEMP_DIR}/databases/db_#{rand(999) + 1}"
9
+
10
+ puts ">> GEM_ROOT : #{GEM_ROOT}"
11
+ puts ">> TEST_DB PATH : #{TEST_DB_PATH}"
12
+
13
+ require 'fileutils'
14
+ FileUtils.mkdir_p TEST_DB_PATH
15
+ @db = OrientDB::Database.new("local:#{TEST_DB_PATH}/test").create
16
+ end
17
+
18
+ include OrientDB
19
+
4
20
  require 'irb'
5
21
  ARGV.clear
6
22
  IRB.start(__FILE__)
data/lib/orientdb.rb CHANGED
@@ -6,7 +6,7 @@ $: << File.expand_path('../../jars/', __FILE__)
6
6
  require 'java'
7
7
  require 'orientdb-client-0.9.23'
8
8
 
9
- class OrientDB
9
+ module OrientDB
10
10
 
11
11
  def self.const_missing(missing)
12
12
  puts "[#{name}:const_missing] #{missing}"
@@ -17,8 +17,8 @@ end
17
17
 
18
18
  require 'orientdb/ext'
19
19
  require 'orientdb/version'
20
- require 'orientdb/proxy_mixin'
21
20
  require 'orientdb/user'
21
+ require 'orientdb/schema'
22
22
  require 'orientdb/database'
23
23
  require 'orientdb/document'
24
24
  require 'orientdb/oclass'
@@ -1,123 +1,104 @@
1
- class OrientDB::Database
1
+ module OrientDB
2
2
 
3
- include OrientDB::ProxyMixin
3
+ Database = com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx
4
4
 
5
- KLASS = com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx
6
-
7
- Record = com.orientechnologies.orient.core.record.ORecord
8
- Schema = com.orientechnologies.orient.core.metadata.schema.OSchema
9
5
  SQLQuery = com.orientechnologies.orient.core.sql.query.OSQLSynchQuery
10
6
 
11
- def initialize(database_url)
12
- @proxy_object = KLASS.new database_url
13
- end
7
+ class Database
14
8
 
15
- def auth(username, password)
16
- proxy_object.open username, password
17
- end
9
+ def auth(username, password)
10
+ open username, password
11
+ end
18
12
 
19
- def user
20
- User.from_ouser proxy_object.getUser
21
- end
13
+ alias_method :native_query, :query
22
14
 
23
- def query(sql_query = nil)
24
- sql_query = prepare_sql_query sql_query
25
- proxy_object.query(sql_query).map { |x| OrientDB::Document.new x }
26
- end
15
+ def query(sql_query = nil)
16
+ sql_query = prepare_sql_query sql_query
17
+ native_query sql_query
18
+ end
27
19
 
28
- alias :find :query
20
+ alias :find :query
29
21
 
30
- def first(sql_query = nil)
31
- sql_query = prepare_sql_query sql_query
32
- proxy_object.query(sql_query).setLimit(1).map { |x| Document.new x }.first
33
- end
22
+ def first(sql_query = nil)
23
+ sql_query = prepare_sql_query sql_query
24
+ query(sql_query).setLimit(1).map { |x| x }.first
25
+ end
34
26
 
35
- def prepare_sql_query(sql_query)
36
- return if sql_query.nil?
37
- case sql_query
38
- when SQLQuery
39
- sql_query
40
- when String
41
- SQLQuery.new sql_query
42
- when Hash
43
- SQLQuery.new sql_query_from_hash(sql_query)
44
- else
45
- raise "Unknown query type"
27
+ def prepare_sql_query(sql_query)
28
+ return if sql_query.nil?
29
+ case sql_query
30
+ when SQLQuery
31
+ sql_query
32
+ when String
33
+ SQLQuery.new sql_query
34
+ when Hash
35
+ SQLQuery.new sql_query_from_hash(sql_query)
36
+ else
37
+ raise "Unknown query type"
38
+ end
46
39
  end
47
- end
48
40
 
49
- def sql_query_from_hash(options = {})
50
- klass_name = options.delete :class
51
- raise "Missing class name" unless klass_name
52
- columns = options.delete(:columns) || '*'
53
- order = options.delete :order
54
- order_sql = order ? " ORDER BY #{order}" : ''
55
- fields = options.map do |field, value|
56
- cmp = '='
57
- if value.is_a?(String)
58
- value = "'" + value + "'"
59
- cmp = 'LIKE' if value.index('%')
41
+ def sql_query_from_hash(options = {})
42
+ klass_name = options.delete :class
43
+ raise "Missing class name" unless klass_name
44
+ columns = options.delete(:columns) || '*'
45
+ order = options.delete :order
46
+ order_sql = order ? " ORDER BY #{order}" : ''
47
+ fields = options.map do |field, value|
48
+ cmp = '='
49
+ if value.is_a?(String)
50
+ value = "'" + value + "'"
51
+ cmp = 'LIKE' if value.index('%')
52
+ end
53
+ "#{field} #{cmp} #{value}"
60
54
  end
61
- "#{field} #{cmp} #{value}"
55
+ "SELECT #{columns} FROM #{klass_name} WHERE #{fields.join(' AND ')}#{order_sql}"
62
56
  end
63
- "SELECT #{columns} FROM #{klass_name} WHERE #{fields.join(' AND ')}#{order_sql}"
64
- end
65
57
 
66
- def schema
67
- proxy_object.getMetadata.getSchema
68
- end
58
+ def schema
59
+ metadata.schema
60
+ end
69
61
 
70
- def storage
71
- proxy_object.storage
72
- end
62
+ def get_class(klass_name)
63
+ schema.get_class klass_name.to_s
64
+ end
73
65
 
74
- def create_class(name, fields = {})
75
- OrientDB::OClass.create self, name, fields
76
- end
66
+ def create_class(klass_name, fields = {})
67
+ OrientDB::OClass.create self, klass_name.to_s, fields
68
+ end
77
69
 
78
- def each_in_class(klass_name)
79
- proxy_object.browseClass(klass_name.to_s).each do |record|
80
- yield OrientDB::Document.new(record)
70
+ def get_or_create_class(klass_name)
71
+ get_class(klass_name) || create_class(klass_name)
81
72
  end
82
- end
83
73
 
84
- def all_in_class(klass_name)
85
- proxy_object.browseClass(klass_name.to_s).map { |x| OrientDB::Document.new x }
86
- end
74
+ alias :each_in_class :browseClass
87
75
 
88
- def each_in_custer(cluster_name)
89
- proxy_object.browseCluster(cluster_name.to_s).each do |record|
90
- yield OrientDB::Document.new(record)
76
+ def all_in_class(klass_name)
77
+ browse_class(klass_name.to_s).map
91
78
  end
92
- end
93
79
 
94
- def all_in_custer(cluster_name)
95
- proxy_object.browseCluster(cluster_name.to_s).map { |x| OrientDB::Document.new x }
96
- end
80
+ alias :each_in_cluster :browseCluster
97
81
 
98
- def get_class(klass_name)
99
- klass = schema.get_class klass_name
100
- klass && OrientDB::OClass.new(klass)
101
- end
82
+ def all_in_cluster(cluster_name)
83
+ browse_cluster(cluster_name.to_s).map
84
+ end
102
85
 
103
- def get_or_create_class(klass_name)
104
- get_class(klass_name) || OrientDB::OClass.create(klass_name)
105
- end
86
+ class << self
106
87
 
107
- class << self
88
+ def create(database_url)
89
+ obj = new(database_url)
90
+ obj.create
91
+ obj
92
+ end
108
93
 
109
- def create(database_url)
110
- obj = new(database_url)
111
- obj.create
112
- obj
113
- end
94
+ def connect(database_url, username, password)
95
+ obj = new(database_url)
96
+ obj.auth(username, password)
97
+ obj
98
+ end
114
99
 
115
- def connect(database_url, username, password)
116
- obj = new(database_url)
117
- obj.auth(username, password)
118
- obj
119
100
  end
120
-
121
101
  end
122
102
 
103
+
123
104
  end
@@ -1,18 +1,11 @@
1
- class OrientDB::DatabasePool
1
+ module OrientDB
2
2
 
3
- include OrientDB::ProxyMixin
3
+ DatabasePool = com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool
4
4
 
5
- KLASS = com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool
5
+ class DatabasePool
6
6
 
7
- def initialize(database_url, username, password)
8
- @proxy_object = KLASS.global.acquire database_url, username, password
9
- end
10
-
11
- class << self
12
-
13
- def connect(database_url, username, password)
14
- obj = new database_url, username, password
15
- obj
7
+ def initialize(database_url, username, password)
8
+ self.class.global.acquire database_url, username, password
16
9
  end
17
10
 
18
11
  end
@@ -1,76 +1,61 @@
1
- class OrientDB::Document
1
+ module OrientDB
2
2
 
3
- include OrientDB::ProxyMixin
3
+ Document = com.orientechnologies.orient.core.record.impl.ODocument
4
4
 
5
- KLASS = com.orientechnologies.orient.core.record.impl.ODocument
5
+ class Document
6
6
 
7
- def initialize(*args)
8
- if args.first.is_a?(KLASS)
9
- @proxy_object = args.first
10
- else
11
- db, klass_name = args[0], args[1]
12
- fields = args[2] || {}
13
- if db && klass_name
14
- @proxy_object = KLASS.new db.proxy_object, klass_name
15
- fields.each do |name, value|
16
- self[name] = value
17
- end
18
- else
19
- @proxy_object = KLASS.new
20
- end
7
+ def values
8
+ field_names.map { |field_name| [field_name, self[field_name]] }
21
9
  end
22
- end
23
10
 
24
- def values
25
- proxy_object.fieldNames.map{|field_name| [field_name, self[field_name]] }
26
- end
11
+ alias :db :database
27
12
 
28
- def db
29
- proxy_object.getDatabase
30
- end
31
-
32
- # def save
33
- # db.save proxy_object
34
- # end
13
+ def [](field_name)
14
+ field field_name.to_s
15
+ end
35
16
 
36
- def [](field_name)
37
- value = proxy_object.field field_name.to_s
38
- value = OrientDB::Document.new(value) if value.is_a?(KLASS)
39
- value
40
- end
17
+ def []=(field_name, value)
18
+ field field_name.to_s, value
19
+ end
41
20
 
42
- def []=(field_name, value)
43
- value = value.proxy_object if value.respond_to?(:proxy_object)
44
- # value = value.to_java if value.respond_to?(:to_java)
45
- proxy_object.field field_name.to_s, value
46
- end
21
+ def method_missing(method_name, *args, &blk)
22
+ return self[method_name] if contains_field(method_name.to_s)
23
+ match = method_name.to_s.match(/(.*?)([?=!]?)$/)
24
+ case match[2]
25
+ when "="
26
+ self[match[1]] = args.first
27
+ when "?"
28
+ !!self[match[1]]
29
+ else
30
+ super
31
+ end
32
+ end
47
33
 
48
- def method_missing(method_name, *args, &blk)
49
- return self[method_name] if proxy_object.containsField(method_name.to_s)
50
- match = method_name.to_s.match(/(.*?)([?=!]?)$/)
51
- case match[2]
52
- when "="
53
- self[match[1]] = args.first
54
- when "?"
55
- !!self[match[1]]
56
- else
57
- super
34
+ def inspect
35
+ props = values.map { |k, v| "#{k}:#{v}" }.join(' ')
36
+ %{#<OrientDB::Document:#{get_class_name}#{props.empty? ? '' : ' ' + props}>}
58
37
  end
59
- end
60
38
 
61
- def inspect
62
- props = values.map{|k,v| "#{k}:#{v}" }.join(' ')
63
- %{#<OrientDB::Document:#{proxy_object.getClassName}#{props.empty? ? '' : ' ' + props}>}
64
- end
39
+ alias :to_s :inspect
40
+
41
+ class << self
65
42
 
66
- alias :to_s :inspect
43
+ alias_method :native_new, :new
67
44
 
68
- class << self
45
+ def new(db, klass_name, fields = {})
46
+ obj = native_new db, klass_name
47
+ fields.each do |name, value|
48
+ obj.field name, value
49
+ end
50
+ obj
51
+ end
52
+
53
+ def create(db, klass_name, fields = {})
54
+ obj = new db, klass_name, fields
55
+ obj.save
56
+ obj
57
+ end
69
58
 
70
- def create(db, klass_name, fields = {})
71
- obj = new(db, klass_name, fields)
72
- obj.save
73
- obj
74
59
  end
75
60
 
76
61
  end
@@ -1,13 +1,13 @@
1
- class OrientDB::OClass
1
+ module OrientDB
2
2
 
3
- include OrientDB::ProxyMixin
4
3
 
5
- KLASS = com.orientechnologies.orient.core.metadata.schema.OClass
4
+ OClass = com.orientechnologies.orient.core.metadata.schema.OClass
6
5
 
7
- SchemaType = com.orientechnologies.orient.core.metadata.schema.OType
6
+ # SchemaType = com.orientechnologies.orient.core.metadata.schema.OType
8
7
  ClusterType = com.orientechnologies.orient.core.storage.OStorage::CLUSTER_TYPE
9
8
  IndexType = com.orientechnologies.orient.core.metadata.schema.OProperty::INDEX_TYPE
10
9
 
10
+
11
11
  FIELD_TYPES = {
12
12
  :binary => "BINARY",
13
13
  :bool => "BOOLEAN",
@@ -36,110 +36,100 @@ class OrientDB::OClass
36
36
  h
37
37
  end
38
38
 
39
- STORAGE_TYPES = %w{ LOGICAL MEMORY PHYSICAL }.inject({}) do |h, s|
40
- h[s.downcase.to_sym] = ClusterType.const_get s
41
- h
42
- end
39
+ STORAGE_TYPES = %w{ LOGICAL MEMORY PHYSICAL }.inject({}) { |h, s| h[s.downcase.to_sym] = ClusterType.const_get s; h }
40
+ INDEX_TYPES = %w{ FULLTEXT NOT_UNIQUE UNIQUE }.inject({}) { |h, s| h[s.downcase.to_sym] = IndexType.const_get s; h }
43
41
 
44
- INDEX_TYPES = %w{ FULLTEXT NOT_UNIQUE UNIQUE }.inject({}) do |h, s|
45
- h[s.downcase.to_sym] = IndexType.const_get s
46
- h
47
- end
42
+ class OClass
48
43
 
49
- def initialize(*args)
50
- if args.first.is_a?(KLASS)
51
- @proxy_object = args.first
52
- else
53
- @proxy_object = KLASS.new
54
- end
55
- end
44
+ def add(property_name, type)
45
+ property_name = property_name.to_s
46
+ if exists_property(property_name)
47
+ puts "We already have that property name [#{property_name}]"
48
+ return false
49
+ end
56
50
 
57
- def add(property_name, type)
58
- property_name = property_name.to_s
59
- if proxy_object.existsProperty(property_name)
60
- puts "We already have that property name [#{property_name}]"
61
- return false
51
+ case type
52
+ when Symbol
53
+ create_property property_name, FIELD_TYPES[type]
54
+ when OrientDB::OClass
55
+ create_property property_name, FIELD_TYPES[:link], type
56
+ when Array
57
+ type[0] = FIELD_TYPES[type[0]] if type[0].is_a?(Symbol)
58
+ create_property property_name, *type
59
+ when Hash
60
+ raise "Missing property type for [#{property_name}]" unless type[:type]
61
+ if type[:type].is_a?(OrientDB::OClass)
62
+ prop = create_property property_name, FIELD_TYPES[:link], type[:type]
63
+ else
64
+ prop = create_property property_name, FIELD_TYPES[type[:type]]
65
+ end
66
+ prop.set_min type[:min].to_s unless type[:min].nil?
67
+ prop.set_max type[:max].to_s unless type[:max].nil?
68
+ prop.set_mandatory !!type[:mandatory] unless type[:mandatory].nil?
69
+ prop.set_not_null type[:not_null] unless type[:not_null].nil?
70
+ unless type[:index].nil?
71
+ index_type = type[:index] == true ? INDEX_TYPES[:not_unique] : INDEX_TYPES[type[:index]]
72
+ prop.createIndex index_type
73
+ end
74
+ else
75
+ puts "ERROR! Unknown type [ #{property_name} | #{type} : #{type.class.name} ]"
76
+ end
77
+ self
62
78
  end
63
79
 
64
- case type
65
- when Symbol
66
- proxy_object.createProperty property_name, FIELD_TYPES[type]
67
- when OrientDB::OClass
68
- proxy_object.createProperty property_name, FIELD_TYPES[:link], type.proxy_object
69
- when Array
70
- type[0] = FIELD_TYPES[type[0]] if type[0].is_a?(Symbol)
71
- proxy_object.createProperty property_name, *type
72
- when Hash
73
- type[:type] = FIELD_TYPES[:link] if type[:type].is_a?(Symbol)
74
- prop = proxy_object.createProperty property_name, type[:type]
75
- prop.setMin(type[:min]) unless type[:min].nil?
76
- prop.setMax(type[:max]) unless type[:max].nil?
77
- prop.setMandatory(!!type[:mandatory]) unless type[:mandatory].nil?
78
- prop.setNotNull(type[:not_null]) unless type[:not_null].nil?
79
- unless type[:index].nil?
80
- index_type = type[:index] == true ? INDEX_TYPES[:not_unique] : INDEX_TYPES[type[:index]]
81
- prop.createIndex index_type
82
- end
83
- else
84
- puts "ERROR! Unknown type [ #{property_name} | #{type} : #{type.class.name} ]"
80
+ def [](property_name)
81
+ property_name = property_name.to_s
82
+ exists_property(property_name) ? get_property(property_name) : nil
85
83
  end
86
- self
87
- end
88
84
 
89
- def [](property_name)
90
- property_name = property_name.to_s
91
- proxy_object.exists_property(property_name) ? proxy_object.getProperty(property_name) : nil
92
- end
93
-
94
- def db
95
- proxy_object.getDocument.getDatabase
96
- end
85
+ def db
86
+ document.database
87
+ end
97
88
 
98
- def schema
99
- db.getMetadata.getSchema
100
- end
89
+ def schema
90
+ db.metadata.schema
91
+ end
101
92
 
102
- def create_document(fields = {})
103
- OrientDB::Document.create db, name, fields
104
- end
105
- alias :ceate :create_document
93
+ def inspect
94
+ props = properties.map { |x| "#{x.name}:#{x.type.to_s.downcase}" }.join(' ')
95
+ %{#<OrientDB::OClass:#{name}#{props.empty? ? '' : ' ' + props}>}
96
+ end
106
97
 
107
- def inspect
108
- props = properties.map { |x| "#{x.getName}:#{x.getType.to_s.downcase}" }.join(' ')
109
- %{#<OrientDB::OClass:#{name}#{props.empty? ? '' : ' ' + props}>}
110
- end
98
+ alias :to_s :inspect
111
99
 
112
- alias :to_s :inspect
113
100
 
114
- class << self
101
+ class << self
115
102
 
116
- def create(db, name, fields = {})
117
- add_cluster = fields.delete :add_cluster
118
- add_cluster = true if add_cluster.nil?
103
+ def create(db, name, fields = {})
104
+ name = name.to_s
105
+ add_cluster = fields.delete :add_cluster
106
+ add_cluster = true if add_cluster.nil?
119
107
 
120
- if add_cluster
121
- cluster = db.storage.addCluster name.downcase, STORAGE_TYPES[:physical]
122
- klass = db.schema.createClass name, cluster
123
- else
124
- klass = db.schema.createClass name
125
- end
126
-
127
- super_klass = fields.delete :super
128
- klass.setSuperClass(super_klass) if super_klass
129
- db.schema.save
108
+ if add_cluster
109
+ cluster = db.storage.add_cluster name.downcase, STORAGE_TYPES[:physical]
110
+ klass = db.schema.create_class name, cluster
111
+ else
112
+ klass = db.schema.create_class name
113
+ end
130
114
 
131
- obj = new klass
115
+ super_klass = fields.delete :super
116
+ super_klass = db.get_class(super_klass.to_s) unless super_klass.is_a?(OrientDB::OClass)
117
+ klass.set_super_class super_klass if super_klass
118
+ db.schema.save
132
119
 
133
- unless fields.empty?
134
- fields.each do |property_name, type|
135
- obj.add property_name, type
120
+ unless fields.empty?
121
+ fields.each do |property_name, type|
122
+ klass.add property_name, type
123
+ end
124
+ db.schema.save
136
125
  end
137
- db.schema.save
126
+
127
+ klass
138
128
  end
139
129
 
140
- obj
141
130
  end
142
131
 
143
132
  end
144
133
 
134
+
145
135
  end
@@ -0,0 +1,6 @@
1
+ module OrientDB
2
+
3
+ Schema = com.orientechnologies.orient.core.metadata.schema.OSchema
4
+ SchemaType = com.orientechnologies.orient.core.metadata.schema.OType
5
+
6
+ end
data/lib/orientdb/user.rb CHANGED
@@ -1,16 +1,5 @@
1
- class OrientDB::User
1
+ module OrientDB
2
2
 
3
- include OrientDB::ProxyMixin
4
-
5
- KLASS = com.orientechnologies.orient.core.metadata.security.OUser
6
-
7
- def initialize
8
- @proxy_object = KLASS.new
9
- end
10
-
11
- def self.from_ouser(ouser)
12
- obj = new
13
- obj.instance_variable_set "@proxy_object", ouser
14
- end
3
+ User = com.orientechnologies.orient.core.metadata.security.OUser
15
4
 
16
5
  end
@@ -1,3 +1,3 @@
1
- class OrientDB
2
- VERSION = "0.0.2"
1
+ module OrientDB
2
+ VERSION = "0.0.4"
3
3
  end
data/orientdb.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency "hashie"
18
18
  s.add_development_dependency "bundler", ">= 1.0.0"
19
19
  s.add_development_dependency "awesome_print"
20
+ s.add_development_dependency "rspec", ">= 2.1"
20
21
 
21
22
  s.files = `git ls-files`.split("\n")
22
23
  s.test_files = Dir["test/test*.rb"]
@@ -0,0 +1,31 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ describe "OrientDB" do
4
+
5
+ before :all do
6
+ @db = OrientDB::Database.new("local:#{TEST_DB_PATH}/test").create
7
+ @person_class = @db.create_class :person, :name => :string
8
+ @customer_class = @db.create_class :customer, :super => @person_class
9
+ @product_class = @db.create_class :product, :sku => :string, :title => :string, :price => :float
10
+ @line_class = @db.create_class :invoice_line, :product => @product_class, :quantity => :int, :price => :float
11
+ @invoice_class = @db.create_class :invoice,
12
+ :number => {:type => :int, :mandatory => true, :index => true},
13
+ :customer => {:type => @customer_class, :not_null => true},
14
+ :sold_on => :date,
15
+ :total => {:type => :float, :min => 0.01, :max => 100_000.0},
16
+ :lines => :embedded_list
17
+ end
18
+
19
+ after :all do
20
+ @db.close
21
+ # puts "Removing files in #{TEMP_DIR}/databases/*"
22
+ # FileUtils.rm_rf "#{TEMP_DIR}/databases/test"
23
+ end
24
+
25
+ it "should create a valid database" do
26
+ puts "Creating db #{@db_path}..."
27
+ @db.should be_a_kind_of OrientDB::Database
28
+ @db.name.should == "test"
29
+ end
30
+
31
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format
3
+ nested
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+ --backtrace
@@ -0,0 +1,25 @@
1
+ unless defined?(SPEC_HELPER_LOADED)
2
+
3
+ GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
+ LIB_ROOT = GEM_ROOT + '/lib'
5
+ SPEC_ROOT = GEM_ROOT + '/spec'
6
+ TEMP_DIR = SPEC_ROOT + '/tmp'
7
+
8
+ TEST_DB_PATH = "#{TEMP_DIR}/databases/db_#{rand(999) + 1}"
9
+
10
+ puts ">> GEM_ROOT : #{GEM_ROOT}"
11
+ puts ">> TEST_DB PATH : #{TEST_DB_PATH}"
12
+
13
+ $LOAD_PATH.unshift(LIB_ROOT) unless $LOAD_PATH.include?(LIB_ROOT)
14
+
15
+ require 'orientdb'
16
+ require 'spec'
17
+ require 'fileutils'
18
+
19
+ FileUtils.mkdir_p TEST_DB_PATH
20
+
21
+ Spec::Runner.configure do |config|
22
+ end
23
+
24
+ SPEC_HELPER_LOADED = true
25
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: jruby
11
11
  authors:
12
12
  - Adrian Madrid
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-03 00:00:00 -06:00
17
+ date: 2010-11-12 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,19 @@ dependencies:
55
55
  version: "0"
56
56
  type: :development
57
57
  version_requirements: *id003
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ prerelease: false
61
+ requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 2
67
+ - 1
68
+ version: "2.1"
69
+ type: :development
70
+ version_requirements: *id004
58
71
  description: JRuby wrapper for OrientDB
59
72
  email:
60
73
  - aemadrid@gmail.com
@@ -84,10 +97,13 @@ files:
84
97
  - lib/orientdb/document.rb
85
98
  - lib/orientdb/ext.rb
86
99
  - lib/orientdb/oclass.rb
87
- - lib/orientdb/proxy_mixin.rb
100
+ - lib/orientdb/schema.rb
88
101
  - lib/orientdb/user.rb
89
102
  - lib/orientdb/version.rb
90
103
  - orientdb.gemspec
104
+ - spec/orientdb_spec.rb
105
+ - spec/spec.opts
106
+ - spec/spec_helper.rb
91
107
  has_rdoc: true
92
108
  homepage: http://rubygems.org/gems/orientdb
93
109
  licenses: []
@@ -1,65 +0,0 @@
1
- class OrientDB
2
- module ProxyMixin
3
-
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
7
-
8
- attr_reader :proxy_object
9
-
10
- def respond_to?(meth)
11
- proxy_object.respond_to?(meth) || super
12
- end
13
-
14
- def method_missing(meth, *args, &blk)
15
- if proxy_object.respond_to? meth
16
- puts "mm : #{meth}"
17
- proxy_object.send meth, *args, &blk
18
- else
19
- super
20
- end
21
- end
22
-
23
- alias_method :decorator_methods, :methods
24
-
25
- def methods
26
- (decorator_methods + proxy_object.methods).uniq
27
- end
28
-
29
- module ClassMethods
30
-
31
- def proxy_method(aliased_name, real_name = nil)
32
- real_name ||= aliased_name
33
- class_eval %{def #{aliased_name}(*args) puts "pm : #{real_name}"; proxy_object.send :#{real_name}, *args end}
34
- end
35
-
36
- def proxy_methods(*args)
37
- args.each { |arg| proxy_method *arg }
38
- end
39
-
40
- def proxy_accessor(aliased_name, real_name = nil)
41
- real_name ||= aliased_name
42
- aliased_name = aliased_name.to_s
43
- if aliased_name[-1, 1] == '?'
44
- class_eval %{def #{aliased_name[0..-2]}() puts "pa : #{real_name}"; proxy_object.send :is_#{real_name}? end}
45
- class_eval %{def #{aliased_name}() puts "pa : #{real_name}"; proxy_object.send :is_#{real_name}? end}
46
- class_eval %{def #{aliased_name[0..-2]}=(v) puts "pa : #{real_name}"; proxy_object.send :set_#{real_name}, v end}
47
- else
48
- class_eval %{def #{aliased_name}() puts "pa : #{real_name}"; proxy_object.send :get_#{real_name}? end}
49
- class_eval %{def #{aliased_name}=(v) puts "pa : #{real_name}"; proxy_object.send :set_#{real_name}, v end}
50
- end
51
- end
52
-
53
- def proxy_accessors(*args)
54
- args.each { |arg| proxy_accessor *arg }
55
- end
56
-
57
- def self.const_missing(missing)
58
- puts "[#{name}:const_missing] #{missing}"
59
- super
60
- end
61
-
62
- end
63
-
64
- end
65
- end