knjrbfw 0.0.59 → 0.0.62

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "wref"
6
6
  gem "tsafe"
7
+ gem "datet"
8
+ gem "http2"
7
9
 
8
10
  # Add dependencies to develop your gem here.
9
11
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -1,12 +1,18 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ datet (0.0.0)
4
5
  diff-lcs (1.1.3)
5
6
  git (1.2.5)
7
+ http2 (0.0.0)
8
+ knjrbfw
6
9
  jeweler (1.6.4)
7
10
  bundler (~> 1.0)
8
11
  git (>= 1.2.5)
9
12
  rake
13
+ knjrbfw (0.0.55)
14
+ tsafe
15
+ wref
10
16
  rake (0.9.2.2)
11
17
  rcov (0.9.11)
12
18
  rcov (0.9.11-java)
@@ -29,6 +35,8 @@ PLATFORMS
29
35
 
30
36
  DEPENDENCIES
31
37
  bundler (>= 1.0.0)
38
+ datet
39
+ http2
32
40
  jeweler (~> 1.6.3)
33
41
  rcov
34
42
  rmagick
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.59
1
+ 0.0.62
data/knjrbfw.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjrbfw}
8
- s.version = "0.0.59"
8
+ s.version = "0.0.62"
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"]
12
- s.date = %q{2012-07-10}
12
+ s.date = %q{2012-07-14}
13
13
  s.description = %q{Including stuff for HTTP, SSH and much more.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.extra_rdoc_files = [
@@ -62,7 +62,6 @@ Gem::Specification.new do |s|
62
62
  "lib/knj/datarow.rb",
63
63
  "lib/knj/datarow_custom.rb",
64
64
  "lib/knj/datestamp.rb",
65
- "lib/knj/datet.rb",
66
65
  "lib/knj/db.rb",
67
66
  "lib/knj/degulesider.rb",
68
67
  "lib/knj/erb/apache_knjerb.conf",
@@ -96,8 +95,6 @@ Gem::Specification.new do |s|
96
95
  "lib/knj/gtk2_tv.rb",
97
96
  "lib/knj/gtk2_window.rb",
98
97
  "lib/knj/hash_methods.rb",
99
- "lib/knj/http.rb",
100
- "lib/knj/http2.rb",
101
98
  "lib/knj/image.rb",
102
99
  "lib/knj/includes/appserver_cli.rb",
103
100
  "lib/knj/includes/require_info.rb",
@@ -259,10 +256,8 @@ Gem::Specification.new do |s|
259
256
  "spec/amixer_spec.rb",
260
257
  "spec/arrayext_spec.rb",
261
258
  "spec/cmd_parser_spec.rb",
262
- "spec/datet_spec.rb",
263
259
  "spec/db_spec.rb",
264
260
  "spec/db_spec_encoding_test_file.txt",
265
- "spec/http2_spec.rb",
266
261
  "spec/knjrbfw_spec.rb",
267
262
  "spec/objects_spec.rb",
268
263
  "spec/php_spec.rb",
@@ -286,6 +281,8 @@ Gem::Specification.new do |s|
286
281
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
287
282
  s.add_runtime_dependency(%q<wref>, [">= 0"])
288
283
  s.add_runtime_dependency(%q<tsafe>, [">= 0"])
284
+ s.add_runtime_dependency(%q<datet>, [">= 0"])
285
+ s.add_runtime_dependency(%q<http2>, [">= 0"])
289
286
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
290
287
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
291
288
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.3"])
@@ -295,6 +292,8 @@ Gem::Specification.new do |s|
295
292
  else
296
293
  s.add_dependency(%q<wref>, [">= 0"])
297
294
  s.add_dependency(%q<tsafe>, [">= 0"])
295
+ s.add_dependency(%q<datet>, [">= 0"])
296
+ s.add_dependency(%q<http2>, [">= 0"])
298
297
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
299
298
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
300
299
  s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
@@ -305,6 +304,8 @@ Gem::Specification.new do |s|
305
304
  else
306
305
  s.add_dependency(%q<wref>, [">= 0"])
307
306
  s.add_dependency(%q<tsafe>, [">= 0"])
307
+ s.add_dependency(%q<datet>, [">= 0"])
308
+ s.add_dependency(%q<http2>, [">= 0"])
308
309
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
309
310
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
310
311
  s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
data/lib/knj/arrayext.rb CHANGED
@@ -190,7 +190,7 @@ module Knj::ArrayExt
190
190
  def self.validate_hash(h, args)
191
191
  h.each do |key, val|
192
192
  if args.key?(:not_empty) and args[:not_empty].index(key) != nil and val.to_s.strip.length <= 0
193
- raise Knj::Errors::InvalidData, sprintf(args[:not_empty_error], key)
193
+ raise ArgumentError, sprintf(args[:not_empty_error], key)
194
194
  end
195
195
  end
196
196
  end
@@ -1,5 +1,5 @@
1
1
  begin
2
- require "wref"
2
+ require "wref" if !Kernel.const_defined?(:Wref)
3
3
  rescue LoadError
4
4
  require "rubygems"
5
5
  require "wref"
@@ -27,7 +27,7 @@ class Knj::Cmd_parser
27
27
  month = match[18].to_i
28
28
  date = match[19].to_i
29
29
  elsif match[20] and match[21] and match[22]
30
- month = Knj::Datet.month_str_to_no(match[21])
30
+ month = Datet.month_str_to_no(match[21])
31
31
  date = match[22].to_i
32
32
  end
33
33
 
data/lib/knj/datarow.rb CHANGED
@@ -547,7 +547,7 @@ class Knj::Datarow
547
547
  classname = self.class.classname.to_sym
548
548
  if @ob.ids_cache_should.key?(classname)
549
549
  #ID caching is enabled for this model - dont reload until first use.
550
- raise Knj::Errors::NotFound, "ID was not found in cache: '#{id}'." if !@ob.ids_cache[classname].key?(@id)
550
+ raise Errno::ENOENT, "ID was not found in cache: '#{id}'." if !@ob.ids_cache[classname].key?(@id)
551
551
  @should_reload = true
552
552
  else
553
553
  #ID caching is not enabled - reload now to check if row exists. Else set 'should_reload'-variable if 'skip_reload' is set.
@@ -558,7 +558,7 @@ class Knj::Datarow
558
558
  end
559
559
  end
560
560
  else
561
- raise Knj::Errors::InvalidData, "Could not figure out the data from '#{data.class.name}'."
561
+ raise ArgumentError, "Could not figure out the data from '#{data.class.name}'."
562
562
  end
563
563
 
564
564
  if @id.to_i <= 0
@@ -574,7 +574,7 @@ class Knj::Datarow
574
574
  # print "The username changed in the database!" if user[:username] != old_username
575
575
  def reload
576
576
  @data = @db.single(self.table, {:id => @id})
577
- raise Knj::Errors::NotFound, "Could not find any data for the object with ID: '#{@id}' in the table '#{self.table}'." if !@data
577
+ raise Errno::ENOENT, "Could not find any data for the object with ID: '#{@id}' in the table '#{self.table}'." if !@data
578
578
  @should_reload = false
579
579
  end
580
580
 
@@ -736,19 +736,19 @@ class Knj::Datarow
736
736
  method_name = "#{args[:col_name]}_str".to_sym
737
737
  if args[:inst_methods].index(method_name) == nil
738
738
  define_method(method_name) do |*method_args|
739
- if Knj::Datet.is_nullstamp?(self[args[:col_name].to_sym])
739
+ if Datet.is_nullstamp?(self[args[:col_name].to_sym])
740
740
  return @ob.events.call(:no_date, self.class.name)
741
741
  end
742
742
 
743
- return Knj::Datet.in(self[args[:col_name].to_sym]).out(*method_args)
743
+ return Datet.in(self[args[:col_name].to_sym]).out(*method_args)
744
744
  end
745
745
  end
746
746
 
747
747
  method_name = "#{args[:col_name]}".to_sym
748
748
  if args[:inst_methods].index(method_name) == nil
749
749
  define_method(method_name) do |*method_args|
750
- return false if Knj::Datet.is_nullstamp?(self[args[:col_name].to_sym])
751
- return Knj::Datet.in(self[args[:col_name].to_sym])
750
+ return false if Datet.is_nullstamp?(self[args[:col_name].to_sym])
751
+ return Datet.in(self[args[:col_name].to_sym])
752
752
  end
753
753
  end
754
754
  end
data/lib/knj/errors.rb CHANGED
@@ -3,21 +3,9 @@ module Knj::Errors
3
3
  #An error that is used when the error is just a notice.
4
4
  class Notice < StandardError; end
5
5
 
6
- #Typically used when an object is not found by the given arguments.
7
- class NotFound < StandardError; end
8
-
9
- #If invalid data was supplied to a list-method or something like it.
10
- class InvalidData < StandardError; end
11
-
12
6
  #An error that specifies that the caller should retry the operation.
13
7
  class Retry < StandardError; end
14
8
 
15
- #The current env does not have access to calling the method.
16
- class NoAccess < StandardError; end
17
-
18
- #The thing you are trying to add already exists or have already been done.
19
- class Exists < StandardError; end
20
-
21
9
  #Returns a string describing the given error. Possible arguments can be given if you want the returned string formatted as HTML.
22
10
  #
23
11
  #===Examples
@@ -16,7 +16,7 @@ class Knj::Facebook_connect
16
16
  end
17
17
 
18
18
  def get(http, url)
19
- resp = http.get(url)
19
+ resp = http.get(:url => url)
20
20
 
21
21
  if resp.body.length > 0
22
22
  begin
@@ -24,7 +24,7 @@ class Knj::Facebook_connect
24
24
 
25
25
  error_type = RuntimeError
26
26
  if jdata["error"] and jdata["error"]["message"] == "Code was invalid or expired. The session is invalid because the user logged out."
27
- error_type = Knj::Errors::InvalidData
27
+ error_type = ArgumentError
28
28
  end
29
29
 
30
30
  raise error_type, "#{jdata["error"]["type"]}: #{jdata["error"]["message"]}" if jdata["error"]
@@ -72,7 +72,7 @@ class Knj::Facebook_connect
72
72
  end
73
73
 
74
74
  def login(args = {})
75
- http = Knj::Http2.new(
75
+ http = Http2.new(
76
76
  :host => "graph.facebook.com",
77
77
  :ssl => true
78
78
  )
@@ -93,7 +93,7 @@ class Knj::Facebook_connect
93
93
  end
94
94
 
95
95
  def wall_post(args)
96
- http = Knj::Http2.new(
96
+ http = Http2.new(
97
97
  :host => "graph.facebook.com",
98
98
  :ssl => true
99
99
  )
@@ -108,7 +108,7 @@ class Knj::Facebook_connect
108
108
  end
109
109
  end
110
110
 
111
- res = http.post("/me/feed?access_token=#{atoken}", post_data)
111
+ res = http.post(:url => "/me/feed?access_token=#{atoken}", :post => post_data)
112
112
  raise res.body.to_s.strip if res.code.to_s != "200"
113
113
  end
114
114
  end
data/lib/knj/gtk2_tv.rb CHANGED
@@ -127,13 +127,13 @@ module Knj::Gtk2::Tv
127
127
  :datetime => {
128
128
  :value => proc{ |data|
129
129
  begin
130
- Knj::Datet.in(data[:value]).dbstr
131
- rescue Knj::Errors::InvalidData
130
+ Datet.in(data[:value]).dbstr
131
+ rescue ArgumentError
132
132
  raise "Invalid timestamp entered."
133
133
  end
134
134
  },
135
135
  :value_set => proc{ |data|
136
- Knj::Datet.in(data[:value]).out
136
+ Datet.in(data[:value]).out
137
137
  }
138
138
  },
139
139
  :time_as_sec => {
@@ -1,6 +1,6 @@
1
1
  #Containing various helper methods for Gtk2-windows.
2
2
  class Knj::Gtk2::Window
3
- require "wref"
3
+ require "wref" if !Kernel.const_defined?(:Wref)
4
4
  @@uniques = Wref_map.new
5
5
 
6
6
  #Used to make a window-instance unique. If it already exists when unique! is called, then it will pass focus to the existing window instead of yielding the block, which should contain code to create the window.
@@ -10,7 +10,9 @@ class KnjDB_mysql
10
10
  @escape_val = "'"
11
11
  @esc_table = "`"
12
12
  @esc_col = "`"
13
- @mutex = Mutex.new
13
+
14
+ require "monitor"
15
+ @mutex = Monitor.new
14
16
 
15
17
  if @opts[:encoding]
16
18
  @encoding = @opts[:encoding]
@@ -31,7 +31,7 @@ class KnjDB_mysql::Tables
31
31
  return table_obj if table_obj.name == table_name
32
32
  end
33
33
 
34
- raise Knj::Errors::NotFound.new("Table was not found: #{table_name}.")
34
+ raise Errno::ENOENT.new("Table was not found: #{table_name}.")
35
35
  end
36
36
 
37
37
  #Yields the tables of the current database.
@@ -103,7 +103,7 @@ class KnjDB_mysql::Tables
103
103
  end
104
104
 
105
105
  class KnjDB_mysql::Tables::Table
106
- attr_accessor :list
106
+ attr_reader :list
107
107
 
108
108
  def initialize(args)
109
109
  @args = args
@@ -160,7 +160,7 @@ class KnjDB_mysql::Tables::Table
160
160
  return col if col.name == name
161
161
  end
162
162
 
163
- raise Knj::Errors::NotFound.new("Column not found: '#{name}'.")
163
+ raise Errno::ENOENT.new("Column not found: '#{name}'.")
164
164
  end
165
165
 
166
166
  def columns(args = nil)
@@ -242,7 +242,7 @@ class KnjDB_mysql::Tables::Table
242
242
  return index if index.name.to_s == name
243
243
  end
244
244
 
245
- raise Knj::Errors::NotFound.new("Index not found: #{name}.")
245
+ raise Errno::ENOENT.new("Index not found: #{name}.")
246
246
  end
247
247
 
248
248
  def create_columns(col_arr)
@@ -23,7 +23,7 @@ class KnjDB_sqlite3::Tables
23
23
  return table_obj if table_obj.name.to_s == table_name.to_s
24
24
  end
25
25
 
26
- raise Knj::Errors::NotFound, "Table was not found: #{table_name}."
26
+ raise Errno::ENOENT, "Table was not found: #{table_name}."
27
27
  end
28
28
 
29
29
  def list
@@ -146,7 +146,7 @@ class KnjDB_sqlite3::Tables::Table
146
146
  def column(name)
147
147
  list = self.columns
148
148
  return list[name] if list[name]
149
- raise Knj::Errors::NotFound.new("Column not found: #{name}.")
149
+ raise Errno::ENOENT.new("Column not found: #{name}.")
150
150
  end
151
151
 
152
152
  def columns
@@ -324,7 +324,7 @@ class KnjDB_sqlite3::Tables::Table
324
324
  return index if index.name.to_s == name
325
325
  end
326
326
 
327
- raise Knj::Errors::NotFound.new("Index not found: #{name}.")
327
+ raise Errno::ENOENT.new("Index not found: #{name}.")
328
328
  end
329
329
 
330
330
  def indexes
@@ -1,8 +1,13 @@
1
+ require "rubygems"
2
+
1
3
  if !Kernel.const_defined?(:Wref)
2
- require "rubygems"
3
4
  require "wref"
4
5
  end
5
6
 
7
+ if !Kernel.const_defined?(:Datet)
8
+ require "datet"
9
+ end
10
+
6
11
  #A wrapper of several possible database-types.
7
12
  #
8
13
  #===Examples
@@ -333,7 +338,7 @@ class Knj::Db
333
338
  end
334
339
 
335
340
  #Convert dates to valid dbstr.
336
- value = self.date_out(value) if value.is_a?(Knj::Datet) or value.is_a?(Time)
341
+ value = self.date_out(value) if value.is_a?(Datet) or value.is_a?(Time)
337
342
 
338
343
  sql << "#{driver.escape_col}#{key.to_s}#{driver.escape_col} = "
339
344
  sql << "#{driver.escape_val}#{driver.escape(value.to_s)}#{driver.escape_val}"
@@ -678,17 +683,17 @@ class Knj::Db
678
683
  #Returns a string which can be used in SQL with the current driver.
679
684
  #===Examples
680
685
  # str = db.date_out(Time.now) #=> "2012-05-20 22:06:09"
681
- def date_out(date_obj = Knj::Datet.new, args = {})
686
+ def date_out(date_obj = Datet.new, args = {})
682
687
  conn_exec do |driver|
683
688
  if driver.respond_to?(:date_out)
684
689
  return driver.date_out(date_obj, args)
685
690
  end
686
691
  end
687
692
 
688
- return Knj::Datet.in(date_obj).dbstr(args)
693
+ return Datet.in(date_obj).dbstr(args)
689
694
  end
690
695
 
691
- #Takes a valid date-db-string and converts it into a Knj::Datet.
696
+ #Takes a valid date-db-string and converts it into a Datet.
692
697
  #===Examples
693
698
  # db.date_in('2012-05-20 22:06:09') #=> 2012-05-20 22:06:09 +0200
694
699
  def date_in(date_obj)
@@ -698,7 +703,7 @@ class Knj::Db
698
703
  end
699
704
  end
700
705
 
701
- return Knj::Datet.in(date_obj)
706
+ return Datet.in(date_obj)
702
707
  end
703
708
 
704
709
  #Returns the table-module and spawns it if it isnt already spawned.
@@ -27,7 +27,7 @@ class Knj::Db_row
27
27
  @data[@args[:col_id].to_sym] = @args[:id]
28
28
  self.reload
29
29
  else
30
- raise Knj::Errors::InvalidData.new("Invalid data: #{@args[:data].to_s} (#{@args[:data].class.to_s})")
30
+ raise ArgumentError.new("Invalid data: #{@args[:data].to_s} (#{@args[:data].class.to_s})")
31
31
  end
32
32
  end
33
33
 
@@ -54,7 +54,7 @@ class Knj::Db_row
54
54
  last_id = self.id
55
55
  data = self.db.single(@args[:table], {@args[:col_id] => self.id})
56
56
  if !data
57
- raise Knj::Errors::NotFound.new("Could not find any data for the object with ID: '#{last_id}' in the table '#{@args[:table].to_s}'.")
57
+ raise Errno::ENOENT.new("Could not find any data for the object with ID: '#{last_id}' in the table '#{@args[:table].to_s}'.")
58
58
  end
59
59
 
60
60
  @data = {}
@@ -151,7 +151,7 @@ class Knj::Db::Revision
151
151
  end
152
152
 
153
153
  first_col = false
154
- rescue Knj::Errors::NotFound => e
154
+ rescue Errno::ENOENT => e
155
155
  print "Column not found: #{table_obj.name}.#{col_data["name"]}.\n" if args["debug"]
156
156
 
157
157
  if col_data.has_key?("renames")
@@ -161,7 +161,7 @@ class Knj::Db::Revision
161
161
  col_data["renames"].each do |col_name|
162
162
  begin
163
163
  col_rename = table_obj.column(col_name)
164
- rescue Knj::Errors::NotFound => e
164
+ rescue Errno::ENOENT => e
165
165
  next
166
166
  end
167
167
 
@@ -202,7 +202,7 @@ class Knj::Db::Revision
202
202
  table_data["columns_remove"].each do |column_name, column_data|
203
203
  begin
204
204
  col_obj = table_obj.column(column_name)
205
- rescue Knj::Errors::NotFound => e
205
+ rescue Errno::ENOENT => e
206
206
  next
207
207
  end
208
208
 
@@ -227,7 +227,7 @@ class Knj::Db::Revision
227
227
  index_obj.drop
228
228
  table_obj.create_indexes([index_data])
229
229
  end
230
- rescue Knj::Errors::NotFound => e
230
+ rescue Errno::ENOENT => e
231
231
  table_obj.create_indexes([index_data])
232
232
  end
233
233
  end
@@ -237,7 +237,7 @@ class Knj::Db::Revision
237
237
  table_data["indexes_remove"].each do |index_name, index_data|
238
238
  begin
239
239
  index_obj = table_obj.index(index_name)
240
- rescue Knj::Errors::NotFound => e
240
+ rescue Errno::ENOENT => e
241
241
  next
242
242
  end
243
243
 
@@ -250,14 +250,14 @@ class Knj::Db::Revision
250
250
  end
251
251
 
252
252
  rows_init("db" => db, "table" => table_obj, "rows" => table_data["rows"]) if table_data and table_data["rows"]
253
- rescue Knj::Errors::NotFound => e
253
+ rescue Errno::ENOENT => e
254
254
  if table_data.key?("renames")
255
255
  table_data["renames"].each do |table_name_rename|
256
256
  begin
257
257
  table_rename = db.tables[table_name_rename.to_sym]
258
258
  table_rename.rename(table_name)
259
259
  raise Knj::Errors::Retry
260
- rescue Knj::Errors::NotFound
260
+ rescue Errno::ENOENT
261
261
  next
262
262
  end
263
263
  end
@@ -292,7 +292,7 @@ class Knj::Db::Revision
292
292
  table_obj = db.tables[table_name.to_sym]
293
293
  table_data["callback"].call("db" => db, "table" => table_obj) if table_data.is_a?(Hash) and table_data["callback"]
294
294
  table_obj.drop
295
- rescue Knj::Errors::NotFound => e
295
+ rescue Errno::ENOENT => e
296
296
  next
297
297
  end
298
298
  end
@@ -208,7 +208,7 @@ class Knj::Objects
208
208
 
209
209
  if args[:cols].key?(key)
210
210
  if val.is_a?(Array)
211
- if val.empty?
211
+ if val.empty? and db.opts[:type].to_s == "mysql"
212
212
  sql_where << " AND false"
213
213
  else
214
214
  escape_sql = Knj::ArrayExt.join(
@@ -312,7 +312,7 @@ class Knj::Objects
312
312
  found = true
313
313
  elsif args.key?(:cols_date) and match = key.match(/^(.+)_(day|week|month|year|from|to|below|above)(|_(not))$/) and args[:cols_date].index(match[1]) != nil
314
314
  not_v = match[4]
315
- val = Knj::Datet.in(val) if val.is_a?(Time)
315
+ val = Datet.in(val) if val.is_a?(Time)
316
316
 
317
317
  if match[2] == "day"
318
318
  if val.is_a?(Array)
data/lib/knj/objects.rb CHANGED
@@ -305,7 +305,7 @@ class Knj::Objects
305
305
  else
306
306
  return false
307
307
  end
308
- rescue Knj::Errors::NotFound
308
+ rescue Errno::ENOENT
309
309
  return false
310
310
  end
311
311
  end
@@ -323,7 +323,7 @@ class Knj::Objects
323
323
  elsif data.is_a?(Hash) and data.key?(@args[:col_id].to_s)
324
324
  id = data[@args[:col_id].to_s].to_i
325
325
  elsif
326
- raise Knj::Errors::InvalidData, "Unknown data: '#{data.class.to_s}'."
326
+ raise ArgumentError, "Unknown data: '#{data.class.to_s}'."
327
327
  end
328
328
 
329
329
  if @objects.key?(classname)
@@ -371,7 +371,7 @@ class Knj::Objects
371
371
  def get!(*args, &block)
372
372
  begin
373
373
  return self.get(*args, &block)
374
- rescue Knj::Errors::NotFound
374
+ rescue Errno::ENOENT
375
375
  return false
376
376
  end
377
377
  end
@@ -414,7 +414,7 @@ class Knj::Objects
414
414
 
415
415
  begin
416
416
  return self.get(obj_name, id_data)
417
- rescue Knj::Errors::NotFound
417
+ rescue Errno::ENOENT
418
418
  return false
419
419
  end
420
420
  end
@@ -469,9 +469,9 @@ class Knj::Objects
469
469
  id = obj[req_data[:col]]
470
470
 
471
471
  begin
472
- raise Knj::Errors::NotFound if !id
472
+ raise Errno::ENOENT if !id
473
473
  obj_req = self.get(req_data[:class], id)
474
- rescue Knj::Errors::NotFound
474
+ rescue Errno::ENOENT
475
475
  yielder << {:obj => obj, :type => :required, :id => id, :data => req_data}
476
476
  end
477
477
  end
data/lib/knj/php.rb CHANGED
@@ -168,8 +168,8 @@ module Knj::Php
168
168
  end
169
169
 
170
170
  retstr << "}\n"
171
- elsif cstr == "Time" or cstr == "Knj::Datet"
172
- argument = argument.time if cstr == "Knj::Datet"
171
+ elsif cstr == "Time" or cstr == "Datet"
172
+ argument = argument.time if cstr == "Datet"
173
173
  retstr << "#{cstr}::#{"%04d" % argument.year}-#{"%02d" % argument.month}-#{"%02d" % argument.day} #{"%02d" % argument.hour}:#{"%02d" % argument.min}:#{"%02d" % argument.sec}\n"
174
174
  else
175
175
  #print argument.to_s, "\n"
@@ -707,7 +707,7 @@ module Knj::Php
707
707
  month = cur_time.month if month == nil
708
708
  year = cur_time.year if year == nil
709
709
 
710
- new_time = Knj::Datet.in("#{year.to_s}-#{month.to_s}-#{date.to_s} #{hour.to_s}:#{min.to_s}:#{sec.to_s}")
710
+ new_time = Datet.in("#{year.to_s}-#{month.to_s}-#{date.to_s} #{hour.to_s}:#{min.to_s}:#{sec.to_s}")
711
711
  return new_time.to_i
712
712
  end
713
713
 
@@ -716,7 +716,7 @@ module Knj::Php
716
716
  date_object = Time.now
717
717
  elsif Knj::Php.is_numeric(date_input)
718
718
  date_object = Time.at(date_input.to_i)
719
- elsif date_input.is_a?(Knj::Datet)
719
+ elsif date_input.is_a?(Datet)
720
720
  date_object = date_input.time
721
721
  elsif date_input.is_a?(Time)
722
722
  date_object = date_input
@@ -100,7 +100,7 @@ end
100
100
  #Match catch exception handeling.
101
101
  cont.scan(/((\s+?)}\s*catch\s*\(\s*(#{regexes["class"]})\s+\$(#{regexes["var"]})\s*\)\s*{(\s+))/) do |match|
102
102
  classname = "#{match[2][0..0].upcase}#{match[2][1..999]}"
103
- classname = "Knj::Errors::NotFound" if classname == "Knjdb_rownotfound_exception"
103
+ classname = "Errno::ENOENT" if classname == "Knjdb_rownotfound_exception"
104
104
 
105
105
  rb_str = "#{match[1]}rescue #{classname} => #{match[3]}#{match[4]}"
106
106
  cont = cont.gsub(match[0], rb_str)
@@ -87,7 +87,7 @@ objects = {}
87
87
  res = nil
88
88
 
89
89
  begin
90
- raise Knj::Errors::NotFound, "No object by that name: '#{obj["var_name"]}' in '#{objects}'." if !objects.key?(obj["var_name"])
90
+ raise Errno::ENOENT, "No object by that name: '#{obj["var_name"]}' in '#{objects}'." if !objects.key?(obj["var_name"])
91
91
  obj_to_call = objects[obj["var_name"]]
92
92
  raise "No object by that name: '#{obj["var_name"]}'." if !obj
93
93
 
@@ -101,14 +101,14 @@ objects = {}
101
101
  end
102
102
  elsif obj["type"] == "unset"
103
103
  raise "Invalid var-name: '#{obj["var_name"]}'." if obj["var_name"].to_s.strip.length <= 0
104
- raise Knj::Errors::NotFound, "Var-name didnt exist when trying to unset: '#{obj["var_name"]}'." if !objects.key?(obj["var_name"])
104
+ raise Errno::ENOENT, "Var-name didnt exist when trying to unset: '#{obj["var_name"]}'." if !objects.key?(obj["var_name"])
105
105
  objects.delete(obj["var_name"])
106
106
  d.answer("type" => "unset_success")
107
107
  elsif obj["type"] == "unset_multiple"
108
108
  err = nil
109
109
  obj["var_names"].each do |var_name|
110
- err = [Knj::Errors::InvalidData, "Invalid var-name: '#{var_name}'."] if var_name.to_s.strip.length <= 0
111
- err = [Knj::Errors::NotFound, "Var-name didnt exist when trying to unset: '#{var_name}'."] if !objects.key?(var_name)
110
+ err = [ArgumentError, "Invalid var-name: '#{var_name}'."] if var_name.to_s.strip.length <= 0
111
+ err = [Errno::ENOENT, "Var-name didnt exist when trying to unset: '#{var_name}'."] if !objects.key?(var_name)
112
112
  objects.delete(var_name)
113
113
  end
114
114
 
data/lib/knj/strings.rb CHANGED
@@ -45,7 +45,7 @@ module Knj::Strings
45
45
  when "x"
46
46
  arg_two |= Regexp::EXTENDED
47
47
  when "U"
48
- raise Knj::Errors::InvalidData, "Ruby does (as far as I know) not support the 'U'-modifier. You should rewrite your regex with non-greedy operators such as '(\d+?)' instead for: '#{str}'."
48
+ raise ArgumentError, "Ruby does (as far as I know) not support the 'U'-modifier. You should rewrite your regex with non-greedy operators such as '(\d+?)' instead for: '#{str}'."
49
49
  else
50
50
  raise "Unknown argument: '#{arg}'."
51
51
  end