knjrbfw 0.0.32 → 0.0.33
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.
- data/Gemfile +2 -0
- data/Gemfile.lock +38 -0
- data/VERSION +1 -1
- data/knjrbfw.gemspec +11 -4
- data/lib/knj/autoload/wref.rb +6 -0
- data/lib/knj/autoload.rb +5 -3
- data/lib/knj/datarow.rb +74 -37
- data/lib/knj/errors.rb +5 -2
- data/lib/knj/http2.rb +8 -2
- data/lib/knj/knj.rb +0 -2
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb +22 -4
- data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb +6 -8
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3.rb +1 -1
- data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb +6 -8
- data/lib/knj/knjdb/libknjdb.rb +27 -20
- data/lib/knj/knjdb/revision.rb +1 -1
- data/lib/knj/objects.rb +194 -109
- data/lib/knj/threadhandler.rb +2 -1
- data/lib/knj/unix_proc.rb +3 -3
- data/spec/datet_spec.rb +43 -0
- data/spec/knjrbfw_spec.rb +0 -290
- data/spec/objects_spec.rb +274 -0
- data/spec/php_spec.rb +28 -7
- data/spec/process_spec.rb +7 -1
- data/spec/web_spec.rb +61 -0
- metadata +40 -17
- data/lib/knj/wref.rb +0 -251
- data/spec/wref_spec.rb +0 -10
data/spec/web_spec.rb
CHANGED
@@ -13,4 +13,65 @@ describe "Web" do
|
|
13
13
|
raise "'trala' in 'second' wasnt a hash or contained invalid amount of elements." if !res["second"]["trala"].is_a?(Hash) or res["second"]["trala"].length != 3
|
14
14
|
raise "'trala' in 'second' didnt contain the right elements." if res["second"]["trala"]["0"] != "1" or res["second"]["trala"]["1"] != "2" or res["second"]["trala"]["2"] != "3"
|
15
15
|
end
|
16
|
+
|
17
|
+
#Moved from "knjrbfw_spec.rb".
|
18
|
+
it "should be able to use alert and back." do
|
19
|
+
Knj::Web.alert("Trala")
|
20
|
+
|
21
|
+
begin
|
22
|
+
Knj::Web.back
|
23
|
+
raise "It should have called exit which it didnt."
|
24
|
+
rescue SystemExit
|
25
|
+
#ignore.
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
Knj::Web.redirect("?show=test")
|
30
|
+
raise "It should have called exit which it didnt."
|
31
|
+
rescue SystemExit
|
32
|
+
#ignore.
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to properly parse 'Set-Cookie' headers." do
|
37
|
+
data = Knj::Web.parse_set_cookies("TestCookie=TestValue+; Expires=Fri, 05 Aug 2011 10:58:17 GMT; Path=\n")
|
38
|
+
|
39
|
+
raise "No data returned?" if !data or !data.respond_to?(:length)
|
40
|
+
raise "Wrong number of cookies returned: '#{data.length}'." if data.length != 1
|
41
|
+
|
42
|
+
raise "Unexpected name: '#{data[0]["name"]}'." if data[0]["name"] != "TestCookie"
|
43
|
+
raise "Unexpected value: '#{data[0]["value"]}'." if data[0]["value"] != "TestValue "
|
44
|
+
raise "Unexpected path: '#{data[0]["path"]}'." if data[0]["path"] != ""
|
45
|
+
raise "Unexpected expire:' #{data[0]["expire"]}'." if data[0]["expires"] != "Fri, 05 Aug 2011 10:58:17 GMT"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be able to execute various forms of Web.input methods." do
|
49
|
+
html = Knj::Web.inputs([{
|
50
|
+
:title => "Test 1",
|
51
|
+
:name => :textest1,
|
52
|
+
:type => :text,
|
53
|
+
:default => "hmm",
|
54
|
+
:value => "trala"
|
55
|
+
},{
|
56
|
+
:title => "Test 2",
|
57
|
+
:name => :chetest2,
|
58
|
+
:type => :checkbox,
|
59
|
+
:default => true
|
60
|
+
},{
|
61
|
+
:title => "Test 4",
|
62
|
+
:name => :textest4,
|
63
|
+
:type => :textarea,
|
64
|
+
:height => 300,
|
65
|
+
:default => "Hmm",
|
66
|
+
:value => "Trala"
|
67
|
+
},{
|
68
|
+
:title => "Test 5",
|
69
|
+
:name => :filetest5,
|
70
|
+
:type => :file
|
71
|
+
},{
|
72
|
+
:title => "Test 6",
|
73
|
+
:type => :info,
|
74
|
+
:value => "Argh"
|
75
|
+
}])
|
76
|
+
end
|
16
77
|
end
|
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.33
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -10,12 +10,34 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-18 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
17
|
+
name: wref
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tsafe
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
19
41
|
none: false
|
20
42
|
requirements:
|
21
43
|
- - ~>
|
@@ -23,10 +45,10 @@ dependencies:
|
|
23
45
|
version: 2.3.0
|
24
46
|
type: :development
|
25
47
|
prerelease: false
|
26
|
-
version_requirements: *
|
48
|
+
version_requirements: *id003
|
27
49
|
- !ruby/object:Gem::Dependency
|
28
50
|
name: bundler
|
29
|
-
requirement: &
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
30
52
|
none: false
|
31
53
|
requirements:
|
32
54
|
- - ">="
|
@@ -34,10 +56,10 @@ dependencies:
|
|
34
56
|
version: 1.0.0
|
35
57
|
type: :development
|
36
58
|
prerelease: false
|
37
|
-
version_requirements: *
|
59
|
+
version_requirements: *id004
|
38
60
|
- !ruby/object:Gem::Dependency
|
39
61
|
name: jeweler
|
40
|
-
requirement: &
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
41
63
|
none: false
|
42
64
|
requirements:
|
43
65
|
- - ~>
|
@@ -45,10 +67,10 @@ dependencies:
|
|
45
67
|
version: 1.6.3
|
46
68
|
type: :development
|
47
69
|
prerelease: false
|
48
|
-
version_requirements: *
|
70
|
+
version_requirements: *id005
|
49
71
|
- !ruby/object:Gem::Dependency
|
50
72
|
name: rcov
|
51
|
-
requirement: &
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
52
74
|
none: false
|
53
75
|
requirements:
|
54
76
|
- - ">="
|
@@ -56,10 +78,10 @@ dependencies:
|
|
56
78
|
version: "0"
|
57
79
|
type: :development
|
58
80
|
prerelease: false
|
59
|
-
version_requirements: *
|
81
|
+
version_requirements: *id006
|
60
82
|
- !ruby/object:Gem::Dependency
|
61
83
|
name: sqlite3
|
62
|
-
requirement: &
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
63
85
|
none: false
|
64
86
|
requirements:
|
65
87
|
- - ">="
|
@@ -67,10 +89,10 @@ dependencies:
|
|
67
89
|
version: "0"
|
68
90
|
type: :development
|
69
91
|
prerelease: false
|
70
|
-
version_requirements: *
|
92
|
+
version_requirements: *id007
|
71
93
|
- !ruby/object:Gem::Dependency
|
72
94
|
name: rmagick
|
73
|
-
requirement: &
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
74
96
|
none: false
|
75
97
|
requirements:
|
76
98
|
- - ">="
|
@@ -78,7 +100,7 @@ dependencies:
|
|
78
100
|
version: "0"
|
79
101
|
type: :development
|
80
102
|
prerelease: false
|
81
|
-
version_requirements: *
|
103
|
+
version_requirements: *id008
|
82
104
|
description: Including stuff for HTTP, SSH and much more.
|
83
105
|
email: k@spernj.org
|
84
106
|
executables: []
|
@@ -92,6 +114,7 @@ files:
|
|
92
114
|
- .document
|
93
115
|
- .rspec
|
94
116
|
- Gemfile
|
117
|
+
- Gemfile.lock
|
95
118
|
- LICENSE.txt
|
96
119
|
- README.rdoc
|
97
120
|
- Rakefile
|
@@ -122,6 +145,7 @@ files:
|
|
122
145
|
- lib/knj/autoload/sqlite3.rb
|
123
146
|
- lib/knj/autoload/tmail.rb
|
124
147
|
- lib/knj/autoload/tzinfo.rb
|
148
|
+
- lib/knj/autoload/wref.rb
|
125
149
|
- lib/knj/autoload/xmlsimple.rb
|
126
150
|
- lib/knj/autoload/zip.rb
|
127
151
|
- lib/knj/cmd_gen.rb
|
@@ -314,7 +338,6 @@ files:
|
|
314
338
|
- lib/knj/win.rb
|
315
339
|
- lib/knj/win_registry.rb
|
316
340
|
- lib/knj/win_tightvnc.rb
|
317
|
-
- lib/knj/wref.rb
|
318
341
|
- lib/knj/x11vnc.rb
|
319
342
|
- lib/knj/youtube.rb
|
320
343
|
- lib/knjrbfw.rb
|
@@ -325,6 +348,7 @@ files:
|
|
325
348
|
- spec/db_spec_encoding_test_file.txt
|
326
349
|
- spec/http2_spec.rb
|
327
350
|
- spec/knjrbfw_spec.rb
|
351
|
+
- spec/objects_spec.rb
|
328
352
|
- spec/php_spec.rb
|
329
353
|
- spec/process_meta_spec.rb
|
330
354
|
- spec/process_spec.rb
|
@@ -332,7 +356,6 @@ files:
|
|
332
356
|
- spec/strings_spec.rb
|
333
357
|
- spec/threadsafe_spec.rb
|
334
358
|
- spec/web_spec.rb
|
335
|
-
- spec/wref_spec.rb
|
336
359
|
- testfiles/image.jpg
|
337
360
|
has_rdoc: true
|
338
361
|
homepage: http://github.com/kaspernj/knjrbfw
|
@@ -348,7 +371,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
348
371
|
requirements:
|
349
372
|
- - ">="
|
350
373
|
- !ruby/object:Gem::Version
|
351
|
-
hash:
|
374
|
+
hash: 2685186522234907408
|
352
375
|
segments:
|
353
376
|
- 0
|
354
377
|
version: "0"
|
data/lib/knj/wref.rb
DELETED
@@ -1,251 +0,0 @@
|
|
1
|
-
#A simple weak-reference framework with mapping. Only handles the referencing of objects.
|
2
|
-
#===Examples
|
3
|
-
# user_obj = ob.get(:User, 1)
|
4
|
-
# weak_ref = Knj::Wref(user_obj)
|
5
|
-
# user_obj = nil
|
6
|
-
# sleep 0.5
|
7
|
-
# GC.start
|
8
|
-
#
|
9
|
-
# begin
|
10
|
-
# user_obj = weak_ref.get
|
11
|
-
# print "The user still exists in memory and has ID #{user.id}."
|
12
|
-
# rescue Knj::Wref::Recycled
|
13
|
-
# print "The user has been removed from memory."
|
14
|
-
# end
|
15
|
-
class Knj::Wref
|
16
|
-
#Returns the classname of the object.
|
17
|
-
attr_reader :class_name
|
18
|
-
|
19
|
-
#Returns the object-ID which is used to look up the ObjectSpace (if not running JRuby).
|
20
|
-
attr_reader :id
|
21
|
-
|
22
|
-
#Initializes various variables.
|
23
|
-
def initialize(obj)
|
24
|
-
@id = obj.__id__
|
25
|
-
|
26
|
-
if RUBY_ENGINE == "jruby"
|
27
|
-
require "java"
|
28
|
-
@weakref = java.lang.ref.WeakReference.new(obj)
|
29
|
-
else
|
30
|
-
@class_name = obj.class.name.to_sym
|
31
|
-
|
32
|
-
if obj.respond_to?("__object_unique_id__")
|
33
|
-
@unique_id = obj.__object_unique_id__
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
#Returns the object that this weak reference holds or raises Knj::Wref::Recycled.
|
39
|
-
# begin
|
40
|
-
# obj = wref.get
|
41
|
-
# print "Object still exists in memory."
|
42
|
-
# rescue Knj::Wref::Recycled
|
43
|
-
# print "Object has been garbage-collected."
|
44
|
-
# end
|
45
|
-
def get
|
46
|
-
begin
|
47
|
-
raise Knj::Wref::Recycled if !@class_name or !@id
|
48
|
-
|
49
|
-
if RUBY_ENGINE == "jruby"
|
50
|
-
obj = @weakref.get
|
51
|
-
|
52
|
-
if obj == nil
|
53
|
-
raise Knj::Wref::Recycled
|
54
|
-
else
|
55
|
-
return obj
|
56
|
-
end
|
57
|
-
else
|
58
|
-
obj = ObjectSpace._id2ref(@id)
|
59
|
-
end
|
60
|
-
|
61
|
-
#Some times this class-name will be nil for some reason - knj
|
62
|
-
obj_class_name = obj.class.name
|
63
|
-
|
64
|
-
if !obj_class_name or @class_name != obj_class_name.to_sym or @id != obj.__id__
|
65
|
-
raise Knj::Wref::Recycled
|
66
|
-
end
|
67
|
-
|
68
|
-
if @unique_id
|
69
|
-
if !obj.respond_to?("__object_unique_id__") or obj.__object_unique_id__ != @unique_id
|
70
|
-
raise Knj::Wref::Recycled
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
return obj
|
75
|
-
rescue RangeError, TypeError
|
76
|
-
raise Knj::Wref::Recycled
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
#Returns true if the reference is still alive.
|
81
|
-
# print "The object still exists in memory." if wref.alive?
|
82
|
-
def alive?
|
83
|
-
begin
|
84
|
-
self.get
|
85
|
-
return true
|
86
|
-
rescue Knj::Wref::Recycled
|
87
|
-
return false
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
#Makes Wref compatible with the normal WeakRef.
|
92
|
-
alias weakref_alive? alive?
|
93
|
-
alias __getobj__ get
|
94
|
-
end
|
95
|
-
|
96
|
-
#A weak hash-map.
|
97
|
-
#===Examples
|
98
|
-
# map = Knj::Wref_map.new
|
99
|
-
# map[1] = obj
|
100
|
-
# obj = nil
|
101
|
-
#
|
102
|
-
# sleep 0.5
|
103
|
-
#
|
104
|
-
# begin
|
105
|
-
# obj = map[1]
|
106
|
-
# print "Object still exists in memory."
|
107
|
-
# rescue Knj::Wref::Recycled
|
108
|
-
# print "Object has been garbage-collected."
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# obj = map.get!(1)
|
112
|
-
# print "Object still exists in memory." if obj
|
113
|
-
class Knj::Wref_map
|
114
|
-
def initialize(args = nil)
|
115
|
-
@map = {}
|
116
|
-
@ids = {}
|
117
|
-
@mutex = Mutex.new
|
118
|
-
end
|
119
|
-
|
120
|
-
#Sets a new object in the map with a given ID.
|
121
|
-
def set(id, obj)
|
122
|
-
wref = Knj::Wref.new(obj)
|
123
|
-
|
124
|
-
@mutex.synchronize do
|
125
|
-
@map[id] = wref
|
126
|
-
@ids[obj.__id__] = id
|
127
|
-
end
|
128
|
-
|
129
|
-
#JRuby cant handle this atm... Dunno why...
|
130
|
-
if RUBY_ENGINE != "jruby"
|
131
|
-
ObjectSpace.define_finalizer(obj, self.method("delete_by_id"))
|
132
|
-
end
|
133
|
-
|
134
|
-
return nil
|
135
|
-
end
|
136
|
-
|
137
|
-
#Returns a object by ID or raises a RefError.
|
138
|
-
#===Examples
|
139
|
-
# begin
|
140
|
-
# obj = map[1]
|
141
|
-
# print "Object still exists in memory."
|
142
|
-
# rescue Knj::Wref::Recycled
|
143
|
-
# print "Object has been garbage-collected."
|
144
|
-
# end
|
145
|
-
def get(id)
|
146
|
-
begin
|
147
|
-
@mutex.synchronize do
|
148
|
-
raise Knj::Wref::Recycled if !@map.key?(id)
|
149
|
-
return @map[id].get
|
150
|
-
end
|
151
|
-
rescue Knj::Wref::Recycled => e
|
152
|
-
self.delete(id)
|
153
|
-
raise e
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
#The same as 'get' but returns nil instead of WeakRef-error. This can be used to avoid writing lots of code.
|
158
|
-
#===Examples
|
159
|
-
# obj = map.get!(1)
|
160
|
-
# print "Object still exists in memory." if obj
|
161
|
-
def get!(id)
|
162
|
-
begin
|
163
|
-
return self.get(id)
|
164
|
-
rescue Knj::Wref::Recycled
|
165
|
-
return nil
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
#Scans the whole map and removes dead references. After the implementation of automatic clean-up by using ObjectSpace.define_finalizer, there should be no reason to call this method.
|
170
|
-
def clean
|
171
|
-
keys = nil
|
172
|
-
@mutex.synchronize do
|
173
|
-
keys = @map.keys
|
174
|
-
end
|
175
|
-
|
176
|
-
keys.each do |key|
|
177
|
-
begin
|
178
|
-
self.get(key) #this will remove the key if the object no longer exists.
|
179
|
-
rescue Knj::Wref::Recycled
|
180
|
-
#ignore.
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
return nil
|
185
|
-
end
|
186
|
-
|
187
|
-
#Returns true if a given key exists and the object it holds is alive.
|
188
|
-
def valid?(key)
|
189
|
-
@mutex.synchronize do
|
190
|
-
return false if !@map.key?(key)
|
191
|
-
|
192
|
-
begin
|
193
|
-
@map[key].get
|
194
|
-
return true
|
195
|
-
rescue Knj::Wref::Recycled
|
196
|
-
return false
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
#Returns true if the given key exists in the hash.
|
202
|
-
#===Examples
|
203
|
-
# print "Key exists but we dont know if the value has been garbage-collected." if map.key?(1)
|
204
|
-
def key?(key)
|
205
|
-
@mutex.synchronize do
|
206
|
-
return @map.key?(key)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
#Returns the length of the hash. This may not be true since invalid objects is also counted.
|
211
|
-
def length
|
212
|
-
@mutex.synchronize do
|
213
|
-
return @map.length
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
#Cleans the hash and returns the length. This is slower but more accurate than the ordinary length that just returns the hash-length.
|
218
|
-
def length_valid
|
219
|
-
self.clean
|
220
|
-
|
221
|
-
@mutex.synchronize do
|
222
|
-
return @map.length
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
#Deletes a key in the hash.
|
227
|
-
def delete(key)
|
228
|
-
@mutex.synchronize do
|
229
|
-
wref = @map[key]
|
230
|
-
@ids.delete(wref.id) if wref
|
231
|
-
@map.delete(key)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
#This method is supposed to remove objects when finalizer is called by ObjectSpace.
|
236
|
-
def delete_by_id(object_id)
|
237
|
-
@mutex.synchronize do
|
238
|
-
id = @ids[object_id]
|
239
|
-
@map.delete(id)
|
240
|
-
@ids.delete(object_id)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
#Make it hash-compatible.
|
245
|
-
alias has_key? key?
|
246
|
-
alias [] get
|
247
|
-
alias []= set
|
248
|
-
end
|
249
|
-
|
250
|
-
#This error is raised when an object in a wref has been garbage-collected.
|
251
|
-
class Knj::Wref::Recycled < RuntimeError; end
|