active-orient 0.4 → 0.80

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.graphs.txt.swp +0 -0
  4. data/Gemfile +9 -5
  5. data/Guardfile +12 -4
  6. data/README.md +70 -281
  7. data/VERSION +1 -1
  8. data/active-orient.gemspec +9 -7
  9. data/bin/active-orient-0.6.gem +0 -0
  10. data/bin/active-orient-console +97 -0
  11. data/changelog.md +60 -0
  12. data/config/boot.rb +70 -17
  13. data/config/config.yml +10 -0
  14. data/config/connect.yml +11 -6
  15. data/examples/books.rb +154 -65
  16. data/examples/streets.rb +89 -85
  17. data/graphs.txt +70 -0
  18. data/lib/active-orient.rb +78 -6
  19. data/lib/base.rb +266 -168
  20. data/lib/base_properties.rb +76 -65
  21. data/lib/class_utils.rb +187 -0
  22. data/lib/database_utils.rb +99 -0
  23. data/lib/init.rb +80 -0
  24. data/lib/java-api.rb +442 -0
  25. data/lib/jdbc.rb +211 -0
  26. data/lib/model/custom.rb +29 -0
  27. data/lib/model/e.rb +6 -0
  28. data/lib/model/edge.rb +114 -0
  29. data/lib/model/model.rb +134 -0
  30. data/lib/model/the_class.rb +657 -0
  31. data/lib/model/the_record.rb +313 -0
  32. data/lib/model/vertex.rb +371 -0
  33. data/lib/orientdb_private.rb +48 -0
  34. data/lib/other.rb +423 -0
  35. data/lib/railtie.rb +68 -0
  36. data/lib/rest/change.rb +150 -0
  37. data/lib/rest/create.rb +287 -0
  38. data/lib/rest/delete.rb +150 -0
  39. data/lib/rest/operations.rb +222 -0
  40. data/lib/rest/read.rb +189 -0
  41. data/lib/rest/rest.rb +120 -0
  42. data/lib/rest_disabled.rb +24 -0
  43. data/lib/support/conversions.rb +42 -0
  44. data/lib/support/default_formatter.rb +7 -0
  45. data/lib/support/errors.rb +41 -0
  46. data/lib/support/logging.rb +38 -0
  47. data/lib/support/orient.rb +305 -0
  48. data/lib/support/orientquery.rb +647 -0
  49. data/lib/support/query.rb +92 -0
  50. data/rails.md +154 -0
  51. data/rails/activeorient.rb +32 -0
  52. data/rails/config.yml +10 -0
  53. data/rails/connect.yml +17 -0
  54. metadata +89 -30
  55. data/lib/model.rb +0 -461
  56. data/lib/orient.rb +0 -98
  57. data/lib/query.rb +0 -88
  58. data/lib/rest.rb +0 -1036
  59. data/lib/support.rb +0 -347
  60. data/test.rb +0 -4
  61. data/usecase.md +0 -91
@@ -1,347 +0,0 @@
1
- class String
2
- def to_classname
3
- if self[0] =='$'
4
- self[1..-1]
5
- else
6
- self.camelize
7
- end
8
- end
9
- def to_orient
10
- self.gsub /%/, '(percent)'
11
-
12
- end
13
- def rid?
14
- self =~ /\A[#]{,1}[0-9]{1,}:[0-9]{1,}\z/
15
- end
16
- def from_orient
17
- if rid?
18
- ActiveOrient::Model.autoload_object self
19
- else
20
- self
21
- end
22
- end
23
- ## this enables the universal use of an rid-string as pseudonym for a ActiveOrient::Model
24
- alias :reload! from_orient
25
- end
26
- class NilClass
27
- def to_orient
28
- self
29
- end
30
- end
31
- class Symbol
32
- def to_orient
33
- self.to_s.to_orient
34
- end
35
- def from_orient
36
- self
37
- end
38
- end
39
-
40
- class Numeric
41
- def from_orient
42
- self
43
- end
44
- def to_orient
45
- self
46
- end
47
- end
48
-
49
- class Time
50
- def from_orient
51
- self
52
- end
53
- def to_orient
54
- self
55
- end
56
- end
57
- class Date
58
- def from_orient
59
- self
60
- end
61
- def to_orient
62
- self
63
- end
64
- end
65
-
66
- class TrueClass
67
- def from_orient
68
- self
69
- end
70
- def to_orient
71
- self
72
- end
73
- end
74
- class FalseClass
75
- def from_orient
76
- self
77
- end
78
- def to_orient
79
- self
80
- end
81
- end
82
-
83
- class Array
84
- def to_orient
85
- map &:to_orient
86
- end
87
- def from_orient
88
- map &:from_orient
89
- end
90
- end
91
- class Hash #WithIndifferentAccess
92
- def from_orient
93
- substitute_hash = HashWithIndifferentAccess.new
94
- keys.each{ |k| puts self[k].inspect }
95
- keys.each{| k | substitute_hash[k] = self[k].from_orient }
96
- substitute_hash
97
-
98
- end
99
- def to_orient
100
- substitute_hash = Hash.new
101
- keys.each{| k | substitute_hash[k] = self[k].to_orient }
102
- substitute_hash
103
-
104
- end
105
-
106
- def nested_under_indifferent_access
107
- HashWithIndifferentAccess.new self
108
- end
109
- end
110
-
111
-
112
- module OrientSupport
113
-
114
- module Support
115
- =begin
116
- supports
117
-
118
- where: 'string'
119
- where: { property: 'value', property: value, ... }
120
- where: ['string, { property: value, ... }, ... ]
121
-
122
-
123
- Used by update and select
124
- =end
125
-
126
- def compose_where *arg
127
- arg=arg.flatten
128
- return "" if arg.blank? || arg.size == 1 && arg.first.blank?
129
- "where " + arg.map do |issue|
130
- case issue
131
- when String
132
- issue
133
- when Hash
134
- generate_sql_list issue
135
- end
136
- end.join( ' and ' )
137
- end
138
- def generate_sql_list attributes={}
139
- attributes.map do | key, value |
140
- case value
141
- when Numeric
142
- key.to_s << " = " << value.to_s
143
- else # String, Symbol, Date, Time, Trueclass, Falseclass ...
144
- key.to_s << ' = ' << "\'#{ value }\'"
145
- end
146
- end.join( ' and ' )
147
- end
148
- end # module
149
-
150
-
151
- class OrientQuery
152
-
153
- include Support
154
-
155
- def initialize **args
156
- @projection = []
157
- @misc = []
158
- @let = []
159
- @where = []
160
- @order = []
161
- args.each do | k,v|
162
- case k
163
- when :projection
164
- @projection << v
165
- when :let
166
- @let << v
167
- when :order
168
- @order << v
169
- when :where
170
- @where << v
171
- else
172
- self.send k, v
173
- end
174
- end
175
- end
176
-
177
- def method_missing method, *arg, &b
178
- @misc << method.to_s << " " << arg.map(&:to_s).join(' ')
179
- end
180
-
181
- def misc
182
- @misc.join(' ') unless @misc.empty?
183
- end
184
-
185
- def subquery
186
- nil
187
- end
188
-
189
- def compose
190
- [ "select", projection_s, from, let_s, where_s , subquery, misc, order_s , group_by, unwind, skip ].compact.join(' ')
191
- end
192
-
193
- alias :to_s :compose
194
- =begin
195
- from can either be a Databaseclass to operate on or a Subquery providing data to query further
196
- =end
197
- def from arg=nil
198
- if arg.present?
199
- @database = case arg
200
- when Class
201
- arg.new.classname
202
- when ActiveOrient::Model
203
- classname
204
- when String
205
- arg
206
- when Symbol
207
- arg
208
- when OrientQuery
209
- arg
210
- end
211
- compose # return the complete query
212
- else # read from
213
- "from " << @database.to_s unless @database.nil?
214
- end
215
- end
216
- alias :from= :from
217
- def database_class= arg
218
- @database = arg if @database.present?
219
- if @from.is_a? OrientQuery
220
- @from.database_class= arg
221
- end
222
- end
223
- def database_class
224
- if @database.present?
225
- @database
226
- elsif @from.is_a? OrientQuery
227
- @from.database_class
228
- else
229
- nil
230
- end
231
- end
232
-
233
-
234
- =begin
235
- Call where without a parameter to request the saved where-string
236
-
237
- to create the where-part of the query a string, a hash or an Array is supported
238
-
239
- where: "r > 9" --> where r > 9
240
- where: {a: 9, b: 's'} --> where a = 9 and b = 's'
241
- where:[{ a: 2} , 'b > 3',{ c: 'ufz' }] --> where a = 2 and b > 3 and c = 'ufz'
242
- =end
243
- attr_accessor :where
244
- def where_s
245
- compose_where @where
246
- end
247
-
248
-
249
- attr_accessor :let
250
- def let_s
251
- unless @let.empty?
252
- "let " << @let.map do |s|
253
- case s
254
- when Hash
255
- s.map{ |x,y| "$#{x} = ( #{y} )"}.join( ', ')
256
- when Array
257
- s.join(', ')
258
- else
259
- s
260
- end
261
- end.join(', ')
262
- end
263
- end
264
-
265
- def distinct d
266
- @projection << case d
267
- when String, Symbol
268
- "distinct( #{d.to_s} )"
269
- when Array
270
- "distinct( #{d.first} ) as #{d.last}"
271
- when Hash
272
- "distinct( #{d.first.first} ) as #{d.first.last}"
273
- else
274
- ""
275
- end
276
- compose # return the hole query
277
- end
278
- alias :distinct= :distinct
279
-
280
- attr_accessor :projection
281
- def projection_s
282
-
283
- @projection.map do | s |
284
- case s
285
- when Hash
286
- s.map{ |x,y| "#{x} as #{y}"}.join( ', ')
287
- when Array
288
- s.join(', ')
289
- else
290
- s
291
- end
292
- end.join( ', ' )
293
-
294
- end
295
-
296
-
297
- # def where= w
298
-
299
- # end
300
- # select_string = ("select " + select_string + distinct_string + ' from ' + class_name(o_class) ).squeeze(' ')
301
- # where_string = compose_where( where )
302
- def group_by g=nil
303
- @group = "group_by #{g.to_s}" if g.present?
304
- # only a string is allowed
305
- @group # return_value
306
- end
307
- def unwind u=nil
308
- @unwind = "unwind #{u.to_s}" if u.present?
309
- # only a string is allowed
310
- @unwind # return_value
311
- end
312
-
313
- def skip n=nil
314
- @skip= n if n.present?
315
- "skip #{@skip}" if @skip.present?
316
- end
317
-
318
- attr_accessor :order
319
-
320
- def order_s
321
- unless @order.empty?
322
- # the [@order] is nessesary to enable query.order= "..." oder query.order= { a: :b }
323
- "order by " << [@order].flatten.map do | o |
324
- case o
325
- when Hash
326
- o.map{ |x,y| "#{x} #{y}" }.join( " " )
327
- else
328
- o.to_s
329
- end # case
330
- end.join(', ')
331
- else
332
- ''
333
- end
334
- end
335
- # misc_string = if skip > 0 && limit > 0
336
- # " skip: #{skip} "
337
- # else
338
- # ""
339
- # end
340
- # #
341
- #
342
- # def compose
343
- #
344
- # end
345
-
346
- end
347
- end # module
data/test.rb DELETED
@@ -1,4 +0,0 @@
1
- $:.unshift File.expand_path('.')
2
- require 'config/boot'
3
-
4
-
data/usecase.md DELETED
@@ -1,91 +0,0 @@
1
- ## Usecase
2
- Below some typical features are summarized by example
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=[]>
12
- ```
13
- #### Object Mapping
14
- Lets create a class, put some content in it and perform basic oo-steps.
15
-
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
17
- »update«
18
-
19
- ``` 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 ] ,
24
- a_hash: { :a => 'b', b: 2 } }
25
- a.to_human
26
- => <Myaclass: a_array: [1, 4, "r", :r] a_hash: {:a=>"b", :b=>2} test: 45>
27
-
28
- ```
29
- Then the attibutes/properties can be handled as normal ruby objects ie.
30
-
31
- ``` ruby
32
- a.a_array << "a new element"
33
- a.a_hash[ :a_new_element ] = "value of the new element"
34
- a.test += 3
35
- a.test = 567
36
- a.update
37
- ```
38
- Objects are synchronized with the database with »update«. To revert changes, a »reload!« method is available.
39
-
40
- #### Contracts-Example
41
- Assume a Database, which is defined as
42
- ```
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
60
-
61
- ```
62
- This defines some conventional relations:
63
-
64
- OpenInterest -> Contracts <- Subcategory <- Category <- Industry
65
-
66
- with some oo-Behavior
67
- ```ruby
68
- 2.2.1 :003 > ror.class_hierachie base_class: 'Contracts'
69
- => ["Forexes", "Futures", "Options", "Stocks"]
70
- ```
71
-
72
- then the following ORM-behavior is implemented:
73
- ```ruby
74
- topo@gamma:~/new_hctw$ irb
75
- 2.2.1 :001 > require './config/boot'
76
- Using development-environment
77
- -------------------- initialize -------------------- => true
78
- 2.2.1 :002 > ActiveOrient::Model.orientdb = ror = ActiveOrient::OrientDB.new
79
- => #<ActiveOrient::OrientDB:0x000000046f1a90 @res=#<RestClient::Resource:0x000000046c0af8 @url="http://localhost:2480", @block=nil, @options={:user=>"hctw", :password=>"**"}>, @database="hc_database", @classes=[]>
80
- 2.2.1 :003 > OpenInterest = ror.open_class 'Openinterest'
81
- => ActiveOrient::Model::Openinterest
82
- 2.2.1 :004 > first_open_interest = OpenInterest.first
83
- => #<ActiveOrient::Model::Openinterest:0x0000000443ede8 @metadata={"type"=>"d", "class"=>"Openinterest", "version"=>5, "fieldTypes"=>"fetch_date=t,contracts=z", "cluster"=>13, "record"=>0}, @attributes={"fetch_date"=>"2015-06-02 00:00:00", "contracts"=>["#21:36", "#21:35", "#21:34", "#21:33", "#21:32", "#21:31", "#21:30", "#21:29", "#21:28", "#21:27", "#21:26", "#21:25", "#21:24", "#21:23", "#21:22", "#21:21", "#21:51", "#21:49", "#21:50", "#21:47", "#21:48", "#21:45", "#21:46", "#21:43", "#21:44", "#21:41", "#21:42", "#21:39", "#21:40", "#21:37", "#21:38", "#21:4", "#21:3", "#21:0", "#21:17", "#21:18", "#21:19", "#21:20", "#21:13", "#21:14", "#21:15", "#21:16", "#21:9", "#21:10", "#21:11", "#21:12", "#21:5", "#21:6", "#21:7", "#21:8"], "created_at"=>2015-07-01 15:27:41 +0200, "updated_at"=>2015-07-01 15:27:41 +0200}>
84
- 2.2.1 :005 > first_open_interest.contracts.first.subcategory.category.industry
85
- => #<ActiveOrient::Model::Industries:0x00000004af88f0 @metadata={"type"=>"d", "class"=>"Industries", "version"=>8, "fieldTypes"=>"categories=n", "cluster"=>17, "record"=>1}, @attributes={"categories"=>["#15:13", "#15:4", "#15:1"], "name"=>"Basic Materials", "created_at"=>2015-07-01 15:27:58 +0200, "updated_at"=>2015-07-01 15:27:58 +0200}>
86
-
87
- 2.2.1 :006 > first_open_interest.contracts.first.subcategory.category.industry.name
88
- => "Basic Materials"
89
- ```
90
-
91
-