active-orient 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +8 -3
  4. data/Guardfile +12 -4
  5. data/README.md +221 -201
  6. data/VERSION +1 -1
  7. data/active-orient.gemspec +3 -2
  8. data/bin/active-orient-console +35 -0
  9. data/config/boot.rb +84 -16
  10. data/config/config.yml +10 -0
  11. data/config/connect.yml +6 -2
  12. data/create_project +19 -0
  13. data/examples/books.rb +86 -39
  14. data/examples/createTime.rb +91 -0
  15. data/examples/streets.rb +85 -84
  16. data/examples/test_commands.rb +92 -0
  17. data/examples/test_commands_2.rb +54 -0
  18. data/examples/test_commands_3.rb +48 -0
  19. data/examples/test_commands_4.rb +28 -0
  20. data/examples/time_graph/Gemfile +21 -0
  21. data/examples/time_graph/Guardfile +26 -0
  22. data/examples/time_graph/README.md +129 -0
  23. data/examples/time_graph/bin/active-orient-console +35 -0
  24. data/examples/time_graph/config/boot.rb +119 -0
  25. data/examples/time_graph/config/config.yml +8 -0
  26. data/examples/time_graph/config/connect.yml +17 -0
  27. data/examples/time_graph/config/init_db.rb +59 -0
  28. data/examples/time_graph/createTime.rb +51 -0
  29. data/examples/time_graph/lib/createTime.rb +82 -0
  30. data/examples/time_graph/model/day_of.rb +3 -0
  31. data/examples/time_graph/model/e.rb +6 -0
  32. data/examples/time_graph/model/edge.rb +53 -0
  33. data/examples/time_graph/model/monat.rb +19 -0
  34. data/examples/time_graph/model/stunde.rb +16 -0
  35. data/examples/time_graph/model/tag.rb +29 -0
  36. data/examples/time_graph/model/time_base.rb +6 -0
  37. data/examples/time_graph/model/time_of.rb +4 -0
  38. data/examples/time_graph/model/v.rb +3 -0
  39. data/examples/time_graph/model/vertex.rb +32 -0
  40. data/examples/time_graph/spec/lib/create_time_spec.rb +50 -0
  41. data/examples/time_graph/spec/rest_helper.rb +37 -0
  42. data/examples/time_graph/spec/spec_helper.rb +46 -0
  43. data/lib/active-orient.rb +56 -6
  44. data/lib/base.rb +149 -147
  45. data/lib/base_properties.rb +40 -41
  46. data/lib/class_utils.rb +301 -0
  47. data/lib/database_utils.rb +97 -0
  48. data/lib/init.rb +35 -0
  49. data/lib/java-api.rb +437 -0
  50. data/lib/jdbc.rb +211 -0
  51. data/lib/model/edge.rb +53 -0
  52. data/lib/model/model.rb +77 -0
  53. data/lib/model/the_class.rb +480 -0
  54. data/lib/model/the_record.rb +310 -0
  55. data/lib/model/vertex.rb +32 -0
  56. data/lib/orient.rb +113 -50
  57. data/lib/orientdb_private.rb +48 -0
  58. data/lib/other.rb +280 -0
  59. data/lib/query.rb +71 -73
  60. data/lib/rest/change.rb +124 -0
  61. data/lib/rest/create.rb +474 -0
  62. data/lib/rest/delete.rb +133 -0
  63. data/lib/rest/operations.rb +150 -0
  64. data/lib/rest/read.rb +150 -0
  65. data/lib/rest/rest.rb +111 -0
  66. data/lib/rest_disabled.rb +24 -0
  67. data/lib/support.rb +387 -296
  68. data/old_lib_functions/two_general_class.rb +139 -0
  69. data/usecase.md +49 -36
  70. data/usecase_oo.md +59 -0
  71. metadata +73 -9
  72. data/lib/model.rb +0 -461
  73. data/lib/rest.rb +0 -1036
  74. data/test.rb +0 -4
@@ -0,0 +1,139 @@
1
+ # NEW
2
+
3
+ def create_general_class classes, behaviour = "NORMALCLASS", extend_class, properties: nil
4
+ if @classes_available.nil?
5
+ @classes_available = get_database_classes requery: true
6
+ @classes_available = @classes_available.map!{|x| x.downcase}
7
+ end
8
+
9
+ begin
10
+ consts = Array.new
11
+
12
+ if classes.is_a? Array
13
+ if behaviour == "NORMALCLASS"
14
+ classes.each do |singleclass|
15
+ consts |= create_general_class singleclass, properties: properties
16
+ end
17
+ else
18
+ classes.each do |singleclass|
19
+ consts |= create_general_class singleclass, "EXTENDEDCLASS", extend_class, properties: properties
20
+ end
21
+ end
22
+
23
+ elsif classes.is_a? Hash
24
+ classes.keys.each do |superclass|
25
+ consts |= create_general_class superclass, "SUPERCLASS"
26
+ consts |= create_general_class classes[superclass], "EXTENDEDCLASS", superclass, properties: properties
27
+ end
28
+
29
+ else
30
+ name_class = classes.to_s.camelize
31
+ unless @classes_available.include?(name_class.downcase)
32
+
33
+ if behaviour == "NORMALCLASS"
34
+ command = "CREATE CLASS #{name_class}"
35
+ elsif behaviour = "SUPERCLASS"
36
+ command = "CREATE CLASS #{name_class} ABSTRACT"
37
+ elsif behaviour = "EXTENDEDCLASS"
38
+ name_superclass = extend_class.to_s.camelize
39
+ command = "CREATE CLASS #{name_class} EXTENDS #{name_superclass}"
40
+ end
41
+
42
+ execute transaction: false do
43
+ { type: "cmd",
44
+ language: "sql",
45
+ command: command}
46
+ end
47
+
48
+ @classes_available << name_class.downcase
49
+
50
+ # Add properties
51
+ unless properties.nil?
52
+ create_properties temp_class, properties
53
+ end
54
+
55
+ end
56
+ temp_class = ActiveOrient::Model.orientdb_class(name: name_class)
57
+ consts << temp_class
58
+ return consts
59
+ end
60
+ rescue RestClient::InternalServerError => e
61
+ logger.progname = 'RestCreate#CreateGeneralClass'
62
+ response = JSON.parse(e.response)['errors'].pop
63
+ logger.error{"#{response['content'].split(':').last }"}
64
+ nil
65
+ end
66
+ end
67
+ alias create_classes create_general_class
68
+
69
+ # OLD
70
+
71
+ def create_general_class classes, properties: nil
72
+ begin
73
+ get_database_classes requery: true
74
+ consts = Array.new
75
+ execute transaction: false do
76
+ class_cmd = -> (s,n) do
77
+ n = n.to_s.camelize
78
+ consts << ActiveOrient::Model.orientdb_class(name: n)
79
+ classes_available = get_database_classes.map{|x| x.downcase}
80
+ unless classes_available.include?(n.downcase)
81
+ {type: "cmd", language: 'sql', command: "CREATE CLASS #{n} EXTENDS #{s}"}
82
+ end
83
+ end ## class_cmd
84
+
85
+ if classes.is_a?(Array)
86
+ classes.map do |n|
87
+ n = n.to_s.camelize
88
+ consts << ActiveOrient::Model.orientdb_class(name: n)
89
+ classes_available = get_database_classes.map{|x| x.downcase}
90
+ unless classes_available.include?(n.downcase)
91
+ {type: "cmd", language: 'sql', command: "CREATE CLASS #{n}"}
92
+ end
93
+ end
94
+ elsif classes.is_a?(Hash)
95
+ classes.keys.map do |superclass|
96
+ items = Array.new
97
+ superClass = superclass.to_s.camelize
98
+ unless get_database_classes.flatten.include?(superClass)
99
+ items << {type: "cmd", language: 'sql', command: "CREATE CLASS #{superClass} ABSTRACT"}
100
+ end
101
+ items << if classes[superclass].is_a?(String) || classes[superclass].is_a?(Symbol)
102
+ class_cmd[superClass, classes[superclass]]
103
+ elsif classes[superclass].is_a?(Array)
104
+ classes[superclass].map{|n| class_cmd[superClass, n]}
105
+ end
106
+ items # returnvalue
107
+ end.flatten
108
+ end.compact # erase nil-entries, in case the class is already allocated
109
+ end
110
+ # refresh cached class-informations
111
+ classes_available = get_database_classes requery: true
112
+
113
+ # Add properties
114
+ unless properties.nil?
115
+ classes_available.map!{|x| x.downcase}
116
+ consts = Array.new
117
+ if classes.is_a?(Hash)
118
+ superclass = classes.keys[0]
119
+ classes = [classes[superclass]]
120
+ end
121
+ classes.each do |n|
122
+ if classes_available.include?(n.downcase)
123
+ temp_class = ActiveOrient::Model.orientdb_class(name: n)
124
+ create_properties temp_class, properties
125
+ consts << temp_class
126
+ end
127
+ end
128
+ end
129
+
130
+ # returns an array of allocated Constants/Classes
131
+ consts
132
+ rescue RestClient::InternalServerError => e
133
+ logger.progname = 'RestCreate#CreateGeneralClass'
134
+ response = JSON.parse(e.response)['errors'].pop
135
+ logger.error{"#{response['content'].split(':').last }"}
136
+ nil
137
+ end
138
+ end
139
+ alias create_classes create_general_class
data/usecase.md CHANGED
@@ -1,67 +1,80 @@
1
1
  ## Usecase
2
2
  Below some typical features are summarized by example
3
3
 
4
- Start a irb-session and initialize ActiveOrient
5
- ```ruby
6
- topo@gamma:~/new_hctw$ irb
7
- 2.2.1 :001 > require './config/boot'
8
- Using development-environment
9
- -------------------- initialize -------------------- => true
10
- 2.2.1 :002 > ActiveOrient::Model.orientdb = ror = ActiveOrient::OrientDB.new
11
- => #<ActiveOrient::OrientDB:0x000000046f1a90 @res=#<RestClient::Resource:0x000000046c0af8 @url="http://localhost:2480", @block=nil, @options={:user=>"hctw", :password=>"**"}>, @database="hc_database", @classes=[]>
4
+ Initialize ActiveOrient by calling »bin/active-orient-console t«.
5
+ This connects to the Test-Database, specified in »config/connect.yml«.
6
+
7
+ ```bash
8
+ topo@gamma:~/activeorient/bin$ ./active-orient-console t
9
+ Using test-environment
10
+ 30.06.(21:36:09) INFO->OrientDB#Connect:..:Connected to database tempera
11
+ ORD points to the REST-Instance
12
+ Allocated Classes (Hierarchy)
13
+ -----------------------------------
14
+ ---
15
+ - E
16
+ - - V
17
+ - - a
18
+ - b
19
+ - c
20
+
21
+ ```
22
+ The database is almost empty. "E" and "V" are base classes for Edges and Vertices.
23
+ "a,b,c" are Vertex-Classes.
24
+ ```ruby
25
+ A,B,C = * ORD.create_classes( [ :a, :b, :c ] ){ :v }
12
26
  ```
27
+ creates them with a single statement and assigns them to Ruby-classes "A","B" and "C".
28
+
13
29
  #### Object Mapping
14
30
  Lets create a class, put some content in it and perform basic oo-steps.
15
31
 
16
- Attributes(Properties) do not have to be formaly declared. However it is nessessary to introduce them properly. This is done with the »attributes«-Argument during the initialisation step or via
32
+ Attributes(Properties) do not have to be formaly declared. One can save any Object, which
33
+ provides a 'to_orient' method. Base-Classes are supported out of the box.
17
34
  »update«
18
35
 
19
36
  ``` ruby
20
- A = r.create_class 'my_a_class'
21
- => ActiveOrient::Model::Myaclass
22
- a = A.new_document attributes: { test: 45}
23
- a.update set: { a_array: aa= [ 1,4,'r', :r ] ,
37
+ A = ORD.create_class 'my_a_class'
38
+ => ActiveOrient::Model::MyAClass
39
+ a = A.create test: 45
40
+ a.update set: { a_array: aa= [ 1,4,'r' ] ,
24
41
  a_hash: { :a => 'b', b: 2 } }
25
42
  a.to_human
26
- => <Myaclass: a_array: [1, 4, "r", :r] a_hash: {:a=>"b", :b=>2} test: 45>
43
+ => <MyAClass: a_array: [1, 4, r], a_hash: { a => b , b =>2}, test: 45>
27
44
 
28
45
  ```
29
- Then the attibutes/properties can be handled as normal ruby objects ie.
46
+ **Notice** Ruby-Symbols are converted to Strings and masked as ":{symbol}:".
47
+
48
+ Attibutes/properties of the Database-Record can be handled as normal ruby objects, ie.
30
49
 
31
50
  ``` ruby
32
- a.a_array << "a new element"
33
- a.a_hash[ :a_new_element ] = "value of the new element"
51
+ a.a_array << "a new element" # changes are updated in the DB, calling »update« is not nesessary
52
+ a.a_hash[ :a_new_element ] = "value of the new element" # changes are local, »update« stores them in the DB
34
53
  a.test += 3
35
54
  a.test = 567
36
55
  a.update
37
56
  ```
38
- Objects are synchronized with the database with »update«. To revert changes, a »reload!« method is available.
39
57
 
40
58
  #### Contracts-Example
41
59
  Assume a Database, which is defined as
42
60
  ```
43
- create class Industries
44
- create class Categories
45
- create class SubCategories
46
- create class OpenInterest ABSTRACT
47
- create class Stocks extends Contracts
48
- create class Futures extends Contracts
49
- create class Options extends Contracts
50
- create class Forexes extends Contracts
51
- create property Industries.categories linkset
52
- create property Categories.subcategories linkset
53
- create property Categories.industry link
54
- create property SubCategories.category link
55
- create property SubCategories.contracts linkset
56
-
57
- create property Contracts.subcategory link
58
- create property Contracts.details link
59
- create property OpenInterest.contracts linkset
61
+ ORD.create_classes [ :Industry, :Category, :SubCategory ]
62
+ ORD.create_class :OpenInterest, abstract: true
63
+ ORD.create_classes { :Contract => [ :Stock, Future, Option, Forex ]}
64
+ ORD.create_property Industry.categories linkset
65
+ ORD.create_property Category.subcategories linkset
66
+ ORD.create_property Category.industry link
67
+ ORD.create_property SubCategory.category link
68
+ ORD.create_property SubCategory.contracts linkset
69
+
70
+ ORD.create_property Contracts.subcategory link
71
+ ORD.create_property Contracts.details link
72
+ ORD.create_property OpenInterest.contracts linkset
60
73
 
61
74
  ```
62
75
  This defines some conventional relations:
63
76
 
64
- OpenInterest -> Contracts <- Subcategory <- Category <- Industry
77
+ OpenInterest -> Contract <- Subcategory <- Category <- Industry
65
78
 
66
79
  with some oo-Behavior
67
80
  ```ruby
@@ -0,0 +1,59 @@
1
+ ## Usecase
2
+ Below some typical features are summarized by example
3
+
4
+ Initialize ActiveOrient by calling »bin/actibe-orient-console t«.
5
+ This connects to the Test-Database.
6
+
7
+ ```ruby
8
+ topo@gamma:~/activeorient/bin$ ./active-orient-console t
9
+ Using test-environment
10
+ 30.06.(21:36:09) INFO->OrientDB#Connect:..:Connected to database tempera
11
+ ORD points to the REST-Instance
12
+ Allocated Classes (Hierarchy)
13
+ -----------------------------------
14
+ ---
15
+ - E
16
+ - - V
17
+ - - a
18
+ - b
19
+ - c
20
+
21
+ ```
22
+ The database is almost empty. "E" and "V" are base classes for Edges and Vertices.
23
+ "a,b,c" are Vertex-Classes.
24
+ ```ruby
25
+ ORD.create_classes( [ :a, :b, :c ] ){ :V }
26
+ ```
27
+ creates them with a single statement. They are mapped to Ruby-classes "A","B" and "C".
28
+
29
+ #### Object Mapping
30
+ Lets create a class, put some content in it and perform basic oo-steps.
31
+
32
+ Attributes(Properties) do not have to be formaly declared. One can save any Object, which
33
+ provides a 'to_orient' method. Base-Classes are supported out of the box.
34
+ »update«
35
+
36
+ ``` ruby
37
+ ORD.create_class 'my_a_class'
38
+ => MyAClass
39
+ my_class = MyAClass.create test: 45
40
+ my_class.update set: { a_array: aa= [ 1,4,'r' ] ,
41
+ a_hash: { :a => 'b', b: 2 } }
42
+ my_class.to_human
43
+ => "<MyAClass: a_array: [1, 4, r], a_hash: { a => b , b =>2}, test: 45>"
44
+
45
+ ```
46
+ **Notice** Ruby-Symbols are converted to Strings and masked as ":{symbol}:".
47
+ There is a method: String#from_orient, which reverses the prodedure.
48
+
49
+ Attibutes/properties of the Database-Record can be handled as normal ruby objects ie.
50
+
51
+ ``` ruby
52
+ my_class.a_array << "a new element"
53
+ my_class.a_hash[ :a_new_element ] = "value of the new element"
54
+ my_class.test += 3
55
+ my_class.test = 567
56
+ my_class.update
57
+ ```
58
+
59
+ ## Inherence
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-orient
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hartmut Bischoff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rest-client
56
+ name: activemodel
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '4.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '4.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Persistent ORM for OrientDB, based on ActiveModel
70
84
  email:
71
85
  - topofocus@gmail.com
@@ -81,20 +95,70 @@ files:
81
95
  - README.md
82
96
  - VERSION
83
97
  - active-orient.gemspec
98
+ - bin/active-orient-console
84
99
  - config/boot.rb
100
+ - config/config.yml
85
101
  - config/connect.yml
102
+ - create_project
86
103
  - examples/books.rb
104
+ - examples/createTime.rb
87
105
  - examples/streets.rb
106
+ - examples/test_commands.rb
107
+ - examples/test_commands_2.rb
108
+ - examples/test_commands_2.rb~
109
+ - examples/test_commands_3.rb
110
+ - examples/test_commands_4.rb
111
+ - examples/time_graph/Gemfile
112
+ - examples/time_graph/Guardfile
113
+ - examples/time_graph/README.md
114
+ - examples/time_graph/bin/active-orient-console
115
+ - examples/time_graph/config/boot.rb
116
+ - examples/time_graph/config/config.yml
117
+ - examples/time_graph/config/connect.yml
118
+ - examples/time_graph/config/init_db.rb
119
+ - examples/time_graph/createTime.rb
120
+ - examples/time_graph/lib/createTime.rb
121
+ - examples/time_graph/model/day_of.rb
122
+ - examples/time_graph/model/e.rb
123
+ - examples/time_graph/model/edge.rb
124
+ - examples/time_graph/model/monat.rb
125
+ - examples/time_graph/model/stunde.rb
126
+ - examples/time_graph/model/tag.rb
127
+ - examples/time_graph/model/time_base.rb
128
+ - examples/time_graph/model/time_of.rb
129
+ - examples/time_graph/model/v.rb
130
+ - examples/time_graph/model/vertex.rb
131
+ - examples/time_graph/spec/lib/create_time_spec.rb
132
+ - examples/time_graph/spec/rest_helper.rb
133
+ - examples/time_graph/spec/spec_helper.rb
88
134
  - lib/active-orient.rb
89
135
  - lib/base.rb
90
136
  - lib/base_properties.rb
91
- - lib/model.rb
137
+ - lib/class_utils.rb
138
+ - lib/database_utils.rb
139
+ - lib/init.rb
140
+ - lib/java-api.rb
141
+ - lib/jdbc.rb
142
+ - lib/model/edge.rb
143
+ - lib/model/model.rb
144
+ - lib/model/the_class.rb
145
+ - lib/model/the_record.rb
146
+ - lib/model/vertex.rb
92
147
  - lib/orient.rb
148
+ - lib/orientdb_private.rb
149
+ - lib/other.rb
93
150
  - lib/query.rb
94
- - lib/rest.rb
151
+ - lib/rest/change.rb
152
+ - lib/rest/create.rb
153
+ - lib/rest/delete.rb
154
+ - lib/rest/operations.rb
155
+ - lib/rest/read.rb
156
+ - lib/rest/rest.rb
157
+ - lib/rest_disabled.rb
95
158
  - lib/support.rb
96
- - test.rb
159
+ - old_lib_functions/two_general_class.rb
97
160
  - usecase.md
161
+ - usecase_oo.md
98
162
  homepage: https://github.com/topofocus/active-orient
99
163
  licenses:
100
164
  - MIT
@@ -107,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
171
  requirements:
108
172
  - - ">="
109
173
  - !ruby/object:Gem::Version
110
- version: 2.2.0
174
+ version: 2.2.5
111
175
  required_rubygems_version: !ruby/object:Gem::Requirement
112
176
  requirements:
113
177
  - - ">="