fxri 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/fxri +4 -344
- data/fxri.gemspec +24 -24
- data/fxri.rb +351 -0
- data/lib/Empty_Text_Field_Handler.rb +63 -63
- data/lib/FoxDisplayer.rb +148 -148
- data/lib/FoxTextFormatter.rb +274 -274
- data/lib/Icon_Loader.rb +35 -35
- data/lib/Packet_Item.rb +178 -178
- data/lib/Packet_List.rb +192 -192
- data/lib/Recursive_Open_Struct.rb +233 -238
- data/lib/Search_Engine.rb +165 -165
- data/lib/fxirb.rb +401 -400
- metadata +13 -22
- data/bugs/fxri bug `concat' can't convert nil into Array (TypeError).eml +0 -50
- data/bugs/fxri with Ruby v1.8.5 via OneClickInstaller v1.8.5-21.eml +0 -167
- data/fxri-0.3.4.gem +0 -0
- data/lib/fxirb-0.2.1/CHANGELOG +0 -31
- data/lib/fxirb-0.2.1/fxirb.rb +0 -395
@@ -1,238 +1,233 @@
|
|
1
|
-
# Author:: Martin Ankerl (mailto:martin.ankerl@gmail.com)
|
2
|
-
|
3
|
-
# Recursive_Open_Struct provides a convenient interface to a hierarchy of configuration
|
4
|
-
# parameters. You do not need to define the accessors, they are created automatically
|
5
|
-
# on demand.
|
6
|
-
#
|
7
|
-
# Have a look at this example:
|
8
|
-
#
|
9
|
-
# ac = Recursive_Open_Struct.new
|
10
|
-
# ac.window.name = "SuperDuper"
|
11
|
-
# ac.app.version = "2.1.3"
|
12
|
-
# ac.this.is.automatically.created = "blabla"
|
13
|
-
#
|
14
|
-
# After you have created all of your configuration parameters, to prevent
|
15
|
-
# typos when using the parameters, the structure can be closed:
|
16
|
-
#
|
17
|
-
# ac.close
|
18
|
-
#
|
19
|
-
# After closing,
|
20
|
-
#
|
21
|
-
# ac.widnow.name = "UberSuperDuper"
|
22
|
-
#
|
23
|
-
# You get the usual NoMethodError, because 'widnow' does not exist.
|
24
|
-
#
|
25
|
-
class Recursive_Open_Struct
|
26
|
-
# Create a new Recursive_Open_Struct.
|
27
|
-
def initialize
|
28
|
-
@methods = Hash.new
|
29
|
-
@open = true
|
30
|
-
end
|
31
|
-
|
32
|
-
# automatically add parameters
|
33
|
-
def method_missing(method, *params) # :nodoc:
|
34
|
-
# setting or getting?
|
35
|
-
is_setting = !params.empty?
|
36
|
-
|
37
|
-
key = method.id2name
|
38
|
-
# remove trailing =
|
39
|
-
key.chop! if is_setting
|
40
|
-
|
41
|
-
# if structure is closed, disable hierarchy creation
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
if
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
#
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
#
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
#
|
113
|
-
# open?
|
114
|
-
#
|
115
|
-
#
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
@s
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
@s.test
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
@s.a =
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
@s.a
|
209
|
-
assert_equal(["a"], @s.attrs)
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
@s.a
|
217
|
-
assert_equal("
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
@s
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@s.
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
@s.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
235
|
-
assert_equal(false, @s.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
1
|
+
# Author:: Martin Ankerl (mailto:martin.ankerl@gmail.com)
|
2
|
+
|
3
|
+
# Recursive_Open_Struct provides a convenient interface to a hierarchy of configuration
|
4
|
+
# parameters. You do not need to define the accessors, they are created automatically
|
5
|
+
# on demand.
|
6
|
+
#
|
7
|
+
# Have a look at this example:
|
8
|
+
#
|
9
|
+
# ac = Recursive_Open_Struct.new
|
10
|
+
# ac.window.name = "SuperDuper"
|
11
|
+
# ac.app.version = "2.1.3"
|
12
|
+
# ac.this.is.automatically.created = "blabla"
|
13
|
+
#
|
14
|
+
# After you have created all of your configuration parameters, to prevent
|
15
|
+
# typos when using the parameters, the structure can be closed:
|
16
|
+
#
|
17
|
+
# ac.close
|
18
|
+
#
|
19
|
+
# After closing,
|
20
|
+
#
|
21
|
+
# ac.widnow.name = "UberSuperDuper"
|
22
|
+
#
|
23
|
+
# You get the usual NoMethodError, because 'widnow' does not exist.
|
24
|
+
#
|
25
|
+
class Recursive_Open_Struct
|
26
|
+
# Create a new Recursive_Open_Struct.
|
27
|
+
def initialize
|
28
|
+
@methods = Hash.new
|
29
|
+
@open = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# automatically add parameters
|
33
|
+
def method_missing(method, *params) # :nodoc:
|
34
|
+
# setting or getting?
|
35
|
+
is_setting = !params.empty?
|
36
|
+
|
37
|
+
key = method.id2name
|
38
|
+
# remove trailing =
|
39
|
+
key.chop! if is_setting
|
40
|
+
|
41
|
+
# if structure is closed, disable hierarchy creation
|
42
|
+
super unless @methods.has_key?(key) || @open
|
43
|
+
|
44
|
+
if is_setting
|
45
|
+
# assigning a new value
|
46
|
+
if @methods[key].class == Recursive_Open_Struct
|
47
|
+
raise TypeError, "overwriting previously created hierarchy entry '#{key}' not allowed", caller(1)
|
48
|
+
end
|
49
|
+
@methods[key] = *params
|
50
|
+
else
|
51
|
+
# no param: create new Recursive_Open_Struct object, if nothing is set.
|
52
|
+
unless @methods.has_key?(key)
|
53
|
+
@methods[key] = Recursive_Open_Struct.new
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@methods[key]
|
57
|
+
end
|
58
|
+
|
59
|
+
# An alternative way to access the value of an attribute
|
60
|
+
# s = Recursive_Open_Struct.new
|
61
|
+
# s.name = "Hugo"
|
62
|
+
# s["name"] # "Hugo"
|
63
|
+
def [](key)
|
64
|
+
@methods[key]
|
65
|
+
end
|
66
|
+
|
67
|
+
# An alternative way to set the value of an attribute
|
68
|
+
# s = Recursive_Open_Struct.new
|
69
|
+
# s["name"] = "Hugo"
|
70
|
+
# s.name # "Hugo"
|
71
|
+
def []=(key, value)
|
72
|
+
self.send((key+"=").to_sym, value)
|
73
|
+
end
|
74
|
+
|
75
|
+
# call-seq:
|
76
|
+
# attrs() -> an_array
|
77
|
+
#
|
78
|
+
# Return a sorted array of attribute names, similar to #methods.
|
79
|
+
#
|
80
|
+
# s = Recursive_Open_Struct.new
|
81
|
+
# s.name = "martinus"
|
82
|
+
# s.age = 25
|
83
|
+
# s.attrs # returns ["age", "name"]
|
84
|
+
def attrs
|
85
|
+
@methods.keys.sort
|
86
|
+
end
|
87
|
+
|
88
|
+
# After calling #close, no further modification of the configuration hierarchy
|
89
|
+
# is allowed. This is not as strict as #freeze, because you are still allowed
|
90
|
+
# to modify data.
|
91
|
+
#
|
92
|
+
# s = Recursive_Open_Struct.new
|
93
|
+
# s.name = "Hugo"
|
94
|
+
# s.close
|
95
|
+
# s.name = "martinus" # does still work
|
96
|
+
# s.age = 25 # raises NoMethodError
|
97
|
+
def close
|
98
|
+
do_set_open_status(false)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Reopens a Recursive_Open_Struct which was closed with #close earlier.
|
102
|
+
# After this call, it is possible to modify the structure again.
|
103
|
+
def re_open
|
104
|
+
do_set_open_status(true)
|
105
|
+
end
|
106
|
+
|
107
|
+
# call-seq:
|
108
|
+
# open?() -> boolean
|
109
|
+
#
|
110
|
+
# Return whether the structure is still open or not.
|
111
|
+
#
|
112
|
+
# s = Recursive_Open_Struct.new
|
113
|
+
# s.open? # returns true
|
114
|
+
# s.close
|
115
|
+
# s.open? # returns false
|
116
|
+
def open?
|
117
|
+
@open
|
118
|
+
end
|
119
|
+
|
120
|
+
# call-seq:
|
121
|
+
# each() { |elem| ... }
|
122
|
+
#
|
123
|
+
# Iterates through all elements of the Recursive_Open_Struct in alphabetic order.
|
124
|
+
def each
|
125
|
+
attrs.each do |attr|
|
126
|
+
yield @methods[attr]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
protected
|
131
|
+
|
132
|
+
def do_set_open_status(status)
|
133
|
+
@methods.each_value do |val|
|
134
|
+
val.do_set_open_status(status) if val.class == Recursive_Open_Struct
|
135
|
+
end
|
136
|
+
@open = status
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
if __FILE__ == $0
|
141
|
+
require 'test/unit'
|
142
|
+
|
143
|
+
class TestRecursiveOpenStruct < Test::Unit::TestCase
|
144
|
+
def setup
|
145
|
+
@s = Recursive_Open_Struct.new
|
146
|
+
end
|
147
|
+
|
148
|
+
def setAndAssertValue(val)
|
149
|
+
@s.test = val
|
150
|
+
assert_equal(val, @s.test)
|
151
|
+
@s.close
|
152
|
+
assert_equal(val, @s.test)
|
153
|
+
@s.test = "asdf"
|
154
|
+
assert_equal("asdf", @s.test)
|
155
|
+
end
|
156
|
+
|
157
|
+
def testSetNil
|
158
|
+
setAndAssertValue(nil)
|
159
|
+
end
|
160
|
+
|
161
|
+
def testSimple
|
162
|
+
@s.test = "xx"
|
163
|
+
@s.close
|
164
|
+
assert_equal("xx", @s.test)
|
165
|
+
end
|
166
|
+
|
167
|
+
def testSetFalse
|
168
|
+
setAndAssertValue(false)
|
169
|
+
end
|
170
|
+
|
171
|
+
def testSetStr
|
172
|
+
setAndAssertValue("topfen")
|
173
|
+
end
|
174
|
+
|
175
|
+
def testSetClass
|
176
|
+
setAndAssertValue(String)
|
177
|
+
end
|
178
|
+
|
179
|
+
def testSetTrue
|
180
|
+
setAndAssertValue(true)
|
181
|
+
end
|
182
|
+
|
183
|
+
def testSet0
|
184
|
+
setAndAssertValue(0)
|
185
|
+
end
|
186
|
+
|
187
|
+
def testRaiseTypeError
|
188
|
+
@s.a.b = 1
|
189
|
+
assert_raise(TypeError) do
|
190
|
+
@s.a = 3
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def testAttrs
|
195
|
+
assert_equal([], @s.attrs)
|
196
|
+
@s.b = "x"
|
197
|
+
@s.a = "a"
|
198
|
+
assert_equal(["a", "b"], @s.attrs)
|
199
|
+
end
|
200
|
+
|
201
|
+
def testRecursive
|
202
|
+
@s.a.b = 1
|
203
|
+
@s.a.c = 2
|
204
|
+
assert_equal(["a"], @s.attrs)
|
205
|
+
end
|
206
|
+
|
207
|
+
def testStrange
|
208
|
+
@s.a
|
209
|
+
assert_equal(["a"], @s.attrs)
|
210
|
+
assert_equal(Recursive_Open_Struct, @s.a.class)
|
211
|
+
@s.a.x = "asfd"
|
212
|
+
assert_equal("asfd", @s.a.x)
|
213
|
+
end
|
214
|
+
|
215
|
+
def testKlammer
|
216
|
+
@s.a = "asdf"
|
217
|
+
assert_equal("asdf", @s["a"])
|
218
|
+
@s.b_x = "hog"
|
219
|
+
assert_equal("hog", @s["b_x"])
|
220
|
+
@s.c.b.a = 1234
|
221
|
+
assert_equal(1234, @s["c"]["b"]["a"])
|
222
|
+
end
|
223
|
+
|
224
|
+
def testDeep
|
225
|
+
@s.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z = false
|
226
|
+
@s.close
|
227
|
+
assert_raise(NoMethodError) do
|
228
|
+
@s.blub = "hellow"
|
229
|
+
end
|
230
|
+
assert_equal(false, @s.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|