knjrbfw 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.7
@@ -0,0 +1,260 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{knjrbfw}
8
+ s.version = "0.0.7"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kasper Johansen"]
12
+ s.date = %q{2011-08-03}
13
+ s.description = %q{Including stuff for HTTP, SSH and much more.}
14
+ s.email = %q{k@spernj.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "knjrbfw.gemspec",
29
+ "lib/knj/.gitignore",
30
+ "lib/knj/arrayext.rb",
31
+ "lib/knj/autoload.rb",
32
+ "lib/knj/autoload/activesupport.rb",
33
+ "lib/knj/autoload/backups/facets_dictionary.rb",
34
+ "lib/knj/autoload/backups/parsedate.rb",
35
+ "lib/knj/autoload/backups/ping.rb",
36
+ "lib/knj/autoload/cinch.rb",
37
+ "lib/knj/autoload/erubis.rb",
38
+ "lib/knj/autoload/facebooker.rb",
39
+ "lib/knj/autoload/facets_dictionary.rb",
40
+ "lib/knj/autoload/gd2.rb",
41
+ "lib/knj/autoload/gettext.rb",
42
+ "lib/knj/autoload/gtk2.rb",
43
+ "lib/knj/autoload/json_autoload.rb",
44
+ "lib/knj/autoload/magick.rb",
45
+ "lib/knj/autoload/mysql.rb",
46
+ "lib/knj/autoload/parsedate.rb",
47
+ "lib/knj/autoload/ping.rb",
48
+ "lib/knj/autoload/rexml.rb",
49
+ "lib/knj/autoload/soap.rb",
50
+ "lib/knj/autoload/sqlite3.rb",
51
+ "lib/knj/autoload/tmail.rb",
52
+ "lib/knj/autoload/twitter.rb",
53
+ "lib/knj/autoload/xmlsimple.rb",
54
+ "lib/knj/autoload/zip.rb",
55
+ "lib/knj/compiler.rb",
56
+ "lib/knj/cpufreq.rb",
57
+ "lib/knj/datarow.rb",
58
+ "lib/knj/datestamp.rb",
59
+ "lib/knj/datet.rb",
60
+ "lib/knj/degulesider.rb",
61
+ "lib/knj/erb/apache_knjerb.conf",
62
+ "lib/knj/erb/cache/README",
63
+ "lib/knj/erb/erb.rb",
64
+ "lib/knj/erb/erb_1.9.rb",
65
+ "lib/knj/erb/erb_cache_clean.rb",
66
+ "lib/knj/erb/erb_fcgi.rb",
67
+ "lib/knj/erb/erb_fcgi_1.9.rb",
68
+ "lib/knj/erb/erb_fcgi_jruby.rb",
69
+ "lib/knj/erb/erb_jruby.rb",
70
+ "lib/knj/erb/include.rb",
71
+ "lib/knj/errors.rb",
72
+ "lib/knj/eruby.rb",
73
+ "lib/knj/event_filemod.rb",
74
+ "lib/knj/event_handler.rb",
75
+ "lib/knj/exchangerates.rb",
76
+ "lib/knj/ext/webrick.rb",
77
+ "lib/knj/filesystem.rb",
78
+ "lib/knj/fs/drivers/filesystem.rb",
79
+ "lib/knj/fs/drivers/ftp.rb",
80
+ "lib/knj/fs/drivers/ssh.rb",
81
+ "lib/knj/fs/fs.rb",
82
+ "lib/knj/gettext_fallback.rb",
83
+ "lib/knj/gettext_threadded.rb",
84
+ "lib/knj/google_sitemap.rb",
85
+ "lib/knj/gtk2.rb",
86
+ "lib/knj/gtk2_cb.rb",
87
+ "lib/knj/gtk2_menu.rb",
88
+ "lib/knj/gtk2_statuswindow.rb",
89
+ "lib/knj/gtk2_tv.rb",
90
+ "lib/knj/hash_methods.rb",
91
+ "lib/knj/http.rb",
92
+ "lib/knj/includes/appserver_cli.rb",
93
+ "lib/knj/ip2location.rb",
94
+ "lib/knj/ironruby-gtk2/button.rb",
95
+ "lib/knj/ironruby-gtk2/dialog.rb",
96
+ "lib/knj/ironruby-gtk2/entry.rb",
97
+ "lib/knj/ironruby-gtk2/gdk_event.rb",
98
+ "lib/knj/ironruby-gtk2/gdk_eventbutton.rb",
99
+ "lib/knj/ironruby-gtk2/gdk_pixbuf.rb",
100
+ "lib/knj/ironruby-gtk2/gladexml.rb",
101
+ "lib/knj/ironruby-gtk2/glib.rb",
102
+ "lib/knj/ironruby-gtk2/gtk2.rb",
103
+ "lib/knj/ironruby-gtk2/gtk_builder.rb",
104
+ "lib/knj/ironruby-gtk2/gtk_cellrenderertext.rb",
105
+ "lib/knj/ironruby-gtk2/gtk_combobox.rb",
106
+ "lib/knj/ironruby-gtk2/gtk_filechooserbutton.rb",
107
+ "lib/knj/ironruby-gtk2/gtk_liststore.rb",
108
+ "lib/knj/ironruby-gtk2/gtk_menu.rb",
109
+ "lib/knj/ironruby-gtk2/gtk_menuitem.rb",
110
+ "lib/knj/ironruby-gtk2/gtk_statusicon.rb",
111
+ "lib/knj/ironruby-gtk2/gtk_treeiter.rb",
112
+ "lib/knj/ironruby-gtk2/gtk_treeselection.rb",
113
+ "lib/knj/ironruby-gtk2/gtk_treeview.rb",
114
+ "lib/knj/ironruby-gtk2/gtk_treeviewcolumn.rb",
115
+ "lib/knj/ironruby-gtk2/iconsize.rb",
116
+ "lib/knj/ironruby-gtk2/image.rb",
117
+ "lib/knj/ironruby-gtk2/label.rb",
118
+ "lib/knj/ironruby-gtk2/stock.rb",
119
+ "lib/knj/ironruby-gtk2/tests/test.glade",
120
+ "lib/knj/ironruby-gtk2/tests/test_2.rb",
121
+ "lib/knj/ironruby-gtk2/tests/test_ironruby_window.rb",
122
+ "lib/knj/ironruby-gtk2/vbox.rb",
123
+ "lib/knj/ironruby-gtk2/window.rb",
124
+ "lib/knj/jruby-gtk2/builder.rb",
125
+ "lib/knj/jruby-gtk2/builder/test_builder.glade",
126
+ "lib/knj/jruby-gtk2/builder/test_builder.rb",
127
+ "lib/knj/jruby-gtk2/builder/test_builder.ui",
128
+ "lib/knj/jruby-gtk2/cellrenderertext.rb",
129
+ "lib/knj/jruby-gtk2/checkbutton.rb",
130
+ "lib/knj/jruby-gtk2/combobox.rb",
131
+ "lib/knj/jruby-gtk2/dialog.rb",
132
+ "lib/knj/jruby-gtk2/eventbutton.rb",
133
+ "lib/knj/jruby-gtk2/gladexml.rb",
134
+ "lib/knj/jruby-gtk2/gtk-4.0.jar",
135
+ "lib/knj/jruby-gtk2/gtk2.rb",
136
+ "lib/knj/jruby-gtk2/hbox.rb",
137
+ "lib/knj/jruby-gtk2/iconsize.rb",
138
+ "lib/knj/jruby-gtk2/image.rb",
139
+ "lib/knj/jruby-gtk2/liststore.rb",
140
+ "lib/knj/jruby-gtk2/menu.rb",
141
+ "lib/knj/jruby-gtk2/progressbar.rb",
142
+ "lib/knj/jruby-gtk2/statusicon.rb",
143
+ "lib/knj/jruby-gtk2/stock.rb",
144
+ "lib/knj/jruby-gtk2/tests/test_glade_window.glade",
145
+ "lib/knj/jruby-gtk2/tests/test_glade_window.rb",
146
+ "lib/knj/jruby-gtk2/tests/test_normal_window.rb",
147
+ "lib/knj/jruby-gtk2/tests/test_trayicon.png",
148
+ "lib/knj/jruby-gtk2/tests/test_trayicon.rb",
149
+ "lib/knj/jruby-gtk2/treeview.rb",
150
+ "lib/knj/jruby-gtk2/vbox.rb",
151
+ "lib/knj/jruby-gtk2/window.rb",
152
+ "lib/knj/jruby_compiler.rb",
153
+ "lib/knj/knj.rb",
154
+ "lib/knj/knj_controller.rb",
155
+ "lib/knj/knjdb/dbtime.rb",
156
+ "lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb",
157
+ "lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb",
158
+ "lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb",
159
+ "lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb",
160
+ "lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3.rb",
161
+ "lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb",
162
+ "lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_indexes.rb",
163
+ "lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb",
164
+ "lib/knj/knjdb/libknjdb.rb",
165
+ "lib/knj/knjdb/libknjdb_java_sqlite3.rb",
166
+ "lib/knj/knjdb/libknjdb_row.rb",
167
+ "lib/knj/knjdb/libknjdb_sqlite3_ironruby.rb",
168
+ "lib/knj/knjdb/mysql-connector-java-5.1.13-bin.jar",
169
+ "lib/knj/knjdb/sqlitejdbc-v056.jar",
170
+ "lib/knj/libqt.rb",
171
+ "lib/knj/libqt_window.rb",
172
+ "lib/knj/locale_strings.rb",
173
+ "lib/knj/locales.rb",
174
+ "lib/knj/maemo/fremantle-calendar/fremantle-calendar.rb",
175
+ "lib/knj/mail.rb",
176
+ "lib/knj/mailobj.rb",
177
+ "lib/knj/mount.rb",
178
+ "lib/knj/mutexcl.rb",
179
+ "lib/knj/notify.rb",
180
+ "lib/knj/nvidia_settings.rb",
181
+ "lib/knj/objects.rb",
182
+ "lib/knj/opts.rb",
183
+ "lib/knj/os.rb",
184
+ "lib/knj/php.rb",
185
+ "lib/knj/php_parser/arguments.rb",
186
+ "lib/knj/php_parser/functions.rb",
187
+ "lib/knj/php_parser/php_parser.rb",
188
+ "lib/knj/php_parser/tests/test.rb",
189
+ "lib/knj/php_parser/tests/test_function.php",
190
+ "lib/knj/php_parser/tests/test_function_run.rb",
191
+ "lib/knj/power_manager.rb",
192
+ "lib/knj/rand.rb",
193
+ "lib/knj/retry.rb",
194
+ "lib/knj/rhodes/mutex.rb",
195
+ "lib/knj/rhodes/rhodes.js",
196
+ "lib/knj/rhodes/rhodes.rb",
197
+ "lib/knj/rsvgbin.rb",
198
+ "lib/knj/scripts/degulesider.rb",
199
+ "lib/knj/scripts/filesearch.rb",
200
+ "lib/knj/scripts/ip2location.rb",
201
+ "lib/knj/scripts/keepalive.rb",
202
+ "lib/knj/scripts/svn_merge.rb",
203
+ "lib/knj/scripts/upgrade_knjrbfw_checker.rb",
204
+ "lib/knj/sms.rb",
205
+ "lib/knj/sshrobot/sshrobot.rb",
206
+ "lib/knj/strings.rb",
207
+ "lib/knj/sysuser.rb",
208
+ "lib/knj/tests/compiler/compiler_test.rb",
209
+ "lib/knj/tests/compiler/compiler_test_file.rb",
210
+ "lib/knj/tests/test_degulesider.rb",
211
+ "lib/knj/tests/test_mount.rb",
212
+ "lib/knj/tests/test_retry.rb",
213
+ "lib/knj/thread.rb",
214
+ "lib/knj/thread2.rb",
215
+ "lib/knj/threadhandler.rb",
216
+ "lib/knj/threadpool.rb",
217
+ "lib/knj/translations.rb",
218
+ "lib/knj/unix_proc.rb",
219
+ "lib/knj/web.rb",
220
+ "lib/knj/webscripts/image.rhtml",
221
+ "lib/knj/win.rb",
222
+ "lib/knj/win_registry.rb",
223
+ "lib/knj/win_tightvnc.rb",
224
+ "lib/knj/x11vnc.rb",
225
+ "lib/knj/youtube.rb",
226
+ "lib/knjrbfw.rb",
227
+ "spec/knjrbfw_spec.rb",
228
+ "spec/spec_helper.rb"
229
+ ]
230
+ s.homepage = %q{http://github.com/kaspernj/knjrbfw}
231
+ s.licenses = ["MIT"]
232
+ s.require_paths = ["lib"]
233
+ s.rubygems_version = %q{1.6.2}
234
+ s.summary = %q{A framework with lots of stuff for Ruby.}
235
+
236
+ if s.respond_to? :specification_version then
237
+ s.specification_version = 3
238
+
239
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
240
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
241
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
242
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.3"])
243
+ s.add_development_dependency(%q<rcov>, [">= 0"])
244
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
245
+ else
246
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
247
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
248
+ s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
249
+ s.add_dependency(%q<rcov>, [">= 0"])
250
+ s.add_dependency(%q<sqlite3>, [">= 0"])
251
+ end
252
+ else
253
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
254
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
255
+ s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
256
+ s.add_dependency(%q<rcov>, [">= 0"])
257
+ s.add_dependency(%q<sqlite3>, [">= 0"])
258
+ end
259
+ end
260
+
@@ -27,6 +27,7 @@ module Knj
27
27
  autoload :Opts, $knjpath + "opts.rb"
28
28
  autoload :Mail, $knjpath + "mail.rb"
29
29
  autoload :Mailobj, $knjpath + "mailobj.rb"
30
+ autoload :Mutexcl, $knjpath + "mutexcl.rb"
30
31
  autoload :Mount, $knjpath + "mount.rb"
31
32
  autoload :Mplayer, $knjpath + "mplayer.rb"
32
33
  autoload :Notify, $knjpath + "notify.rb"
@@ -14,15 +14,14 @@ class Knj::Compiler
14
14
  #Compiles file into cache as a method.
15
15
  def compile_file(args)
16
16
  raise "File does not exist." if !File.exist?(args[:filepath])
17
- filepath = Knj::Php.realpath(args[:filepath])
18
- defname = def_name_for_file_path(filepath)
17
+ defname = def_name_for_file_path(args[:filepath])
19
18
 
20
19
  evalcont = "class Knj::Compiler::Container; def self.#{defname};"
21
- evalcont += File.read(filepath)
20
+ evalcont += File.read(args[:filepath])
22
21
  evalcont += ";end;end"
23
22
 
24
23
  eval(evalcont, nil, args[:fileident])
25
- @compiled[filepath] = Time.new
24
+ @compiled[args[:filepath]] = Time.new
26
25
  end
27
26
 
28
27
  #Returns the method name for a filepath.
@@ -32,19 +31,23 @@ class Knj::Compiler
32
31
 
33
32
  #Compile and evaluate a file - it will be cached.
34
33
  def eval_file(args)
35
- filepath = Knj::Php.realpath(args[:filepath])
36
-
37
34
  #Compile if it hasnt been compiled yet.
38
- @mutex.synchronize do
39
- compile_file(args) if !@compiled.has_key?(filepath)
40
-
41
- #Compile if modified time has been changed.
42
- mtime = File.mtime(filepath)
43
- compile_file(args) if @compiled[filepath] < mtime
35
+ if !@compiled.has_key?(args[:filepath])
36
+ @mutex.synchronize do
37
+ compile_file(args) if !@compiled.has_key?(args[:filepath])
38
+ end
39
+ end
40
+
41
+ #Compile if modified time has been changed.
42
+ mtime = File.mtime(args[:filepath])
43
+ if @compiled[args[:filepath]] < mtime
44
+ @mutex.synchronize do
45
+ compile_file(args)
46
+ end
44
47
  end
45
48
 
46
49
  #Call the compiled function.
47
- defname = def_name_for_file_path(filepath)
50
+ defname = def_name_for_file_path(args[:filepath])
48
51
  Knj::Compiler::Container.send(defname)
49
52
  end
50
53
 
@@ -37,15 +37,19 @@ class Knj::Datarow
37
37
  raise "Unknown argument: '#{val.class.name}'."
38
38
  end
39
39
 
40
- if !methodname
41
- methodname = "#{classname.to_s.downcase}s".to_sym
42
- end
40
+ methodname = "#{classname.to_s.downcase}s".to_sym if !methodname
43
41
 
44
42
  define_method(methodname) do |*args|
45
43
  merge_args = args[0] if args and args[0]
46
44
  merge_args = {} if !merge_args
47
45
  return ob.list(classname, {colname.to_s => self.id}.merge(merge_args))
48
46
  end
47
+
48
+ define_method("#{methodname}_count".to_sym) do |*args|
49
+ merge_args = args[0] if args and args[0]
50
+ merge_args = {} if !merge_args
51
+ return ob.list(classname, {"count" => true, colname.to_s => self.id}.merge(merge_args))
52
+ end
49
53
  end
50
54
  end
51
55
 
@@ -111,46 +115,95 @@ class Knj::Datarow
111
115
  return @columns_sqlhelper_args
112
116
  end
113
117
 
118
+ def self.list(d)
119
+ if d.args["count"]
120
+ count = true
121
+ d.args.delete("count")
122
+ sql = "SELECT COUNT(*) AS count"
123
+ else
124
+ sql = "SELECT *"
125
+ end
126
+
127
+ sql += " FROM #{d.db.enc_table}#{table}#{d.db.enc_table} WHERE 1=1"
128
+
129
+ ret = list_helper(d)
130
+ d.args.each do |key, val|
131
+ raise "Invalid key: '#{key}'."
132
+ end
133
+
134
+ sql += ret[:sql_where]
135
+ sql += ret[:sql_order]
136
+ sql += ret[:sql_limit]
137
+
138
+ return d.db.query(sql).fetch[:count].to_i if count
139
+ return d.ob.list_bysql(table, sql)
140
+ end
141
+
142
+ def self.load_columns(d)
143
+ if @columns_sqlhelper_args_working
144
+ sleep 0.1 while @columns_sqlhelper_args_working
145
+ return false
146
+ end
147
+
148
+ begin
149
+ @columns_sqlhelper_args_working = true
150
+ cols = self.columns(d)
151
+
152
+ inst_methods = instance_methods(false)
153
+
154
+ sqlhelper_args = {
155
+ :db => d.db,
156
+ :table => table,
157
+ :cols_bools => [],
158
+ :cols_date => [],
159
+ :cols_dbrows => [],
160
+ :cols_num => [],
161
+ :cols_str => []
162
+ }
163
+ cols.each do |col_name, col_obj|
164
+ col_type = col_obj.type
165
+ col_type = "int" if col_type == "bigint" or col_type == "tinyint" or col_type == "mediumint" or col_type == "smallint"
166
+
167
+ if col_type == "enum" and col_obj.maxlength == "'0','1'"
168
+ sqlhelper_args[:cols_bools] << col_name
169
+ method_name = "#{col_name}?".to_sym
170
+
171
+ if !inst_methods.index(method_name)
172
+ define_method(method_name) do
173
+ return true if self[col_name.to_sym].to_s == "1"
174
+ return false
175
+ end
176
+ end
177
+ elsif col_type == "int" and col_name.slice(-3, 3) == "_id"
178
+ sqlhelper_args[:cols_dbrows] << col_name
179
+ elsif col_type == "int" or col_type == "bigint"
180
+ sqlhelper_args[:cols_num] << col_name
181
+ elsif col_type == "varchar" or col_type == "text" or col_type == "enum"
182
+ sqlhelper_args[:cols_str] << col_name
183
+ elsif col_type == "date" or col_type == "datetime"
184
+ sqlhelper_args[:cols_date] << col_name
185
+ method_name = "#{col_name}_str".to_sym
186
+
187
+ if !inst_methods.index(method_name)
188
+ define_method(method_name) do |*args|
189
+ if Knj::Datet.is_nullstamp?(self[col_name.to_sym])
190
+ return ob.events.call(:no_date, self.class.name)
191
+ end
192
+
193
+ return Knj::Datet.in(self[col_name.to_sym]).out(*args)
194
+ end
195
+ end
196
+ end
197
+ end
198
+
199
+ @columns_sqlhelper_args = sqlhelper_args
200
+ ensure
201
+ @columns_sqlhelper_args_working = false
202
+ end
203
+ end
204
+
114
205
  def self.list_helper(d)
115
- sleep 0.1 while @columns_sqlhelper_args_working
116
-
117
- if !@columns_sqlhelper_args
118
- begin
119
- @columns_sqlhelper_args_working = true
120
- cols = self.columns(d)
121
-
122
- sqlhelper_args = {
123
- :db => d.db,
124
- :table => table,
125
- :cols_bools => [],
126
- :cols_date => [],
127
- :cols_dbrows => [],
128
- :cols_num => [],
129
- :cols_str => []
130
- }
131
- cols.each do |col_name, col_obj|
132
- col_type = col_obj.type
133
- col_type = "int" if col_type == "bigint" or col_type == "tinyint" or col_type == "mediumint" or col_type == "smallint"
134
-
135
- if col_type == "enum" and col_obj.maxlength == "'0','1'"
136
- sqlhelper_args[:cols_bools] << col_name
137
- elsif col_type == "int" and col_name.slice(-3, 3) == "_id"
138
- sqlhelper_args[:cols_dbrows] << col_name
139
- elsif col_type == "int" or col_type == "bigint"
140
- sqlhelper_args[:cols_num] << col_name
141
- elsif col_type == "varchar" or col_type == "text" or col_type == "enum"
142
- sqlhelper_args[:cols_str] << col_name
143
- elsif col_type == "date" or col_type == "datetime"
144
- sqlhelper_args[:cols_date] << col_name
145
- end
146
- end
147
-
148
- @columns_sqlhelper_args = sqlhelper_args
149
- ensure
150
- @columns_sqlhelper_args_working = false
151
- end
152
- end
153
-
206
+ load_columns(d) if !@columns_sqlhelper_args
154
207
  return d.ob.sqlhelper(d.args, @columns_sqlhelper_args)
155
208
  end
156
209
 
@@ -240,17 +293,4 @@ class Knj::Datarow
240
293
  def each(&args)
241
294
  return @data.each(&args)
242
295
  end
243
-
244
- def method_missing(*args)
245
- func_name = args[0].to_s
246
- if match = func_name.match(/^(\S+)\?$/) and @data.has_key?(match[1].to_sym)
247
- if @data[match[1].to_sym] == "1" or @data[match[1].to_sym] == "yes"
248
- return true
249
- elsif @data[match[1].to_sym] == "0" or @data[match[1].to_sym] == "no"
250
- return false
251
- end
252
- end
253
-
254
- raise "No such method: '#{func_name}' on '#{self.class.name}'"
255
- end
256
296
  end
@@ -420,6 +420,18 @@ class Knj::Datet
420
420
  ]
421
421
  end
422
422
 
423
+ def self.days_arr
424
+ return {
425
+ 1 => _("Monday"),
426
+ 2 => _("Tuesday"),
427
+ 3 => _("Wednesday"),
428
+ 4 => _("Thursday"),
429
+ 5 => _("Friday"),
430
+ 6 => _("Saturday"),
431
+ 0 => _("Sunday")
432
+ }
433
+ end
434
+
423
435
  def loc_wday
424
436
  return _(@time.strftime("%A"))
425
437
  end
@@ -4,6 +4,7 @@ class Knj::Event_filemod
4
4
  def initialize(args, &block)
5
5
  @args = args
6
6
  @run = true
7
+ @mutex = Mutex.new
7
8
 
8
9
  @args[:wait] = 1 if !@args.has_key?(:wait)
9
10
 
@@ -16,7 +17,8 @@ class Knj::Event_filemod
16
17
  while @run do
17
18
  break if !@args or !@args[:paths] or @args[:paths].empty?
18
19
 
19
- @args[:paths].clone.each do |path|
20
+ @mutex.synchronize do
21
+ @args[:paths].each do |path|
20
22
  changed = false
21
23
 
22
24
  if @mtimes and !@mtimes.has_key?(path) and @mtimes.is_a?(Hash)
@@ -50,4 +52,8 @@ class Knj::Event_filemod
50
52
  @run = false
51
53
  @args = nil
52
54
  end
55
+
56
+ def add_path(fpath)
57
+ @args[:paths] << fpath
58
+ end
53
59
  end
@@ -22,7 +22,7 @@ class Knj::Event_handler
22
22
  end
23
23
 
24
24
  def connect(name, &block)
25
- raise "No such event." if !@events.has_key?(name)
25
+ raise "No such event: '#{name}'." if !@events.has_key?(name)
26
26
 
27
27
  event = @events[name]
28
28
 
@@ -380,6 +380,16 @@ class Knj::Db
380
380
  end
381
381
  end
382
382
 
383
+ def enc_table
384
+ if !@enc_table
385
+ conn_exec do |driver|
386
+ @enc_table = driver.escape_table
387
+ end
388
+ end
389
+
390
+ return @enc_table
391
+ end
392
+
383
393
  def date_out(date_obj)
384
394
  return Knj::Datet.in(date_obj).dbstr
385
395
  end
@@ -0,0 +1,48 @@
1
+ class Knj::Mutexcl
2
+ def initialize(args = {})
3
+ @args = args
4
+ raise "No ':modes' given in arguments." if !@args.has_key?(:modes)
5
+ @mutex = Mutex.new
6
+ @blocked = {}
7
+ @args[:modes].each do |mode, data|
8
+ data[:blocks].each do |block|
9
+ @blocked[block] = {
10
+ :mutex => Mutex.new,
11
+ :count => 0
12
+ }
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.rw
18
+ return Knj::Mutexcl.new(
19
+ :modes => {
20
+ :reader => {:blocks => [:writer]},
21
+ :writer => {:blocks => [:writer, :reader]}
22
+ }
23
+ )
24
+ end
25
+
26
+ def sync(mode)
27
+ raise "No such mode: '#{mode}'." if !@args[:modes].has_key?(mode)
28
+
29
+ while @blocked[mode][:count].to_i > 0
30
+ STDOUT.print "Sleeping because blocked '#{mode}' (#{@blocked[mode][:count]}).\n"
31
+ sleep 0.1
32
+ end
33
+
34
+ @mutex.synchronize do
35
+ @args[:modes][mode][:blocks].each do |block|
36
+ @blocked[block][:count] += 1
37
+ end
38
+ end
39
+
40
+ begin
41
+ yield
42
+ ensure
43
+ @args[:modes][mode][:blocks].each do |block|
44
+ @blocked[block][:count] -= 1
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,11 +8,14 @@ class Knj::Objects
8
8
  @args[:class_pre] = "class_" if !@args[:class_pre]
9
9
  @args[:module] = Kernel if !@args[:module]
10
10
  @objects = {}
11
- @objects_mutex = Mutex.new
12
11
 
13
12
  @events = Knj::Event_handler.new
14
13
  @events.add_event(
15
14
  :name => :no_html,
15
+ :connections_max => 1
16
+ )
17
+ @events.add_event(
18
+ :name => :no_date,
16
19
  :connections_max => 1
17
20
  )
18
21
 
@@ -20,15 +23,18 @@ class Knj::Objects
20
23
  raise "No class path given." if !@args[:class_path] and (@args[:require] or !@args.has_key?(:require))
21
24
  end
22
25
 
26
+ def init_class(classname)
27
+ return false if @objects.has_key?(classname)
28
+ @objects[classname] = {}
29
+ end
30
+
23
31
  #Returns a cloned version of the @objects variable. Cloned because iteration on it may crash some of the other methods in Ruby 1.9+
24
32
  def objects
25
33
  objs_cloned = {}
26
34
 
27
- @objects_mutex.synchronize do
28
- @objects.each do |classn, newhash|
29
- objs_cloned[classn] = newhash.clone
30
- end
31
- end
35
+ @objects.keys.each do |key|
36
+ objs_cloned[key] = @objects[key].clone
37
+ end
32
38
 
33
39
  return objs_cloned
34
40
  end
@@ -39,13 +45,9 @@ class Knj::Objects
39
45
 
40
46
  def count_objects
41
47
  count = 0
42
- @objects_mutex.synchronize do
43
- @objects.each do |key, value|
44
- value.each do |id, object|
45
- count += 1
46
- end
47
- end
48
- end
48
+ @objects.keys.each do |key|
49
+ count += @objects[key].length
50
+ end
49
51
 
50
52
  return count
51
53
  end
@@ -96,14 +98,20 @@ class Knj::Objects
96
98
  end
97
99
 
98
100
  def requireclass(classname)
99
- return nil if !@args[:require] and @args.has_key?(:require)
100
- classname = classname.to_s
101
-
102
- if !Knj::Php.class_exists(classname)
101
+ classname = classname.to_sym
102
+
103
+ if !@args[:require] and @args.has_key?(:require)
104
+ @objects[classname] = {} if !@objects.has_key?(classname)
105
+ return nil
106
+ end
107
+
108
+ if !@objects.has_key?(classname)
103
109
  filename = @args[:class_path] + "/#{@args[:class_pre]}#{classname.downcase}.rb"
104
110
  filename_req = @args[:class_path] + "/#{@args[:class_pre]}#{classname.downcase}"
105
111
  raise "Class file could not be found: #{filename}." if !File.exists?(filename)
106
112
  require filename_req
113
+ @args[:module].const_get(classname).load_columns(Knj::Hash_methods.new(:args => args, :ob => self, :db => @args[:db]))
114
+ @objects[classname] = {}
107
115
  end
108
116
  end
109
117
 
@@ -120,30 +128,21 @@ class Knj::Objects
120
128
  raise Knj::Errors::InvalidData, "Unknown data: '#{data.class.to_s}'."
121
129
  end
122
130
 
123
- return @objects[classname][id] if @objects.has_key?(classname) and @objects[classname].has_key?(id)
124
-
125
- retobj = nil
126
- @objects_mutex.synchronize do
127
- if !@objects.has_key?(classname)
128
- self.requireclass(classname)
129
- @objects[classname] = {}
130
- end
131
-
132
- if @args[:datarow]
133
- @objects[classname][id] = @args[:module].const_get(classname).new(Knj::Hash_methods.new(
134
- :ob => self,
135
- :data => data
136
- ))
137
- else
138
- args = [data]
139
- args = args | @args[:extra_args] if @args[:extra_args]
140
- @objects[classname][id] = @args[:module].const_get(classname).new(*args)
141
- end
142
-
143
- return @objects[classname][id]
144
- end
145
-
146
- raise "Something went wrong."
131
+ return @objects[classname][id] if @objects.has_key?(classname) and @objects[classname].has_key?(id)
132
+ self.requireclass(classname) if !@objects.has_key?(classname)
133
+
134
+ if @args[:datarow]
135
+ @objects[classname][id] = @args[:module].const_get(classname).new(Knj::Hash_methods.new(
136
+ :ob => self,
137
+ :data => data
138
+ ))
139
+ else
140
+ args = [data]
141
+ args = args | @args[:extra_args] if @args[:extra_args]
142
+ @objects[classname][id] = @args[:module].const_get(classname).new(*args)
143
+ end
144
+
145
+ return @objects[classname][id]
147
146
  end
148
147
 
149
148
  def get_by(classname, args = {})
@@ -275,10 +274,10 @@ class Knj::Objects
275
274
  obs = self.list(classname)
276
275
  end
277
276
 
278
- if Knj::Php.class_exists("Dictionary")
277
+ if RUBY_VERSION[0..2] == 1.8 and Knj::Php.class_exists("Dictionary")
279
278
  list = Dictionary.new
280
279
  else
281
- list = Hash.new
280
+ list = {}
282
281
  end
283
282
 
284
283
  if args[:addnew] or args[:add]
@@ -430,9 +429,7 @@ class Knj::Objects
430
429
  #errstr += "Could not find object ID in cache."
431
430
  #raise errstr
432
431
  #else
433
- @objects_mutex.synchronize do
434
- @objects[classname].delete(object.id.to_i)
435
- end
432
+ @objects[classname].delete(object.id.to_i)
436
433
  #end
437
434
  end
438
435
 
@@ -448,9 +445,7 @@ class Knj::Objects
448
445
  classname = classname.to_sym
449
446
 
450
447
  return false if !@objects.has_key?(classname)
451
- @objects_mutex.synchronize do
452
- @objects[classname] = {}
453
- end
448
+ @objects[classname] = {}
454
449
  end
455
450
 
456
451
  # Delete an object. Both from the database and from the cache.
@@ -508,37 +503,32 @@ class Knj::Objects
508
503
  end
509
504
  else
510
505
  return false if !@objects.has_key?(classn)
511
- @objects_mutex.synchronize do
512
- @objects[classn] = {}
513
- GC.start
514
- end
506
+ @objects[classn] = {}
507
+ GC.start
515
508
  end
516
509
  end
517
510
 
518
511
  def clean_all
519
512
  classnames = []
520
- @objects_mutex.synchronize do
521
- @objects.each do |classn, hash_list|
522
- classnames << classn
523
- end
524
-
525
- classnames.each do |classn|
526
- @objects[classn] = {}
527
- end
528
- end
513
+ @objects.keys.each do |classn|
514
+ classnames << classn
515
+ end
516
+
517
+ classnames.each do |classn|
518
+ @objects[classn] = {}
519
+ end
529
520
 
530
521
  GC.start
531
522
  end
532
523
 
533
524
  def clean_recover
534
- @objects_mutex.synchronize do
535
- @objects.each do |classn, hash_list|
536
- classobj = Kernel.const_get(classn)
537
- ObjectSpace.each_object(classobj) do |obj|
538
- @objects[classn][obj.id] = obj
539
- end
540
- end
541
- end
525
+ @objects.keys.each do |classn|
526
+ data = @objects[classn]
527
+ classobj = Kernel.const_get(classn)
528
+ ObjectSpace.each_object(classobj) do |obj|
529
+ data[obj.id] = obj
530
+ end
531
+ end
542
532
  end
543
533
 
544
534
  def sqlhelper(list_args, args)
@@ -865,6 +865,16 @@ class Knj::Web
865
865
  html = ""
866
866
 
867
867
  hidden_arr.each do |hidden_hash|
868
+ if hidden_hash[:value].is_a?(Array)
869
+ if !hidden_hash[:value][0]
870
+ hidden_hash[:value] = nil
871
+ else
872
+ key = hidden_hash[:value][1]
873
+ obj = hidden_hash[:value][0]
874
+ hidden_hash[:value] = obj[key]
875
+ end
876
+ end
877
+
868
878
  html += "<input type=\"hidden\" name=\"#{hidden_hash[:name].to_s.html}\" value=\"#{hidden_hash[:value].to_s.html}\" />"
869
879
  end
870
880
 
@@ -266,4 +266,72 @@ describe "Knjrbfw" do
266
266
  #ignore.
267
267
  end
268
268
  end
269
+
270
+ it "should be able to use Knj::Mutexcl with advanced arguments." do
271
+ mutex = Knj::Mutexcl.new(
272
+ :modes => {
273
+ :reader => {
274
+ :blocks => [:writer]
275
+ },
276
+ :writer => {
277
+ :blocks => [:reader, :writer]
278
+ }
279
+ }
280
+ )
281
+
282
+ $count = 0
283
+
284
+ Knj::Thread.new do
285
+ mutex.sync(:reader) do
286
+ sleep 0.2
287
+ $count += 1
288
+ end
289
+ end
290
+
291
+ mutex.sync(:reader) do
292
+ $count += 1
293
+ end
294
+
295
+ raise "Count should be 1 by now but it wasnt: '#{$count}'." if $count != 1
296
+ sleep 0.3
297
+ raise "Count should be 2 by now but it wasnt: '#{$count}'." if $count != 2
298
+
299
+
300
+ $count = 0
301
+ Knj::Thread.new do
302
+ mutex.sync(:reader) do
303
+ sleep 2
304
+ $count += 1
305
+ end
306
+ end
307
+ sleep 0.1
308
+
309
+ Knj::Thread.new do
310
+ mutex.sync(:writer) do
311
+ $count += 1
312
+ end
313
+ end
314
+
315
+ sleep 1
316
+ raise "Count should be 0 but it wasnt: '#{$count}'." if $count != 0
317
+ sleep 1.1
318
+ raise "Count should be 2 but it wasnt: '#{$count}'." if $count != 2
319
+
320
+ Knj::Thread.new do
321
+ mutex.sync(:reader) do
322
+ sleep 0.2
323
+ $count += 1
324
+ end
325
+ end
326
+
327
+ Knj::Thread.new do
328
+ mutex.sync(:reader) do
329
+ sleep 0.2
330
+ $count += 1
331
+ end
332
+ end
333
+
334
+ sleep 0.35
335
+ raise "Count should be 4 but it wasnt: '#{$count}'." if $count != 4
336
+ end
269
337
  end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease: !!null
4
+ version: 0.0.7
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
9
- autorequire: !!null
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-28 00:00:00.000000000 +02:00
13
- default_executable: !!null
12
+ date: 2011-08-03 00:00:00.000000000 +02:00
13
+ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &21954700 !ruby/object:Gem::Requirement
17
+ requirement: &13561560 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.3.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *21954700
25
+ version_requirements: *13561560
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
- requirement: &21954220 !ruby/object:Gem::Requirement
28
+ requirement: &13537480 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *21954220
36
+ version_requirements: *13537480
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: jeweler
39
- requirement: &21953740 !ruby/object:Gem::Requirement
39
+ requirement: &13534260 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.6.3
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *21953740
47
+ version_requirements: *13534260
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rcov
50
- requirement: &21953260 !ruby/object:Gem::Requirement
50
+ requirement: &13526740 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *21953260
58
+ version_requirements: *13526740
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: sqlite3
61
- requirement: &21952780 !ruby/object:Gem::Requirement
61
+ requirement: &13524020 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *21952780
69
+ version_requirements: *13524020
70
70
  description: Including stuff for HTTP, SSH and much more.
71
71
  email: k@spernj.org
72
72
  executables: []
@@ -83,6 +83,7 @@ files:
83
83
  - README.rdoc
84
84
  - Rakefile
85
85
  - VERSION
86
+ - knjrbfw.gemspec
86
87
  - lib/knj/.gitignore
87
88
  - lib/knj/arrayext.rb
88
89
  - lib/knj/autoload.rb
@@ -232,6 +233,7 @@ files:
232
233
  - lib/knj/mail.rb
233
234
  - lib/knj/mailobj.rb
234
235
  - lib/knj/mount.rb
236
+ - lib/knj/mutexcl.rb
235
237
  - lib/knj/notify.rb
236
238
  - lib/knj/nvidia_settings.rb
237
239
  - lib/knj/objects.rb
@@ -286,7 +288,7 @@ has_rdoc: true
286
288
  homepage: http://github.com/kaspernj/knjrbfw
287
289
  licenses:
288
290
  - MIT
289
- post_install_message: !!null
291
+ post_install_message:
290
292
  rdoc_options: []
291
293
  require_paths:
292
294
  - lib
@@ -298,7 +300,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
300
  version: '0'
299
301
  segments:
300
302
  - 0
301
- hash: 3068308084372948741
303
+ hash: -3172684593992288463
302
304
  required_rubygems_version: !ruby/object:Gem::Requirement
303
305
  none: false
304
306
  requirements:
@@ -306,9 +308,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
308
  - !ruby/object:Gem::Version
307
309
  version: '0'
308
310
  requirements: []
309
- rubyforge_project: !!null
310
- rubygems_version: 1.5.0
311
- signing_key: !!null
311
+ rubyforge_project:
312
+ rubygems_version: 1.6.2
313
+ signing_key:
312
314
  specification_version: 3
313
315
  summary: A framework with lots of stuff for Ruby.
314
316
  test_files: []