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
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4
1
+ 0.80
@@ -8,10 +8,10 @@ Gem::Specification.new do |s|
8
8
  s.email = ["topofocus@gmail.com"]
9
9
  s.homepage = 'https://github.com/topofocus/active-orient'
10
10
  s.licenses = ['MIT']
11
- s.summary = 'Pure ruby client for OrientDB based on ActiveModel'
12
- s.description = 'Persistent ORM for OrientDB, based on ActiveModel'
11
+ s.summary = 'Pure ruby client for OrientDB(V.3) based on ActiveModel'
12
+ s.description = 'Persistent ORM for OrientDB(V.3), based on ActiveModel'
13
13
  s.platform = Gem::Platform::RUBY
14
- s.required_ruby_version = '>= 2.2.0'
14
+ s.required_ruby_version = '>= 2.5'
15
15
  s.date = Time.now.strftime "%Y-%m-%d"
16
16
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
17
17
  s.require_paths = ["lib"]
@@ -19,9 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.bindir = "exe"
20
20
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
 
22
- s.add_development_dependency "bundler", "~> 1.8"
23
- s.add_development_dependency "rake", "~> 10.0"
24
- s.add_dependency 'activesupport', "~> 4.2"
25
- s.add_dependency 'rest-client', "~> 2.0"
22
+ s.add_development_dependency "bundler"
23
+ s.add_development_dependency "rake"
24
+ s.add_dependency 'activesupport'#, "~> 4.2"
25
+ s.add_dependency 'activemodel'#, "~> 4.2"
26
+ s.add_dependency 'rest-client'
27
+ s.add_dependency 'pond'
26
28
 
27
29
  end
Binary file
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+ ## loads the active-orient environment
3
+ ## and starts an interactive shell
4
+ ##
5
+ ## Parameter:
6
+ ## production (p)
7
+ ## development (d) [default]
8
+ ## test (t)
9
+ require 'bundler/setup'
10
+ require 'yaml'
11
+ require 'logger'
12
+ require 'active-orient'
13
+ begin
14
+ config_file = File.expand_path('../../config/connect.yml', __FILE__)
15
+ connectyml = if File.exist?(config_file)
16
+ YAML.load_file( config_file )[:orientdb]
17
+ else
18
+ puts "config/connect.yml not found "
19
+ puts "using defaults"
20
+ { server: 'localhost', port: 2480,
21
+ database: { development: 'demodb',
22
+ production: 'hcn_data',
23
+ test: 'temp'},
24
+ admin: { user: 'root', pass: 'root' } }
25
+ end
26
+ rescue Psych::SyntaxError
27
+ puts "Please edit /config/connect.yml"
28
+ puts
29
+ puts "current settings:"
30
+ puts `cat ../config/connect.yml`
31
+ Kernel.exit
32
+ end
33
+ e= ARGV.present? ? ARGV.last.downcase : 'development'
34
+ env = if e =~ /^p/
35
+ :production
36
+ elsif e =~ /^t/
37
+ :test
38
+ else
39
+ :development
40
+ end
41
+ begin
42
+ ORD = ActiveOrient::Init.connect database: connectyml[:database][env].to_s,
43
+ user: connectyml[:admin][:user].to_s,
44
+ password: connectyml[:admin][:pass].to_s,
45
+ server: connectyml[:server].to_s
46
+ ActiveOrient::Base.logger.level = Logger::INFO
47
+ ## example for namespace support, then set »keep_models_without_file« temporary to »false«
48
+ # module HH; end
49
+ # ActiveOrient::Init.define_namespace { HH }
50
+ ActiveOrient::Model.keep_models_without_file = true
51
+ ActiveOrient::OrientDB.new model_dir: '../lib/model' , preallocate: true
52
+ rescue RestClient::Unauthorized
53
+ puts "Cannot connect to the server. Wrong credentials"
54
+ Kernel.exit
55
+ rescue Errno::ECONNREFUSED
56
+ puts "Database Server is not running on #{connectyml[:server]} "
57
+ Kernel.exit
58
+ end
59
+
60
+ class Array
61
+ # Method missing enables fancy stuff like
62
+ # Jahr[2000 .. 2005].monat(5..7).value
63
+ #
64
+ # its included only in the console, for inspection purposes
65
+
66
+ # def method_missing(method, *key)
67
+ # unless method == :to_hash || method == :to_str #|| method == :to_int
68
+ # return self.map{|x| x.public_send(method, *key)}
69
+ # end
70
+
71
+ # end
72
+ end # Array
73
+
74
+
75
+ puts "ORD points to the REST-Instance, Database: #{ActiveOrient.database}"
76
+ #puts "DB is the API-Instance of the database, DB.db gets the DB-Api-base " if RUBY_PLATFORM == 'java'
77
+
78
+ puts '-'* 45
79
+ ns= case ActiveOrient::Model.namespace
80
+ when Object
81
+ "No Prefix, just ClassName#CamelCase"
82
+ else
83
+ ActiveOrient::Model.namespace.to_s + "{ClassName.camelcase}"
84
+ end
85
+ puts "Namespace for model-classes : #{ns}"
86
+ puts "Present Classes (Hierarchy) "
87
+
88
+ puts ORD.class_hierarchy.to_yaml
89
+ puts ActiveOrient::show_classes
90
+
91
+ include OrientDB
92
+
93
+ require 'pry'
94
+ #require 'irb'
95
+ ARGV.clear
96
+ #IRB.start(__FILE__)
97
+ Pry.start(__FILE__)
@@ -0,0 +1,60 @@
1
+ Changelog
2
+ =========
3
+ 2020/11/27 : file: /lib/database_utils.rb
4
+ method: system_classes, OrientDB 3.1 compatibility
5
+ Added 'OSecurityPolicy' class to system-classes array
6
+
7
+
8
+ 2020/11/30 : file: /lib/model/the_class.rb
9
+ method: require_model_file
10
+ The method now accepts an array of directories to be loaded
11
+
12
+ Thus hierarchical class-structures are initialised properly.
13
+ It appeared that on reopening a base-class in a hierarchical structure
14
+ the contents were not read when accessing the child-classes.
15
+
16
+ The change is backward compatible, the method accepts single directories as well.
17
+
18
+ 2020/12/01 Ruby 2.7 (3.0) Compatibiltiy
19
+ file: /lib/init.rb ** Hash-notation as method parameter
20
+ file: /lib/model/the_record.rb
21
+
22
+ 2020/12/13 file /lib/other.rb
23
+ method: Array#to_orient
24
+ If all members of the array respond to `rid?` and any of them is a reference
25
+ to a database-record, put it without quotes into the serialized string.
26
+ This enables: where: { contract: ['#194:0','208:0'] } => .in[ contract in [194:0, 208:0] ]
27
+
28
+ 2020/12/14 file /lib/other.rb
29
+ method: Array#orient_flatten
30
+ The method flattens the Array and removes nil-values. The array itself is modified
31
+
32
+ 2020/12/16 file /lib/model/vertex.rb
33
+ method: detect_edges
34
+ If no informations about edges are present, reload the vertex
35
+
36
+ file /example/books.rb
37
+ updated together with the spec-file
38
+
39
+ 2020/12/17 file /lib/support/orient.rb
40
+ class: OrientSupport::Hash
41
+ method: merge (alias << )
42
+ calls super (Hash#merge) and stores the result in the database, reloads the record
43
+
44
+ method: remove
45
+ performs the database-operation and reloads the record
46
+
47
+ 2020/12/21 file /lib/rest/create.rb
48
+ method: create_record
49
+ Included the option: »silence«. If set, if a duplicate index-error is fired, the
50
+ original record is loaded instead of creating a new one.
51
+
52
+ file /lib/model/vertex.rb
53
+ method: create
54
+ Vertex.create uses »create_record« with »silence:true« to create records.
55
+
56
+ file /lib/orientquery.rb
57
+ class: OrientSupport::OrientQuery
58
+ method: execute
59
+ If the execution of a query was not successfull, nil is returned
60
+
@@ -1,23 +1,76 @@
1
+ #### sample boot file ####
2
+
3
+
4
+
1
5
  require 'bundler/setup'
2
6
  require 'yaml'
7
+ if RUBY_VERSION == 'java'
8
+ require 'orientdb'
9
+ end
10
+ require "active-orient"
3
11
  project_root = File.expand_path('../..', __FILE__)
4
- require "#{project_root}/lib/support.rb"
5
- require "#{project_root}/lib/base.rb"
6
- require "#{project_root}/lib/base_properties.rb"
7
-
8
- require "#{project_root}/lib/model.rb"
9
- require "#{project_root}/lib/orient.rb"
10
- require "#{project_root}/lib/rest.rb"
11
- #require "#{project_root}/lib/graph.rb"
12
-
13
- # require all the models and libraries
14
- libs= Dir.glob(File.join( project_root, "lib",'**', "*rb"))
15
- result = libs.reverse.collect { |file| [file, require( file )] }
16
-
17
- logger = Logger.new '/dev/stdout'
18
- #REST::Graph.logger = logger
19
- ActiveOrient::Model.logger = logger
20
- ActiveOrient::OrientDB.logger = logger
12
+ begin
13
+ connect_file = File.expand_path('../../config/connect.yml', __FILE__)
14
+ config_file = File.expand_path('../../config/config.yml', __FILE__)
15
+ connectyml = YAML.load_file( connect_file )[:orientdb][:admin] if connect_file.present?
16
+ configyml = YAML.load_file( config_file )[:active_orient] if config_file.present?
17
+ databaseyml = YAML.load_file( connect_file )[:orientdb][:database] if connect_file.present?
18
+ rescue Errno::ENOENT
19
+ puts "config/connectyml not present"
20
+ puts "Using defaults to connect database-server"
21
+ end
22
+
23
+ e= ARGV.present? ? ARGV.last.downcase : 'development'
24
+ env = if e =~ /^p/
25
+ :production
26
+ elsif e =~ /^t/
27
+ :test
28
+ else
29
+ :development
30
+ end
31
+ puts "Using #{env}-environment"
32
+
33
+ log_file = if File.exist?(config_file)
34
+ dev = YAML.load_file( connect_file )[:orientdb][:logger]
35
+ if dev.blank? || dev== 'stdout'
36
+ '/dev/stdout'
37
+ else
38
+ project_root+'/log/'+env+'.log'
39
+ end
40
+ end
41
+
42
+
43
+ logger = Logger.new(log_file)
44
+ logger.level = case env
45
+ when :production
46
+ Logger::ERROR
47
+ when :development
48
+ Logger::WARN
49
+ else
50
+ Logger::INFO
51
+ end
52
+ logger.formatter = proc do |severity, datetime, progname, msg|
53
+ "#{datetime.strftime("%d.%m.(%X)")}#{"%5s" % severity}->#{msg}\n"
54
+ end
55
+
56
+ ORD = ActiveOrient::Init.connect database: databaseyml[env],
57
+ user: connectyml[:user].to_s,
58
+ password: connectyml[:pass].to_s,
59
+ server: '172.28.50.25',
60
+ logger: logger
61
+
62
+
63
+
64
+ ActiveOrient::Model.keep_models_without_file = true
65
+ ActiveOrient::Init.define_namespace yml: configyml, namespace: @namespace
66
+ ActiveOrient::OrientDB.new preallocate: true,
67
+ model_dir: "#{project_root}/#{ configyml.present? ? configyml[:model_dir] : "model" }"
68
+
69
+ if RUBY_PLATFORM == 'java'
70
+ DB = ActiveOrient::API.new preallocate: false
71
+ else
72
+ DB = ORD
73
+ end
21
74
 
22
75
 
23
76
 
@@ -0,0 +1,10 @@
1
+ ---
2
+ :active_orient:
3
+ ## Namespace: Prefix of Model-Objects. :self -> ActiveOrient::Model::{name}
4
+ ## :object => No Prefix
5
+ ## :active_orient => ActiveOrient::{name}
6
+ :namespace: :object
7
+ ## model_dir: Path to model-files relative to the root of the application
8
+ ## ie. app/model or model
9
+ :model_dir: 'lib/model'
10
+
@@ -1,13 +1,18 @@
1
1
  ---
2
2
  :orientdb:
3
- :server: localhost
3
+ :server: 10.222.148.109
4
+ #:server: localhost
4
5
  :port: 2480
5
- :database: hc_database
6
+ :logger: stdout # 'file' or 'stdout'
7
+ :database:
8
+ :development: devel
9
+ :production: produc
10
+ :test: temp
6
11
  :admin:
7
- :user: hctw
8
- :pass: hc
12
+ :user: ***w
13
+ :pass: ***c
9
14
  :auth:
10
- :user: topo
11
- :pass: focus
15
+ :user: root
16
+ :pass: ****s
12
17
 
13
18
  # hfx: 101
@@ -5,74 +5,163 @@ There are several Books. And there is a Table with Keywords. These are our Verte
5
5
 
6
6
  The Keywords are associated to the books, this is realized via an Edge »has_content«
7
7
 
8
- This Example demonstrates how to build a query by using OrientSupport::OrientQuery
8
+ This Example demonstrates how create a simple graph:
9
+
10
+ Book --> HasContent --> KeyWord
11
+
12
+ and to query it dynamically using OrientSupport::OrientQuery
13
+
14
+ REQUIREMENT: Configurate config/connectyml (admin/user+pass)
15
+
16
+ There are 3 default search items provided. They are used if no parameter is given.
17
+ However, any parameter given is transmitted as serach-criteria, ie.
18
+ ruby books.rb Juli August
19
+ defines two search criteria.
20
+
9
21
  =end
22
+ require 'bundler/setup'
23
+ require 'yaml'
24
+ require 'logger'
25
+ require 'active-orient'
26
+
10
27
  class BooksExample
11
28
 
12
- def initialize db, rebuild: true
13
- if rebuild
14
- db.delete_class :book
15
- db.delete_class :keyword
16
- db.delete_class :has_content
17
- db.create_vertex_class :book
18
- db.create_vertex_class :keyword
19
- db.create_edge_class :has_content
20
- ActiveOrient::Model::Keyword.create_property( :item , type: :string, index: :unique )
21
- ActiveOrient::Model::Book.create_property( :title, type: :string, index: :unique )
22
- end
23
- end
24
-
25
-
26
- def read_samples
27
- fill_database = ->(sentence, this_book ) do
28
- sentence.split(' ').each do |x|
29
- this_word = Keyword.update_or_create where: { item: x }
30
- this_edge = HC.create_edge from: this_book, to: this_word if this_word.present?
31
- end
32
- end
33
- words = 'Die Geschäfte in der Industrie im wichtigen US-Bundesstaat New York sind im August so schlecht gelaufen wie seit mehr als sechs Jahren nicht mehr Der entsprechende Empire-State-Index fiel überraschend von plus Punkten im Juli auf minus 14,92 Zähler Dies teilte die New Yorker Notenbank Fed heut mit Bei Werten im positiven Bereich signalisiert das Barometer ein Wachstum Ökonomen hatten eigentlich mit einem Anstieg auf 5,0 Punkte gerechnet'
34
- this_book = Book.create title: 'first'
35
- fill_database[ words, this_book ]
36
-
37
- words2 = 'Das Bruttoinlandsprodukt BIP in Japan ist im zweiten Quartal mit einer aufs Jahr hochgerechneten Rate von Prozent geschrumpft Zu Jahresbeginn war die nach den USA und China drittgrößte Volkswirtschaft der Welt noch um Prozent gewachsen Der Schwächeanfall wird auch als Rückschlag für Ministerpräsident Shinzo Abe gewertet der das Land mit einem Mix aus billigem Geld und Konjunkturprogramm aus der Flaute bringen will Allerdings wirkte sich die heutige Veröffentlichung auf die Märkten nur wenig aus da Ökonomen mit einem schwächeren zweiten Quartal gerechnet hatten'
38
- this_book = Book.create title: 'second'
39
- fill_database[ words2, this_book ]
40
- end
41
-
42
- def display_books_with *desired_words
43
- query = OrientSupport::OrientQuery.new from: Keyword, projection: "expand(in('HasContent'))"
44
- q = OrientSupport::OrientQuery.new projection: 'expand( $z )'
45
-
46
- intersects = Array.new
47
- desired_words.each_with_index do | word, i |
48
- symbol = ( i+97 ).chr # convert 1 -> 'a'
49
- query.where = { item: word }
50
- q.let << { symbol => query }
51
- intersects << "$#{symbol}"
52
- end
53
- q.let << "$z = Intersect(#{intersects.join(', ')}) "
54
- puts "generated Query:"
55
- puts q.to_s
56
- result = Keyword.query_database q, set_from: false
57
- puts "found books: "
58
- puts result.map( &:title ).join("; ")
59
- puts " -- None -- " if result.empty?
60
- end
29
+ def initialize rebuild: true
30
+ if rebuild
31
+ print "\n === REBUILD === \n"
32
+ ## check wether the database tables exist. Then delete Database-Class and preallocated ruby-Object
33
+ di = database_instance = V.db
34
+ database_classes = [ :book, :keyword, :has_content ]
35
+ print " creating Book and Keyword as Vertex; HAS_CONTENT as Edge \n"
36
+ V.create_class :book, :keyword
37
+ E.create_class :has_content
38
+ print "\n === PROPERTY === \n"
39
+ Keyword.create_property :item, type: :string, index: :unique
40
+ Book.create_property :title, type: :string, index: :unique
41
+ print "\n === Unique Edges === \n"
42
+ HAS_CONTENT.uniq_index
43
+
44
+ Keyword.delete( all: true )
45
+ Book.delete :all => true
46
+ end
47
+ end
48
+
49
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
50
+ ################# read samples ##############
51
+ def read_samples
52
+ print "\n === READ SAMPLES === \n"
53
+ ## Lambda fill databasea
54
+ # Anaylse a sentence
55
+ # Split into words and upsert them to Word-Class.
56
+ # The Block is only performed, if a new Word is inserted.
57
+ fill_database = ->(sentence, this_book ) do
58
+
59
+ sentence.split(' ').map do | word |
60
+ this_book.assign vertex: Keyword.create( item: word ), via: HAS_CONTENT if Keyword.where( item: word ).empty?
61
+ end
62
+
63
+ end
64
+ ## Lambda end
65
+ words = 'Die Geschäfte in der Industrie im wichtigen US-Bundesstaat New York sind im August so schlecht gelaufen wie seit mehr als sechs Jahren nicht mehr Der entsprechende Empire-State-Index fiel überraschend von plus Punkten im Juli auf minus 14,92 Zähler Dies teilte die New Yorker Notenbank Fed heute mit. Bei Werten im positiven Bereich signalisiert das Barometer ein Wachstum Ökonomen hatten eigentlich mit einem Anstieg auf 5,0 Punkte gerechnet'
66
+ this_book = Book.create title: 'first'
67
+ fill_database[ words, this_book ]
68
+
69
+ words2 = 'Das Bruttoinlandsprodukt BIP in Japan ist im zweiten Quartal mit einer aufs Jahr hochgerechneten Rate von Prozent geschrumpft Zu Jahresbeginn war die nach den USA und China drittgrößte Volkswirtschaft der Welt noch um Prozent gewachsen Der Schwächeanfall wird auch als Rückschlag für Ministerpräsident Shinzo Abe gewertet der das Land mit einem Mix aus billigem Geld und Konjunkturprogramm aus der Flaute bringen will Allerdings wirkte sich die heutige Veröffentlichung auf die Märkten nur wenig aus da Ökonomen mit einem schwächeren zweiten Quartal gerechnet hatten'
70
+ this_book = Book.create title: 'second'
71
+ fill_database[ words2, this_book ]
72
+ puts "#{Keyword.count} keywords inserted into Database"
73
+ end
74
+
75
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
76
+ ################# display books ##############
77
+ def display_books_with *desired_words
78
+ ## Each serach criteria becomes a subquery
79
+ ## This is integrated into the main_query using 'let'.
80
+ ## Subquery: let ${a-y} = select expand(in('has_content')) from keyword where item = {search_word}
81
+ ## combine with intercect: $z = Intercect( $a ... $y )
82
+ ## Main Query is just
83
+ ## select expand( $z ) followed by all let-statements and finalized by "intercect"
84
+ #
85
+
86
+ # lambda to create subqueries
87
+ word_query = -> (arg) do
88
+ q= Keyword.query where: arg
89
+ q.nodes :in, via: HAS_CONTENT
90
+ end
91
+
92
+ ## We just create "select expand($z)"
93
+ main_query = OrientSupport::OrientQuery.new
94
+ main_query.expand( '$z' )
95
+
96
+
97
+ print("\n === display_books_with » #{ desired_words.join "," } « === \n")
98
+
99
+ intersects = Array.new
100
+ ## Now, add subqueries to the main-query
101
+ desired_words.each_with_index do | word, i |
102
+ symbol = ( i+97 ).chr # convert 1 -> 'a', 2 -> 'b' ...
103
+ main_query.let symbol => word_query[ item: word ]
104
+ intersects << "$#{symbol}"
105
+ end
106
+ ## Finally add the intersects statement
107
+ main_query.let "$z = Intersect(#{intersects.join(', ')}) "
108
+ puts "generated Query:"
109
+ puts main_query.to_s
110
+ puts "\n\n\n"
111
+ result = main_query.execute
112
+ puts '-' * 23
113
+ puts "found books: "
114
+ puts result.map( &:title ).uniq.join("; ")
115
+ if result.empty?
116
+ puts " -- None -- "
117
+ puts " try » ruby books.rb japan flaute « for a positive search in one of the two sentences"
118
+ else
119
+ puts '-_' * 23
120
+ puts "that's it folks"
121
+ end
122
+ end
61
123
  end
62
124
 
63
- if $0 == __FILE__
64
-
65
- require '../config/boot'
66
-
67
- ActiveOrient::OrientDB.default_server = { user: 'hctw', password: 'hc' }
68
- ActiveOrient::OrientDB.logger.level = Logger::WARN
69
- r = ActiveOrient::OrientDB.new database: 'BookTest'
70
- b= BooksExample.new r, rebuild: true
71
-
72
- Book = r.open_class :book
73
- Keyword = r.open_class :keyword
74
- HC = r.open_class :has_content
75
-
76
- b.read_samples if Keyword.count.zero?
77
- b.display_books_with 'Land', 'Quartal'
125
+ if $0 == __FILE__
126
+ config_file = File.expand_path('../../config/connect.yml', __FILE__)
127
+ connectyml = if File.exist?(config_file)
128
+ YAML.load_file( config_file )[:orientdb]
129
+ else
130
+ puts "config/connect.yml not found "
131
+ puts "using defaults"
132
+ { server: 'localhost', port: 2480,
133
+ database: { development: 'temp' },
134
+ admin: { user: 'root', pass: 'root' } }
135
+ end
136
+
137
+ begin
138
+ ActiveOrient::Init.connect database: connectyml[:database][:development].to_s,
139
+ user: connectyml[:admin][:user].to_s,
140
+ password: connectyml[:admin][:pass].to_s,
141
+ server: connectyml[:server].to_s
142
+
143
+ ActiveOrient::Base.logger.level = Logger::INFO
144
+ ActiveOrient::Model.keep_models_without_file = true
145
+ ActiveOrient::OrientDB.new model_dir: 'lib/model'
146
+ rescue RestClient::Unauthorized
147
+ puts "Cannot connect to the server. Wrong credentials"
148
+ Kernel.exit
149
+ rescue Errno::ECONNREFUSED
150
+ puts "Database Server is not running on #{connectyml[:server]} "
151
+ Kernel.exit
152
+ end
153
+
154
+
155
+ search_items = ARGV.empty? ? ['China', 'aus', 'Flaute'] : ARGV
156
+ ARGV = [ 'd' ] # development-mode
157
+
158
+ # search_items = ARGV.empty? ? ['China', 'aus', 'Flaute'] : ARGV
159
+ b = BooksExample.new rebuild: true
160
+
161
+ # ORD.create_vertex_class "Book", "Keyword"
162
+ # ORD.create_edge_class 'has_content'
163
+
164
+ b.read_samples if Keyword.count.zero?
165
+ b.display_books_with *search_items
166
+
78
167
  end