baza 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +157 -0
  3. data/Gemfile +11 -9
  4. data/Gemfile.lock +41 -9
  5. data/README.md +1 -1
  6. data/Rakefile +19 -16
  7. data/VERSION +1 -1
  8. data/baza.gemspec +31 -7
  9. data/config/best_project_practice_rubocop.yml +2 -0
  10. data/config/best_project_practice_rubocop_todo.yml +157 -0
  11. data/lib/baza/base_sql_driver.rb +79 -20
  12. data/lib/baza/cloner.rb +2 -2
  13. data/lib/baza/column.rb +6 -0
  14. data/lib/baza/database.rb +33 -0
  15. data/lib/baza/database_model.rb +26 -0
  16. data/lib/baza/database_model_functionality.rb +10 -0
  17. data/lib/baza/database_model_name.rb +16 -0
  18. data/lib/baza/db.rb +210 -413
  19. data/lib/baza/dbtime.rb +20 -20
  20. data/lib/baza/driver.rb +3 -3
  21. data/lib/baza/drivers/active_record/columns.rb +1 -1
  22. data/lib/baza/drivers/active_record/indexes.rb +1 -1
  23. data/lib/baza/drivers/active_record/result.rb +3 -5
  24. data/lib/baza/drivers/active_record/tables.rb +2 -2
  25. data/lib/baza/drivers/active_record.rb +30 -16
  26. data/lib/baza/drivers/mysql/column.rb +51 -48
  27. data/lib/baza/drivers/mysql/columns.rb +8 -8
  28. data/lib/baza/drivers/mysql/database.rb +28 -0
  29. data/lib/baza/drivers/mysql/databases.rb +35 -0
  30. data/lib/baza/drivers/mysql/index.rb +32 -22
  31. data/lib/baza/drivers/mysql/result.rb +24 -24
  32. data/lib/baza/drivers/mysql/sqlspecs.rb +1 -1
  33. data/lib/baza/drivers/mysql/table.rb +80 -91
  34. data/lib/baza/drivers/mysql/tables.rb +30 -32
  35. data/lib/baza/drivers/mysql/unbuffered_result.rb +5 -5
  36. data/lib/baza/drivers/mysql.rb +127 -220
  37. data/lib/baza/drivers/mysql2/database.rb +2 -0
  38. data/lib/baza/drivers/mysql2/databases.rb +2 -0
  39. data/lib/baza/drivers/mysql2/result.rb +3 -5
  40. data/lib/baza/drivers/mysql2.rb +21 -106
  41. data/lib/baza/drivers/mysql_java/database.rb +2 -0
  42. data/lib/baza/drivers/mysql_java/databases.rb +2 -0
  43. data/lib/baza/drivers/mysql_java.rb +16 -12
  44. data/lib/baza/drivers/sqlite3/column.rb +33 -33
  45. data/lib/baza/drivers/sqlite3/columns.rb +6 -6
  46. data/lib/baza/drivers/sqlite3/database.rb +2 -0
  47. data/lib/baza/drivers/sqlite3/databases.rb +25 -0
  48. data/lib/baza/drivers/sqlite3/index.rb +20 -6
  49. data/lib/baza/drivers/sqlite3/result.rb +16 -17
  50. data/lib/baza/drivers/sqlite3/sqlspecs.rb +1 -1
  51. data/lib/baza/drivers/sqlite3/table.rb +99 -100
  52. data/lib/baza/drivers/sqlite3/tables.rb +30 -23
  53. data/lib/baza/drivers/sqlite3/unbuffered_result.rb +2 -2
  54. data/lib/baza/drivers/sqlite3.rb +27 -14
  55. data/lib/baza/drivers/sqlite3_java/database.rb +2 -0
  56. data/lib/baza/drivers/sqlite3_java/unbuffered_result.rb +2 -2
  57. data/lib/baza/drivers/sqlite3_java.rb +12 -10
  58. data/lib/baza/drivers/sqlite3_rhodes.rb +9 -7
  59. data/lib/baza/dump.rb +55 -55
  60. data/lib/baza/errors.rb +5 -0
  61. data/lib/baza/idquery.rb +25 -25
  62. data/lib/baza/index.rb +6 -0
  63. data/lib/baza/jdbc_driver.rb +6 -8
  64. data/lib/baza/jdbc_result.rb +1 -1
  65. data/lib/baza/model.rb +299 -309
  66. data/lib/baza/model_custom.rb +74 -72
  67. data/lib/baza/model_handler.rb +244 -255
  68. data/lib/baza/model_handler_sqlhelper.rb +122 -132
  69. data/lib/baza/mysql_base_driver.rb +112 -0
  70. data/lib/baza/query_buffer.rb +23 -23
  71. data/lib/baza/result_base.rb +2 -2
  72. data/lib/baza/revision.rb +67 -67
  73. data/lib/baza/row.rb +82 -84
  74. data/lib/baza/sqlspecs.rb +1 -1
  75. data/lib/baza/table.rb +31 -0
  76. data/lib/baza.rb +43 -10
  77. data/shippable.yml +1 -0
  78. data/spec/cloner_spec.rb +4 -4
  79. data/spec/drivers/active_record_mysql2_spec.rb +3 -3
  80. data/spec/drivers/active_record_mysql_spec.rb +2 -2
  81. data/spec/drivers/active_record_sqlite3_spec.rb +2 -2
  82. data/spec/drivers/mysql2_spec.rb +1 -0
  83. data/spec/drivers/mysql_spec.rb +1 -0
  84. data/spec/drivers/sqlite3_spec.rb +4 -5
  85. data/spec/info_active_record_example.rb +4 -6
  86. data/spec/info_active_record_mysql.rb +6 -7
  87. data/spec/info_active_record_mysql2.rb +2 -4
  88. data/spec/info_active_record_mysql2_shippable.rb +2 -4
  89. data/spec/info_active_record_mysql_shippable.rb +2 -4
  90. data/spec/info_active_record_sqlite3.rb +5 -6
  91. data/spec/info_mysql2_example.rb +1 -1
  92. data/spec/info_mysql2_shippable.rb +1 -1
  93. data/spec/info_mysql_example.rb +1 -1
  94. data/spec/info_mysql_shippable.rb +1 -1
  95. data/spec/info_sqlite3.rb +4 -3
  96. data/spec/model_handler_spec.rb +102 -115
  97. data/spec/spec_helper.rb +5 -5
  98. data/spec/support/driver_collection.rb +98 -95
  99. data/spec/support/driver_columns_collection.rb +18 -22
  100. data/spec/support/driver_databases_collection.rb +29 -0
  101. data/spec/support/driver_indexes_collection.rb +7 -6
  102. data/spec/support/driver_tables_collection.rb +38 -26
  103. metadata +49 -3
@@ -1,23 +1,23 @@
1
1
  require "#{$knjpath}event_handler"
2
2
 
3
3
  class Baza::ModelCustom
4
- #Used to determine if this is a knj-datarow-object.
4
+ # Used to determine if this is a knj-datarow-object.
5
5
  def is_knj?
6
- return true
6
+ true
7
7
  end
8
-
9
- #Initializes variables on the class from objects.
8
+
9
+ # Initializes variables on the class from objects.
10
10
  def self.datarow_init(d)
11
11
  @@ob = d.ob
12
12
  @@db = d.db
13
13
  end
14
-
14
+
15
15
  def self.has_one(arr)
16
16
  arr.each do |val|
17
17
  methodname = nil
18
18
  colname = nil
19
19
  classname = nil
20
-
20
+
21
21
  if val.is_a?(Symbol)
22
22
  classname = val
23
23
  methodname = val.to_s.downcase.to_sym
@@ -25,129 +25,131 @@ class Baza::ModelCustom
25
25
  elsif val.is_a?(Array)
26
26
  classname, colname, methodname = *val
27
27
  elsif val.is_a?(Hash)
28
- classname, colname, methodname = val[:class], val[:col], val[:method]
28
+ classname = val[:class]
29
+ colname = val[:col]
30
+ methodname = val[:method]
29
31
  else
30
32
  raise "Unknown argument-type: '#{arr.class.name}'."
31
33
  end
32
-
33
- methodname = classname.to_s.downcase if !methodname
34
- colname = "#{classname.to_s.downcase}_id".to_sym if !colname
35
-
34
+
35
+ methodname = classname.to_s.downcase unless methodname
36
+ colname = "#{classname.to_s.downcase}_id".to_sym unless colname
37
+
36
38
  define_method(methodname) do
37
39
  return @@ob.get_try(self, colname, classname)
38
40
  end
39
-
40
- methodname_html = "#{methodname.to_s}_html".to_sym
41
+
42
+ methodname_html = "#{methodname}_html".to_sym
41
43
  define_method(methodname_html) do |*args|
42
- obj = self.send(methodname)
43
- return @@ob.events.call(:no_html, classname) if !obj
44
-
45
- raise "Class '#{classname}' does not have a 'html'-method." if !obj.respond_to?(:html)
44
+ obj = send(methodname)
45
+ return @@ob.events.call(:no_html, classname) unless obj
46
+
47
+ raise "Class '#{classname}' does not have a 'html'-method." unless obj.respond_to?(:html)
46
48
  return obj.html(*args)
47
49
  end
48
50
  end
49
51
  end
50
-
52
+
51
53
  def self.events
52
- if !@events
54
+ unless @events
53
55
  @events = Knj::Event_handler.new
54
- @events.add_event(:name => :add, :connections_max => 1)
55
- @events.add_event(:name => :update, :connections_max => 1)
56
- @events.add_event(:name => :data_from_id, :connections_max => 1)
57
- @events.add_event(:name => :delete, :connections_max => 1)
56
+ @events.add_event(name: :add, connections_max: 1)
57
+ @events.add_event(name: :update, connections_max: 1)
58
+ @events.add_event(name: :data_from_id, connections_max: 1)
59
+ @events.add_event(name: :delete, connections_max: 1)
58
60
  end
59
-
60
- return @events
61
+
62
+ @events
61
63
  end
62
-
64
+
63
65
  def self.classname
64
- self.name.split("::").last
66
+ name.split("::").last
65
67
  end
66
-
68
+
67
69
  def self.add(d)
68
- return @events.call(:add, d)
70
+ @events.call(:add, d)
69
71
  end
70
-
72
+
71
73
  def self.table
72
- return self.name.split("::").last
74
+ name.split("::").last
73
75
  end
74
-
76
+
75
77
  def deleted?
76
- return true if !@data
77
- return false
78
+ return true unless @data
79
+ false
78
80
  end
79
-
81
+
80
82
  def table
81
- return self.class.table
83
+ self.class.table
82
84
  end
83
-
84
- def initialize(data, args)
85
+
86
+ def initialize(data, _args)
85
87
  if data.is_a?(Hash)
86
88
  @data = Knj::ArrayExt.hash_sym(data)
87
- @id = self.id
89
+ @id = id
88
90
  else
89
91
  @id = data
90
- self.reload
92
+ reload
91
93
  end
92
94
  end
93
-
95
+
94
96
  def reload
95
- raise "No 'data_from_id'-event connected to class." if !self.class.events.connected?(:data_from_id)
96
- data = self.class.events.call(:data_from_id, Knj::Hash_methods.new(:id => @id))
97
- raise "No data was received from the event: 'data_from_id'." if !data
98
- raise "Data expected to be a hash but wasnt: '#{data.class.name}'." if !data.is_a?(Hash)
97
+ raise "No 'data_from_id'-event connected to class." unless self.class.events.connected?(:data_from_id)
98
+ data = self.class.events.call(:data_from_id, Knj::Hash_methods.new(id: @id))
99
+ raise "No data was received from the event: 'data_from_id'." unless data
100
+ raise "Data expected to be a hash but wasnt: '#{data.class.name}'." unless data.is_a?(Hash)
99
101
  @data = Knj::ArrayExt.hash_sym(data)
100
102
  end
101
-
103
+
102
104
  def update(data)
103
- ret = self.class.events.call(:update, Knj::Hash_methods.new(:object => self, :data => data))
104
- self.reload
105
- return ret
105
+ ret = self.class.events.call(:update, Knj::Hash_methods.new(object: self, data: data))
106
+ reload
107
+ ret
106
108
  end
107
-
108
- #Returns a key from the hash that this object is holding or raises an error if it doesnt exist.
109
+
110
+ # Returns a key from the hash that this object is holding or raises an error if it doesnt exist.
109
111
  def [](key)
110
- raise "No data spawned on object." if !@data
111
- raise "No such key: '#{key}'. Available keys are: '#{@data.keys.sort.join(", ")}'." if !@data.key?(key)
112
- return @data[key]
112
+ raise "No data spawned on object." unless @data
113
+ raise "No such key: '#{key}'. Available keys are: '#{@data.keys.sort.join(", ")}'." unless @data.key?(key)
114
+ @data[key]
113
115
  end
114
-
115
- #Returns the ID of the object.
116
+
117
+ # Returns the ID of the object.
116
118
  def id
117
- return self[:id]
119
+ self[:id]
118
120
  end
119
-
120
- #Returns the name of the object, which can be taken from various data or various defined methods.
121
+
122
+ # Returns the name of the object, which can be taken from various data or various defined methods.
121
123
  def name
122
124
  if @data.key?(:title)
123
125
  return @data[:title]
124
126
  elsif @data.key?(:name)
125
127
  return @data[:name]
126
128
  end
127
-
129
+
128
130
  obj_methods = self.class.instance_methods(false)
129
131
  [:name, :title].each do |method_name|
130
- return self.method(method_name).call if obj_methods.index(method_name)
132
+ return method(method_name).call if obj_methods.index(method_name)
131
133
  end
132
-
134
+
133
135
  raise "Couldnt figure out the title/name of the object on class #{self.class.name}."
134
136
  end
135
-
136
- alias :title :name
137
-
137
+
138
+ alias_method :title, :name
139
+
138
140
  def delete
139
- self.class.events.call(:delete, Knj::Hash_methods.new(:object => self))
141
+ self.class.events.call(:delete, Knj::Hash_methods.new(object: self))
140
142
  end
141
-
143
+
142
144
  def destroy
143
145
  @data = nil
144
146
  end
145
-
147
+
146
148
  def each(&args)
147
- return @data.each(&args)
149
+ @data.each(&args)
148
150
  end
149
-
151
+
150
152
  def to_hash
151
- return @data.clone
153
+ @data.clone
152
154
  end
153
- end
155
+ end