knjrbfw 0.0.70 → 0.0.71
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/knjrbfw.gemspec +1 -2
- data/lib/knj/datarow.rb +96 -79
- data/lib/knj/knjdb/libknjdb.rb +7 -1
- metadata +2 -3
- data/lib/knj/jruby/sqlitejdbc-v056.jar +0 -0
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.71
|
data/knjrbfw.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{knjrbfw}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.71"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kasper Johansen"]
|
@@ -158,7 +158,6 @@ Gem::Specification.new do |s|
|
|
158
158
|
"lib/knj/jruby-gtk2/treeview.rb",
|
159
159
|
"lib/knj/jruby-gtk2/vbox.rb",
|
160
160
|
"lib/knj/jruby-gtk2/window.rb",
|
161
|
-
"lib/knj/jruby/sqlitejdbc-v056.jar",
|
162
161
|
"lib/knj/jruby_compiler.rb",
|
163
162
|
"lib/knj/knj.rb",
|
164
163
|
"lib/knj/knj_controller.rb",
|
data/lib/knj/datarow.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#This class helps create models in a framework with Knj::Db and Knj::Objects.
|
2
2
|
#===Examples
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
3
|
+
# db = Knj::Db.new(:type => "sqlite3", :path => "somepath.sqlite3")
|
4
|
+
# ob = Knj::Objects.new(:db => db, :datarow => true, :path => "path_of_model_class_files")
|
5
|
+
# user = ob.get(:User, 1) #=> <Models::User> that extends <Knj::Datarow>
|
6
6
|
class Knj::Datarow
|
7
7
|
@@refs = {}
|
8
8
|
|
@@ -29,11 +29,11 @@ class Knj::Datarow
|
|
29
29
|
#This is used by 'Knj::Objects' to find out what data is required for this class. Returns the array that tells about required data.
|
30
30
|
#===Examples
|
31
31
|
#When adding a new user, this can fail if the ':group_id' is not given, or the ':group_id' doesnt refer to a valid group-row in the db.
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
32
|
+
# class Models::User < Knj::Datarow
|
33
|
+
# has_one [
|
34
|
+
# {:class => :Group, :col => :group_id, :method => :group, :required => true}
|
35
|
+
# ]
|
36
|
+
# end
|
37
37
|
def self.required_data
|
38
38
|
@required_data = [] if !@required_data
|
39
39
|
return @required_data
|
@@ -42,11 +42,11 @@ class Knj::Datarow
|
|
42
42
|
#This is used by 'Knj::Objects' to find out what other objects this class depends on. Returns the array that tells about depending data.
|
43
43
|
#===Examples
|
44
44
|
#This will tell Knj::Objects that files depends on users. It can prevent the user from being deleted, if any files depend on it.
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
45
|
+
# class Models::User < Knj::Datarow
|
46
|
+
# has_many [
|
47
|
+
# {:class => :File, :col => :user_id, :method => :files, :depends => true}
|
48
|
+
# ]
|
49
|
+
# end
|
50
50
|
def self.depending_data
|
51
51
|
return @depending_data
|
52
52
|
end
|
@@ -60,11 +60,11 @@ class Knj::Datarow
|
|
60
60
|
#This is used by 'Knj::Objects' to find out which other objects should be deleted when an object of this class is deleted automatically. Returns the array that tells about autodelete data.
|
61
61
|
#===Examples
|
62
62
|
#This will trigger Knj::Objects to automatically delete all the users pictures, when deleting the current user.
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
63
|
+
# class Models::User < Knj::Datarow
|
64
|
+
# has_many [
|
65
|
+
# {:class => :Picture, :col => :user_id, :method => :pictures, :autodelete => true}
|
66
|
+
# ]
|
67
|
+
# end
|
68
68
|
def self.autodelete_data
|
69
69
|
return @autodelete_data
|
70
70
|
end
|
@@ -76,15 +76,15 @@ class Knj::Datarow
|
|
76
76
|
|
77
77
|
#This helps various parts of the framework determine if this is a datarow class without requiring it.
|
78
78
|
#===Examples
|
79
|
-
#
|
79
|
+
# print "This is a knj-object." if obj.respond_to?("is_knj?")
|
80
80
|
def is_knj?
|
81
81
|
return true
|
82
82
|
end
|
83
83
|
|
84
84
|
#This tests if a certain string is a date-null-stamp.
|
85
85
|
#===Examples
|
86
|
-
#
|
87
|
-
#
|
86
|
+
# time_str = dbrow[:date]
|
87
|
+
# print "No valid date on the row." if Knj::Datarow.is_nullstamp?(time_str)
|
88
88
|
def self.is_nullstamp?(stamp)
|
89
89
|
return true if !stamp or stamp == "0000-00-00 00:00:00" or stamp == "0000-00-00"
|
90
90
|
return false
|
@@ -93,12 +93,12 @@ class Knj::Datarow
|
|
93
93
|
#This is used to define datarows that this object can have a lot of.
|
94
94
|
#===Examples
|
95
95
|
#This will define the method "pictures" on 'Models::User' that will return all pictures for the users and take possible Objects-sql-arguments. It will also enabling joining pictures when doing Objects-sql-lookups.
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
96
|
+
# class Models::User < Knj::Datarow
|
97
|
+
# has_many [
|
98
|
+
# [:Picture, :user_id, :pictures],
|
99
|
+
# {:class => :File, :col => :user_id, :method => :files}
|
100
|
+
# ]
|
101
|
+
# end
|
102
102
|
def self.has_many(arr)
|
103
103
|
arr.each do |val|
|
104
104
|
if val.is_a?(Array)
|
@@ -199,15 +199,15 @@ class Knj::Datarow
|
|
199
199
|
|
200
200
|
#This define is this object has one element of another datarow-class. It define various methods and joins based on that.
|
201
201
|
#===Examples
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
202
|
+
# class Models::User < Knj::Datarow
|
203
|
+
# has_one [
|
204
|
+
# #Defines the method 'group', which returns a 'Group'-object by the column 'group_id'.
|
205
|
+
# :Group,
|
206
|
+
#
|
207
|
+
# #Defines the method 'type', which returns a 'Type'-object by the column 'type_id'.
|
208
|
+
# {:class => :Type, :col => :type_id, :method => :type}
|
209
|
+
# ]
|
210
|
+
# end
|
211
211
|
def self.has_one(arr)
|
212
212
|
arr.each do |val|
|
213
213
|
methodname = nil
|
@@ -284,15 +284,15 @@ class Knj::Datarow
|
|
284
284
|
|
285
285
|
#This method initializes joins, sets methods to update translations and makes the translations automatically be deleted when the object is deleted.
|
286
286
|
#===Examples
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
293
|
-
#
|
294
|
-
#
|
295
|
-
#
|
287
|
+
# class Models::Article < Knj::Datarow
|
288
|
+
# #Defines methods such as: 'title', 'title=', 'content', 'content='. When used with Knjappserver these methods will change what they return and set based on the current language of the session.
|
289
|
+
# has_translation [:title, :content]
|
290
|
+
# end
|
291
|
+
#
|
292
|
+
# article = ob.get(:Article, 1)
|
293
|
+
# print "The title in the current language is: '#{article.title}'."
|
294
|
+
#
|
295
|
+
# article.title = 'Title in english if the language is english'
|
296
296
|
def self.has_translation(arr)
|
297
297
|
@translations = [] if !@translations
|
298
298
|
|
@@ -421,12 +421,12 @@ class Knj::Datarow
|
|
421
421
|
|
422
422
|
#This method helps returning objects and supports various arguments. It should be called by Object#list.
|
423
423
|
#===Examples
|
424
|
-
#
|
425
|
-
#
|
426
|
-
#
|
427
|
-
#
|
428
|
-
#
|
429
|
-
#
|
424
|
+
# ob.list(:User, {"username_lower" => "john doe"}) do |user|
|
425
|
+
# print user.id
|
426
|
+
# end
|
427
|
+
#
|
428
|
+
# array = ob.list(:User, {"id" => 1})
|
429
|
+
# print array.length
|
430
430
|
def self.list(d, &block)
|
431
431
|
args = d.args
|
432
432
|
|
@@ -526,16 +526,16 @@ class Knj::Datarow
|
|
526
526
|
|
527
527
|
#Returns the table-name that should be used for this datarow.
|
528
528
|
#===Examples
|
529
|
-
#
|
530
|
-
#
|
531
|
-
#
|
529
|
+
# db.query("SELECT * FROM `#{Models::User.table}` WHERE username = 'John Doe'") do |data|
|
530
|
+
# print data[:id]
|
531
|
+
# end
|
532
532
|
def self.table
|
533
533
|
return @table
|
534
534
|
end
|
535
535
|
|
536
536
|
#This can be used to manually set the table-name. Useful when meta-programming classes that extends the datarow-class.
|
537
537
|
#===Examples
|
538
|
-
#
|
538
|
+
# Models::User.table = "prefix_User"
|
539
539
|
def self.table=(newtable)
|
540
540
|
@table = newtable
|
541
541
|
@columns_sqlhelper_args[:table] = @table if @columns_sqlhelper_args.is_a?(Hash)
|
@@ -543,17 +543,17 @@ class Knj::Datarow
|
|
543
543
|
|
544
544
|
#Returns the class-name but without having to call the class-table-method. To make code look shorter.
|
545
545
|
#===Examples
|
546
|
-
#
|
547
|
-
#
|
548
|
-
#
|
549
|
-
#
|
546
|
+
# user = ob.get_by(:User, {:username => 'John Doe'})
|
547
|
+
# db.query("SELECT * FROM `#{user.table}` WHERE username = 'John Doe'") do |data|
|
548
|
+
# print data[:id]
|
549
|
+
# end
|
550
550
|
def table
|
551
551
|
return self.class.table
|
552
552
|
end
|
553
553
|
|
554
554
|
#Initializes the object. This should be called from 'Knj::Objects' and not manually.
|
555
555
|
#===Examples
|
556
|
-
#
|
556
|
+
# user = ob.get(:User, 3)
|
557
557
|
def initialize(data, args = nil)
|
558
558
|
if data.is_a?(Hash) and data.key?(:id)
|
559
559
|
@data = data
|
@@ -586,9 +586,9 @@ class Knj::Datarow
|
|
586
586
|
|
587
587
|
#Reloads the data from the database.
|
588
588
|
#===Examples
|
589
|
-
#
|
590
|
-
#
|
591
|
-
#
|
589
|
+
# old_username = user[:username]
|
590
|
+
# user.reload
|
591
|
+
# print "The username changed in the database!" if user[:username] != old_username
|
592
592
|
def reload
|
593
593
|
@data = self.class.db.single(self.class.table, {:id => @id})
|
594
594
|
raise Errno::ENOENT, "Could not find any data for the object with ID: '#{@id}' in the table '#{self.class.table}'." if !@data
|
@@ -597,8 +597,8 @@ class Knj::Datarow
|
|
597
597
|
|
598
598
|
#Tells the object that it should reloads its data because it has changed. It wont reload before it is required though, which may save you a couple of SQL-calls.
|
599
599
|
#===Examples
|
600
|
-
#
|
601
|
-
#
|
600
|
+
# obj = _ob.get(:User, 5)
|
601
|
+
# obj.should_reload
|
602
602
|
def should_reload
|
603
603
|
@should_reload = true
|
604
604
|
@data = nil
|
@@ -612,7 +612,7 @@ class Knj::Datarow
|
|
612
612
|
|
613
613
|
#Writes/updates new data for the object.
|
614
614
|
#===Examples
|
615
|
-
#
|
615
|
+
# user.update(:username => 'New username', :date_changed => Time.now)
|
616
616
|
def update(newdata)
|
617
617
|
self.class.db.update(self.class.table, newdata, {:id => @id})
|
618
618
|
self.should_reload
|
@@ -628,7 +628,7 @@ class Knj::Datarow
|
|
628
628
|
|
629
629
|
#Returns true if that key exists on the object.
|
630
630
|
#===Examples
|
631
|
-
#
|
631
|
+
# print "Looks like the user has a name." if user.key?(:name)
|
632
632
|
def key?(key)
|
633
633
|
self.reload if @should_reload
|
634
634
|
return @data.key?(key.to_sym)
|
@@ -637,7 +637,7 @@ class Knj::Datarow
|
|
637
637
|
|
638
638
|
#Returns true if the object has been deleted.
|
639
639
|
#===Examples
|
640
|
-
#
|
640
|
+
# print "That user is deleted." if user.deleted?
|
641
641
|
def deleted?
|
642
642
|
return true if !@data and !@id
|
643
643
|
return false
|
@@ -661,9 +661,9 @@ class Knj::Datarow
|
|
661
661
|
end
|
662
662
|
|
663
663
|
#Returns a specific data from the object by key.
|
664
|
-
#
|
665
|
-
#
|
666
|
-
#
|
664
|
+
# print "Username: #{user[:username]}\n"
|
665
|
+
# print "ID: #{user[:id]}\n"
|
666
|
+
# print "ID again: #{user.id}\n"
|
667
667
|
def [](key)
|
668
668
|
raise "Key was not a symbol: '#{key.class.name}'." if !key.is_a?(Symbol)
|
669
669
|
return @id if !@data and key == :id and @id
|
@@ -674,8 +674,8 @@ class Knj::Datarow
|
|
674
674
|
end
|
675
675
|
|
676
676
|
#Writes/updates a keys value on the object.
|
677
|
-
#
|
678
|
-
#
|
677
|
+
# user = ob.get_by(:User, {"username" => "John Doe"})
|
678
|
+
# user[:username] = 'New username'
|
679
679
|
def []=(key, value)
|
680
680
|
self.update(key.to_sym => value)
|
681
681
|
self.should_reload
|
@@ -723,15 +723,32 @@ class Knj::Datarow
|
|
723
723
|
|
724
724
|
#Loops through the data on the object.
|
725
725
|
#===Examples
|
726
|
-
#
|
727
|
-
#
|
728
|
-
#
|
729
|
-
#
|
726
|
+
# user = ob.get(:User, 1)
|
727
|
+
# user.each do |key, val|
|
728
|
+
# print "#{key}: #{val}\n" #=> username: John Doe
|
729
|
+
# end
|
730
730
|
def each(*args, &block)
|
731
731
|
self.reload if @should_reload
|
732
732
|
return @data.each(*args, &block)
|
733
733
|
end
|
734
734
|
|
735
|
+
#Returns a default-URL to show the object.
|
736
|
+
def url
|
737
|
+
cname = self.class.classname.to_s.downcase
|
738
|
+
return "?show=#{cname}_show&#{cname}_id=#{self.id}"
|
739
|
+
end
|
740
|
+
|
741
|
+
#Returns the URL for editting the object.
|
742
|
+
def url_edit
|
743
|
+
cname = self.class.classname.to_s.downcase
|
744
|
+
return "?show=#{cname}_edit&#{cname}_id=#{self.id}"
|
745
|
+
end
|
746
|
+
|
747
|
+
#Returns the HTML for making a link to the object.
|
748
|
+
def html
|
749
|
+
return "<a href=\"#{Knj::Web.ahref_parse(self.url)}\">#{self.name_html}</a>"
|
750
|
+
end
|
751
|
+
|
735
752
|
private
|
736
753
|
|
737
754
|
#Various methods to define methods based on the columns for the datarow.
|
@@ -803,8 +820,8 @@ class Knj::Datarow
|
|
803
820
|
|
804
821
|
#Define methods to look up objects directly.
|
805
822
|
#===Examples
|
806
|
-
#
|
807
|
-
#
|
823
|
+
# user = Models::User.by_username('John Doe')
|
824
|
+
# print user.id
|
808
825
|
def self.define_text_methods(args)
|
809
826
|
method_name = "by_#{args[:col_name]}".to_sym
|
810
827
|
if args[:inst_methods].index(method_name) == nil and RUBY_VERSION.to_s.slice(0, 3) != "1.8"
|
data/lib/knj/knjdb/libknjdb.rb
CHANGED
@@ -244,7 +244,13 @@ class Knj::Db
|
|
244
244
|
|
245
245
|
if !arr_insert or arr_insert.empty?
|
246
246
|
#This is the correct syntax for inserting a blank row in MySQL.
|
247
|
-
|
247
|
+
if @opts[:type].to_s == "mysql"
|
248
|
+
sql << " VALUES ()"
|
249
|
+
elsif @opts[:type].to_s == "sqlite3"
|
250
|
+
sql << " DEFAULT VALUES"
|
251
|
+
else
|
252
|
+
raise "Unknown database-type: '#{@opts[:type]}'."
|
253
|
+
end
|
248
254
|
else
|
249
255
|
sql << " ("
|
250
256
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: knjrbfw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.71
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -263,7 +263,6 @@ files:
|
|
263
263
|
- lib/knj/jruby-gtk2/treeview.rb
|
264
264
|
- lib/knj/jruby-gtk2/vbox.rb
|
265
265
|
- lib/knj/jruby-gtk2/window.rb
|
266
|
-
- lib/knj/jruby/sqlitejdbc-v056.jar
|
267
266
|
- lib/knj/jruby_compiler.rb
|
268
267
|
- lib/knj/knj.rb
|
269
268
|
- lib/knj/knj_controller.rb
|
@@ -386,7 +385,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
386
385
|
requirements:
|
387
386
|
- - ">="
|
388
387
|
- !ruby/object:Gem::Version
|
389
|
-
hash:
|
388
|
+
hash: 1335178365550765429
|
390
389
|
segments:
|
391
390
|
- 0
|
392
391
|
version: "0"
|
Binary file
|