knjrbfw 0.0.72 → 0.0.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +4 -0
  3. data/VERSION +1 -1
  4. data/knjrbfw.gemspec +4 -3
  5. data/lib/knj/arrayext.rb +7 -5
  6. data/lib/knj/datarow.rb +6 -0
  7. data/lib/knj/datarow_custom.rb +4 -0
  8. data/lib/knj/datestamp.rb +4 -4
  9. data/lib/knj/degulesider.rb +1 -1
  10. data/lib/knj/erb/include.rb +1 -1
  11. data/lib/knj/fs/fs.rb +3 -3
  12. data/lib/knj/gtk2_menu.rb +1 -1
  13. data/lib/knj/hash_methods.rb +9 -0
  14. data/lib/knj/iotop.rb +1 -1
  15. data/lib/knj/ironruby-gtk2/gladexml.rb +1 -1
  16. data/lib/knj/jruby-gtk2/gladexml.rb +1 -1
  17. data/lib/knj/jruby-gtk2/tests/test_glade_window.rb +1 -1
  18. data/lib/knj/knj.rb +2 -2
  19. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3.rb +1 -1
  20. data/lib/knj/knjdb/libknjdb.rb +2 -2
  21. data/lib/knj/knjdb/libknjdb_row.rb +4 -0
  22. data/lib/knj/locales.rb +1 -1
  23. data/lib/knj/notify.rb +1 -1
  24. data/lib/knj/objects.rb +4 -4
  25. data/lib/knj/objects/objects_sqlhelper.rb +1 -1
  26. data/lib/knj/php_parser/php_parser.rb +1 -1
  27. data/lib/knj/php_parser/tests/test.rb +2 -2
  28. data/lib/knj/power_manager.rb +1 -1
  29. data/lib/knj/process.rb +1 -0
  30. data/lib/knj/scripts/ip2location.rb +2 -2
  31. data/lib/knj/scripts/php_to_rb_helper.rb +6 -6
  32. data/lib/knj/scripts/process_meta_exec.rb +1 -1
  33. data/lib/knj/sms.rb +3 -3
  34. data/lib/knj/strings.rb +3 -1
  35. data/lib/knj/table_writer.rb +4 -4
  36. data/lib/knj/tests/test_degulesider.rb +1 -1
  37. data/lib/knj/tests/test_http2.rb +1 -1
  38. data/lib/knj/tests/test_mount.rb +1 -1
  39. data/lib/knj/tests/test_retry.rb +1 -1
  40. data/lib/knj/unix_proc.rb +5 -0
  41. data/lib/knj/web.rb +11 -9
  42. data/spec/cmd_parser_spec.rb +2 -2
  43. data/spec/process_spec.rb +1 -1
  44. data/spec/web_spec.rb +1 -1
  45. metadata +23 -14
  46. data/lib/knj/php.rb +0 -978
  47. data/spec/php_spec.rb +0 -98
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gem "wref"
6
6
  gem "tsafe"
7
7
  gem "datet"
8
8
  gem "http2"
9
+ gem "php4r"
9
10
 
10
11
  # Add dependencies to develop your gem here.
11
12
  # Include everything needed to run rake, tests, features, etc.
@@ -9,6 +9,9 @@ GEM
9
9
  bundler (~> 1.0)
10
10
  git (>= 1.2.5)
11
11
  rake
12
+ php4r (0.0.0)
13
+ datet
14
+ http2
12
15
  rake (0.9.2.2)
13
16
  rmagick (2.13.1)
14
17
  rspec (2.3.0)
@@ -31,6 +34,7 @@ DEPENDENCIES
31
34
  datet
32
35
  http2
33
36
  jeweler (~> 1.6.3)
37
+ php4r
34
38
  rmagick
35
39
  rspec (~> 2.3.0)
36
40
  sqlite3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.72
1
+ 0.0.74
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjrbfw}
8
- s.version = "0.0.72"
8
+ s.version = "0.0.74"
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"]
@@ -198,7 +198,6 @@ Gem::Specification.new do |s|
198
198
  "lib/knj/objects/objects_sqlhelper.rb",
199
199
  "lib/knj/opts.rb",
200
200
  "lib/knj/os.rb",
201
- "lib/knj/php.rb",
202
201
  "lib/knj/php_parser/arguments.rb",
203
202
  "lib/knj/php_parser/functions.rb",
204
203
  "lib/knj/php_parser/php_parser.rb",
@@ -259,7 +258,6 @@ Gem::Specification.new do |s|
259
258
  "spec/db_spec_encoding_test_file.txt",
260
259
  "spec/knjrbfw_spec.rb",
261
260
  "spec/objects_spec.rb",
262
- "spec/php_spec.rb",
263
261
  "spec/process_meta_spec.rb",
264
262
  "spec/process_spec.rb",
265
263
  "spec/spec_helper.rb",
@@ -281,6 +279,7 @@ Gem::Specification.new do |s|
281
279
  s.add_runtime_dependency(%q<tsafe>, [">= 0"])
282
280
  s.add_runtime_dependency(%q<datet>, [">= 0"])
283
281
  s.add_runtime_dependency(%q<http2>, [">= 0"])
282
+ s.add_runtime_dependency(%q<php4r>, [">= 0"])
284
283
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
285
284
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
286
285
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.3"])
@@ -291,6 +290,7 @@ Gem::Specification.new do |s|
291
290
  s.add_dependency(%q<tsafe>, [">= 0"])
292
291
  s.add_dependency(%q<datet>, [">= 0"])
293
292
  s.add_dependency(%q<http2>, [">= 0"])
293
+ s.add_dependency(%q<php4r>, [">= 0"])
294
294
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
295
295
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
296
296
  s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
@@ -302,6 +302,7 @@ Gem::Specification.new do |s|
302
302
  s.add_dependency(%q<tsafe>, [">= 0"])
303
303
  s.add_dependency(%q<datet>, [">= 0"])
304
304
  s.add_dependency(%q<http2>, [">= 0"])
305
+ s.add_dependency(%q<php4r>, [">= 0"])
305
306
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
306
307
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
307
308
  s.add_dependency(%q<jeweler>, ["~> 1.6.3"])
@@ -1,3 +1,5 @@
1
+ require "php4r"
2
+
1
3
  module Knj::ArrayExt
2
4
  def self.join(args = {}, key = nil, sep = nil)
3
5
  if args.is_a?(Array) and sep
@@ -13,7 +15,7 @@ module Knj::ArrayExt
13
15
  str = ""
14
16
  first = true
15
17
 
16
- Knj::Php.foreach(args[:arr]) do |key, value|
18
+ Php4r.foreach(args[:arr]) do |key, value|
17
19
  if first
18
20
  first = false
19
21
  else
@@ -30,7 +32,7 @@ module Knj::ArrayExt
30
32
  if args[:callback].is_a?(Proc) or args[:callback].is_a?(Method)
31
33
  value = args[:callback].call(value)
32
34
  else
33
- value = Knj::Php.call_user_func(args[:callback], value) if args[:callback]
35
+ value = Php4r.call_user_func(args[:callback], value) if args[:callback]
34
36
  end
35
37
  end
36
38
 
@@ -58,7 +60,7 @@ module Knj::ArrayExt
58
60
  def self.hash_numeric_keys?(hash)
59
61
  all_num = true
60
62
  hash.each do |key, val|
61
- if !Knj::Php.is_numeric(key)
63
+ if !Php4r.is_numeric(key)
62
64
  all_num = false
63
65
  break
64
66
  end
@@ -212,10 +214,10 @@ module Knj::ArrayExt
212
214
  return hash if !hash
213
215
 
214
216
  hash = hash.clone
215
- Knj::Php.foreach(hash) do |key, val|
217
+ Php4r.foreach(hash) do |key, val|
216
218
  if val.is_a?(String)
217
219
  begin
218
- hash[key] = Knj::Php.utf8_encode(val)
220
+ hash[key] = Php4r.utf8_encode(val)
219
221
  rescue Encoding::UndefinedConversionError => e
220
222
  if args["ignore_encoding_errors"]
221
223
  next
@@ -732,6 +732,12 @@ class Knj::Datarow
732
732
  return @data.each(*args, &block)
733
733
  end
734
734
 
735
+ #Hash-compatible.
736
+ def to_hash
737
+ self.reload if @should_reload
738
+ return @data.clone
739
+ end
740
+
735
741
  #Returns a default-URL to show the object.
736
742
  def url
737
743
  cname = self.class.classname.to_s.downcase
@@ -146,4 +146,8 @@ class Knj::Datarow_custom
146
146
  def each(&args)
147
147
  return @data.each(&args)
148
148
  end
149
+
150
+ def to_hash
151
+ return @data.clone
152
+ end
149
153
  end
@@ -1,6 +1,6 @@
1
1
  class Knj::Datestamp
2
2
  def self.in(time = Time.new)
3
- if Knj::Php.is_numeric(time)
3
+ if Php4r.is_numeric(time)
4
4
  time = Time.at(time.to_i)
5
5
  elsif time.is_a?(String)
6
6
  time = Time.local(*ParseDate.parsedate(time))
@@ -14,7 +14,7 @@ class Knj::Datestamp
14
14
  time = Time.new
15
15
  end
16
16
 
17
- if Knj::Php.is_numeric(time)
17
+ if Php4r.is_numeric(time)
18
18
  time = Time.at(time.to_i)
19
19
  elsif time.is_a?(String)
20
20
  begin
@@ -42,10 +42,10 @@ class Knj::Datestamp
42
42
 
43
43
  time = Time.new if !time
44
44
 
45
- if Knj::Php.is_numeric(time)
45
+ if Php4r.is_numeric(time)
46
46
  time = Time.at(time.to_i)
47
47
  elsif time.is_a?(String)
48
- time = Time.at(Knj::Php.strtotime(time))
48
+ time = Time.at(Php4r.strtotime(time))
49
49
  end
50
50
 
51
51
  str = ""
@@ -7,7 +7,7 @@ class Knj::Degulesider
7
7
  end
8
8
 
9
9
  def search(sargs)
10
- url = "/search/#{Knj::Php.urlencode(sargs[:where])}/-/1/"
10
+ url = "/search/#{Php4r.urlencode(sargs[:where])}/-/1/"
11
11
 
12
12
  html = @http.get(url)
13
13
  ret = []
@@ -30,7 +30,7 @@ class ERuby
30
30
  Dir.chdir(File.dirname(filename))
31
31
 
32
32
  fpath = "#{KnjEruby.filepath}/cache/#{filename.gsub("/", "_").gsub(".", "_")}"
33
- pi = Knj::Php.pathinfo(filename)
33
+ pi = Php4r.pathinfo(filename)
34
34
  cachename = fpath + ".cache"
35
35
 
36
36
  filetime = File.mtime(filename)
@@ -1,11 +1,11 @@
1
1
  class Knj::Fs
2
2
  @drivers = []
3
- drivers_path = Knj::Php.realpath("#{File.dirname(__FILE__)}/drivers")
3
+ drivers_path = Php4r.realpath("#{File.dirname(__FILE__)}/drivers")
4
4
  Dir.new(drivers_path).each do |file|
5
5
  fn = "#{drivers_path}/#{file}"
6
6
  next if file == "." or file == ".." or File.directory?(fn)
7
7
 
8
- class_name = Knj::Php.ucwords(file.slice(0..-4)).to_sym
8
+ class_name = Php4r.ucwords(file.slice(0..-4)).to_sym
9
9
  print "Classname: #{class_name}\n"
10
10
  autoload class_name, fn
11
11
 
@@ -24,7 +24,7 @@ class Knj::Fs
24
24
  end
25
25
 
26
26
  def spawn_driver
27
- class_name = Knj::Php.ucwords(@args[:driver])
27
+ class_name = Php4r.ucwords(@args[:driver])
28
28
  @driver = self.class.const_get(class_name).new(:fs => self, :args => @args)
29
29
  end
30
30
  end
@@ -26,7 +26,7 @@ class Knj::Gtk2::Menu
26
26
 
27
27
  if menuitem["connect"]
28
28
  newitem.signal_connect("activate") do
29
- Knj::Php.call_user_func(menuitem["connect"])
29
+ Php4r.call_user_func(menuitem["connect"])
30
30
  end
31
31
  else
32
32
  newitem.signal_connect("activate") do
@@ -28,6 +28,15 @@ class Knj::Hash_methods < Hash
28
28
  return self[:data]
29
29
  end
30
30
 
31
+ def to_hash
32
+ h = {}
33
+ self.each do |key, val|
34
+ h[k] = val
35
+ end
36
+
37
+ return h
38
+ end
39
+
31
40
  #Proxies methods into the hash as keys.
32
41
  def method_missing(method, *args)
33
42
  method = method.to_sym
@@ -26,7 +26,7 @@ class Knj::Iotop
26
26
 
27
27
  if match[12].index("bestseller") != nil
28
28
  print line_str + "\n"
29
- Knj::Php.print_r(match)
29
+ Php4r.print_r(match)
30
30
  end
31
31
 
32
32
  @data[pid] = {
@@ -14,7 +14,7 @@ class GladeXML
14
14
  @cont = filename
15
15
  @data = XmlSimple.xml_in(@cont)
16
16
  window_name = self.find_window(data)
17
- Knj::Php.file_put_contents("temp.glade", @cont)
17
+ Php4r.file_put_contents("temp.glade", @cont)
18
18
  @glade = Glade::XML.new("temp.glade", window_name, nil)
19
19
  FileUtils.rm("temp.glade")
20
20
  end
@@ -14,7 +14,7 @@ class GladeXML
14
14
  cont = filename
15
15
  @data = XmlSimple.xml_in(cont)
16
16
  window_name = self.find_window(data)
17
- Knj::Php.file_put_contents("temp.glade", cont)
17
+ Php4r.file_put_contents("temp.glade", cont)
18
18
  @glade = org.gnome.glade.Glade::parse("temp.glade", window_name)
19
19
  FileUtils.rm("temp.glade")
20
20
  end
@@ -28,7 +28,7 @@ class WinAppEdit
28
28
  print "Save clicked.\n"
29
29
 
30
30
  val = @glade["tvTest"].sel
31
- Knj::Php.print_r(val)
31
+ Php4r.print_r(val)
32
32
  end
33
33
 
34
34
  def on_btnCancel_clicked
@@ -30,9 +30,9 @@ module Knj
30
30
  return File.realpath(File.dirname(__FILE__))
31
31
  end
32
32
 
33
- #Shortcut to Knj::Php.print_r.
33
+ #Shortcut to Php4r.print_r.
34
34
  def self.p(*args, &block)
35
- return Knj::Php.print_r(*args, &block)
35
+ return Php4r.print_r(*args, &block)
36
36
  end
37
37
 
38
38
  def self.handle_return(args)
@@ -163,7 +163,7 @@ class KnjDB_sqlite3_result
163
163
 
164
164
  ret = {}
165
165
  result_hash.each do |key, val|
166
- if Knj::Php::is_numeric(key)
166
+ if Php4r.is_numeric(key)
167
167
  #do nothing.
168
168
  elsif @symbols and !key.is_a?(Symbol)
169
169
  ret[key.to_sym] = val
@@ -401,8 +401,8 @@ class Knj::Db
401
401
  end
402
402
 
403
403
  if args["limit_from"] and args["limit_to"]
404
- raise "'limit_from' was not numeric: '#{args["limit_from"]}'." if !Knj::Php.is_numeric(args["limit_from"])
405
- raise "'limit_to' was not numeric: '#{args["limit_to"]}'." if !Knj::Php.is_numeric(args["limit_to"])
404
+ raise "'limit_from' was not numeric: '#{args["limit_from"]}'." if !Php4r.is_numeric(args["limit_from"])
405
+ raise "'limit_to' was not numeric: '#{args["limit_to"]}'." if !Php4r.is_numeric(args["limit_to"])
406
406
  sql << " LIMIT #{args["limit_from"]}, #{args["limit_to"]}"
407
407
  end
408
408
  end
@@ -130,6 +130,10 @@ class Knj::Db_row
130
130
  return @data.each(&args)
131
131
  end
132
132
 
133
+ def to_hash
134
+ return @data.clone
135
+ end
136
+
133
137
  def esc(str)
134
138
  return self.db.escape(str)
135
139
  end
@@ -51,7 +51,7 @@ module Knj::Locales
51
51
  # Knj::Locales.number_out(123456.68) #=> "123,456.68"
52
52
  def self.number_out(num_str, dec = 2)
53
53
  lc = Knj::Locales.localeconv
54
- return Knj::Php.number_format(num_str, dec, lc["decimal_point"], lc["thousands_sep"])
54
+ return Php4r.number_format(num_str, dec, lc["decimal_point"], lc["thousands_sep"])
55
55
  end
56
56
 
57
57
  #Returns the current locale for the current environment (_session[:locale] or Thread.current[:locale]).
@@ -26,7 +26,7 @@ class Knj::Notify
26
26
  cmd = "notify-send"
27
27
 
28
28
  if args["time"]
29
- raise "Time is not numeric." if !Knj::Php.is_numeric(args["time"])
29
+ raise "Time is not numeric." if !Php4r.is_numeric(args["time"])
30
30
  cmd << " -t #{args["time"]}"
31
31
  end
32
32
 
@@ -41,7 +41,7 @@ class Knj::Objects
41
41
  file_parsed = file
42
42
  file_parsed.gsub!(@args[:class_pre], "") if @args.key?(:class_pre)
43
43
  file_parsed.gsub!(/\.rb$/, "")
44
- file_parsed = Knj::Php.ucwords(file_parsed)
44
+ file_parsed = Php4r.ucwords(file_parsed)
45
45
 
46
46
  loads << file_parsed
47
47
  self.requireclass(file_parsed, {:load => false})
@@ -186,7 +186,7 @@ class Knj::Objects
186
186
 
187
187
  callback["block"].call(*callargs)
188
188
  elsif callback["callback"]
189
- Knj::Php.call_user_func(callback["callback"], args)
189
+ Php4r.call_user_func(callback["callback"], args)
190
190
  else
191
191
  raise "No valid callback given."
192
192
  end
@@ -403,7 +403,7 @@ class Knj::Objects
403
403
  def get_try(obj, col_name, obj_name = nil)
404
404
  if !obj_name
405
405
  if match = col_name.to_s.match(/^(.+)_id$/)
406
- obj_name = Knj::Php.ucwords(match[1]).to_sym
406
+ obj_name = Php4r.ucwords(match[1]).to_sym
407
407
  else
408
408
  raise "Could not figure out objectname for: #{col_name}."
409
409
  end
@@ -557,7 +557,7 @@ class Knj::Objects
557
557
  list_args = {}
558
558
  end
559
559
 
560
- if RUBY_VERSION[0..2] == 1.8 and Knj::Php.class_exists("Dictionary")
560
+ if RUBY_VERSION[0..2] == 1.8 and Php4r.class_exists("Dictionary")
561
561
  list = Dictionary.new
562
562
  else
563
563
  list = {}
@@ -109,7 +109,7 @@ class Knj::Objects
109
109
  end
110
110
  end
111
111
 
112
- raise "No such joined table on '#{args[:table]}': '#{col.first}' (#{col.first.class.name}) with the following joined table:\n#{Knj::Php.print_r(args[:joined_tables], true)}" if !found
112
+ raise "No such joined table on '#{args[:table]}': '#{col.first}' (#{col.first.class.name}) with the following joined table:\n#{Php4r.print_r(args[:joined_tables], true)}" if !found
113
113
  elsif col.is_a?(String) or col.is_a?(Symbol)
114
114
  col_str = "#{table_def}`#{col}`"
115
115
  found = true
@@ -7,7 +7,7 @@ class Knj::Php_parser
7
7
 
8
8
  if !args.key?("require_requirements") or args["require_requirements"]
9
9
  @retcont = "require \"knj/autoload\"\n"
10
- @retcont << "require \"knj/php\"\n"
10
+ @retcont << "require \"php4r\"\n"
11
11
  @retcont << "require \"knj/php_parser/php_parser\"\n"
12
12
  @retcont << "\n"
13
13
  else
@@ -4,8 +4,8 @@ require "#{$knjpath}php_parser/php_parser"
4
4
 
5
5
  module Knj::Php_parser::Functions
6
6
  def self.my_function(phpvar_arg)
7
- Knj::Php.print("Hejsa.\n")
8
- Knj::Php.print(phpvar_arg + "\n")
7
+ Php4r.print("Hejsa.\n")
8
+ Php4r.print(phpvar_arg + "\n")
9
9
  end
10
10
  end
11
11
  Knj::Php_parser::Functions.my_function("Helloworld.")
@@ -11,7 +11,7 @@ class Knj::Power_manager
11
11
  fn = "/proc/acpi/ac_adapter/#{file}"
12
12
 
13
13
  if File.directory?(fn)
14
- @ac_folder = Knj::Php.realpath(fn)
14
+ @ac_folder = Php4r.realpath(fn)
15
15
  break
16
16
  end
17
17
  end
@@ -1,5 +1,6 @@
1
1
  require "#{$knjpath}errors"
2
2
  require "#{$knjpath}thread"
3
+ require "tsafe"
3
4
 
4
5
  #This class is able to control communicate with another Ruby-process also running Knj::Process.
5
6
  class Knj::Process
@@ -6,7 +6,7 @@ ip2loc = Knj::Ip2location.new
6
6
  data = ip2loc.lookup(ARGV[0])
7
7
 
8
8
  if ARGV[1] == "json"
9
- print Knj::Php.json_encode(data)
9
+ print Php4r.json_encode(data)
10
10
  else
11
- Knj::Php.print_r(data)
11
+ Php4r.print_r(data)
12
12
  end