facets 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +3 -3
- data/README +6 -7
- data/lib/core/facets.rb +1 -46
- data/lib/core/facets/array.rb +3 -0
- data/lib/core/facets/array/indexable.rb +6 -1
- data/lib/core/facets/array/only.rb +20 -0
- data/lib/core/facets/dir/multiglob.rb +12 -1
- data/lib/core/facets/enumerable.rb +0 -1
- data/lib/core/facets/enumerable/collect.rb +1 -0
- data/lib/core/facets/enumerable/combination.rb +44 -90
- data/lib/core/facets/facets.rb +46 -0
- data/lib/core/facets/file/write.rb +46 -58
- data/lib/core/facets/hash.rb +2 -0
- data/lib/core/facets/hash/select.rb +14 -0
- data/lib/core/facets/integer/multiples.rb +12 -55
- data/lib/core/facets/kernel/val.rb +14 -0
- data/lib/core/facets/module/alias.rb +28 -9
- data/lib/core/facets/module/methods.rb +18 -0
- data/lib/core/facets/module/traits.rb +65 -70
- data/lib/core/facets/proc/compose.rb +15 -12
- data/lib/core/facets/stackable.rb +3 -2
- data/lib/core/facets/string/format.rb +4 -6
- data/lib/core/facets/string/tabs.rb +34 -0
- data/lib/core/facets/symbol.rb +1 -0
- data/lib/core/facets/symbol/succ.rb +1 -42
- data/lib/core/facets/symbol/to_proc.rb +34 -0
- data/lib/methods/facets/array/contains.rb +1 -0
- data/lib/methods/facets/facets/require_core.rb +1 -0
- data/lib/methods/facets/file/writelines.rb +1 -0
- data/lib/methods/facets/io/writelines.rb +1 -0
- data/lib/methods/facets/kernel/not_nil.rb +1 -0
- data/lib/methods/facets/module/conflict.rb +1 -0
- data/lib/methods/facets/module/instance_method_defined.rb +1 -0
- data/lib/methods/facets/module/module_method_defined.rb +1 -0
- data/lib/methods/facets/module/private_conflict.rb +1 -0
- data/lib/methods/facets/module/protected_conflict.rb +1 -0
- data/lib/methods/facets/module/public_conflict.rb +1 -0
- data/lib/methods/facets/string/expand_tabs.rb +1 -0
- data/lib/methods/facets/string/outdent.rb +1 -0
- data/lib/methods/facets/string/taballto.rb +1 -0
- data/lib/more/facets/arguments.rb +1 -1
- data/lib/more/facets/association.rb +0 -46
- data/lib/more/facets/autoarray.rb +0 -28
- data/lib/more/facets/command.rb +341 -8
- data/lib/more/facets/dictionary.rb +25 -131
- data/lib/more/facets/downloader.rb +1 -1
- data/lib/more/facets/infinity.rb +3 -3
- data/lib/more/facets/interval.rb +0 -161
- data/lib/more/facets/multiton.rb +16 -12
- data/lib/more/facets/namespace.rb +1 -1
- data/lib/more/facets/ostruct.rb +46 -10
- data/lib/more/facets/overload.rb +0 -51
- data/lib/more/facets/paramix.rb +0 -97
- data/lib/more/facets/pp_s.rb +30 -0
- data/lib/more/facets/progressbar.rb +18 -10
- data/lib/more/facets/prototype.rb +1 -40
- data/lib/more/facets/random.rb +1 -0
- data/lib/more/facets/rbsystem.rb +4 -1
- data/lib/more/facets/snapshot.rb +8 -1
- data/lib/more/facets/stylize.rb +2 -0
- data/meta/{project.yaml → facets-2.0.3.roll} +22 -14
- data/meta/manifest.txt +38 -8
- data/task/{config.yaml → config/general.yaml} +7 -2
- data/task/{rdoc.yaml → config/rdoc.yaml} +1 -1
- data/task/crosstest +309 -0
- data/task/isotest +293 -0
- data/task/loadtest +28 -0
- data/task/methods +4 -4
- data/task/prepare +5 -0
- data/task/publish +2 -2
- data/task/rdoc +1 -0
- data/task/syntax +29 -0
- data/task/test +0 -1
- data/task/testeach +42 -0
- data/task/testpairs +50 -0
- data/test/lib/rq.rb +15 -0
- data/test/unit/array/test_merge.rb +21 -43
- data/test/unit/array/test_only.rb +21 -0
- data/test/unit/enumerable/test_collect.rb +1 -21
- data/test/unit/enumerable/test_combination.rb +50 -44
- data/test/unit/file/test_topath.rb +48 -57
- data/test/unit/file/test_write.rb +82 -0
- data/test/unit/hash/test_select.rb +43 -0
- data/test/unit/integer/test_multiples.rb +28 -32
- data/test/unit/kernel/test_report.rb +9 -12
- data/test/unit/kernel/test_val.rb +50 -45
- data/test/unit/module/test_include.rb +56 -57
- data/test/unit/module/test_name.rb +42 -55
- data/test/unit/module/test_traits.rb +46 -47
- data/test/unit/string/test_filter.rb +19 -34
- data/test/unit/string/test_format.rb +87 -96
- data/test/unit/string/test_regesc.rb +18 -26
- data/test/unit/string/test_tabs.rb +226 -119
- data/test/unit/symbol/test_succ.rb +14 -23
- data/test/unit/symbol/test_to_proc.rb +41 -0
- data/test/unit/test_association.rb +38 -47
- data/test/unit/test_attributes.rb +24 -33
- data/test/unit/test_autoarray.rb +23 -32
- data/test/unit/test_command.rb +26 -0
- data/test/unit/test_dictionary.rb +123 -117
- data/test/unit/test_infinity.rb +41 -47
- data/test/unit/test_inheritor.rb +133 -142
- data/test/unit/test_interval.rb +129 -93
- data/test/unit/test_ostruct.rb +148 -101
- data/test/unit/test_overload.rb +8 -15
- data/test/unit/test_paramix.rb +67 -73
- data/test/unit/test_pp_s.rb +23 -0
- data/test/unit/test_prototype.rb +28 -38
- metadata +47 -11
- data/lib/core/facets/enumerable/instance_map.rb +0 -0
- data/lib/more/facets/command_options.rb +0 -328
- data/meta/version.txt +0 -1
- data/task/load +0 -39
- data/test/unit/test_command_options.rb +0 -29
data/lib/more/facets/ostruct.rb
CHANGED
@@ -32,6 +32,42 @@ require 'ostruct'
|
|
32
32
|
|
33
33
|
class OpenStruct
|
34
34
|
|
35
|
+
#
|
36
|
+
# Allows the initialization of an OpenStruct with a block:
|
37
|
+
#
|
38
|
+
# person = OpenStruct.new do |p|
|
39
|
+
# p.name = 'John Smith'
|
40
|
+
# p.gender = :M
|
41
|
+
# p.age = 71
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# You can still provide a hash for initialization purposes, and even combine
|
45
|
+
# the two approaches if you wish.
|
46
|
+
#
|
47
|
+
# person = OpenStruct.new(:name => 'John Smith', :age => 31) do |p|
|
48
|
+
# p.gender = :M
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# CREDIT Noah Gibbs
|
52
|
+
# CREDIT Gavin Sinclair
|
53
|
+
|
54
|
+
def initialize(hash=nil) # :yield: self
|
55
|
+
@table = {}
|
56
|
+
if hash
|
57
|
+
for k,v in hash
|
58
|
+
@table[k.to_sym] = v
|
59
|
+
new_ostruct_member(k)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
yield self if block_given?
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
def each(&blk)
|
67
|
+
@table.each(&blk)
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
35
71
|
def to_h
|
36
72
|
@table
|
37
73
|
end
|
@@ -88,8 +124,8 @@ class OpenStruct
|
|
88
124
|
# o.a #=> 2
|
89
125
|
#
|
90
126
|
def ostruct_update(other)
|
91
|
-
|
92
|
-
for k,v in
|
127
|
+
#other = other.to_hash #to_h ?
|
128
|
+
for k,v in other
|
93
129
|
@table[k.to_sym] = v
|
94
130
|
end
|
95
131
|
self
|
@@ -119,9 +155,9 @@ class OpenStruct
|
|
119
155
|
# o.ostruct_update { :a => 2 }
|
120
156
|
# o.a #=> 2
|
121
157
|
#
|
122
|
-
def __update__(
|
123
|
-
|
124
|
-
for k,v in
|
158
|
+
def __update__(other)
|
159
|
+
#other = other.to_hash #to_h?
|
160
|
+
for k,v in other
|
125
161
|
@table[k.to_sym] = v
|
126
162
|
end
|
127
163
|
self
|
@@ -133,9 +169,9 @@ class OpenStruct
|
|
133
169
|
# o.ostruct_merge { :a => 2 }
|
134
170
|
# o.a #=> 2
|
135
171
|
#
|
136
|
-
def __merge__(
|
172
|
+
def __merge__(other)
|
137
173
|
o = dup
|
138
|
-
o.__update__(
|
174
|
+
o.__update__(other)
|
139
175
|
o
|
140
176
|
end
|
141
177
|
end
|
@@ -176,14 +212,14 @@ class Hash
|
|
176
212
|
# o = h.to_ostruct_recurse( { h['a'] => h['a'] } )
|
177
213
|
# o.a['b'] #=> 1
|
178
214
|
#
|
179
|
-
def to_ostruct_recurse(
|
215
|
+
def to_ostruct_recurse(exclude={})
|
180
216
|
return exclude[self] if exclude.key?( self )
|
181
217
|
o = exclude[self] = OpenStruct.new
|
182
218
|
h = self.dup
|
183
219
|
each_pair do |k,v|
|
184
|
-
h[k] = v.to_ostruct_recurse( exclude ) if v.respond_to?(
|
220
|
+
h[k] = v.to_ostruct_recurse( exclude ) if v.respond_to?(:to_ostruct_recurse)
|
185
221
|
end
|
186
|
-
o.__update__(
|
222
|
+
o.__update__(h)
|
187
223
|
end
|
188
224
|
|
189
225
|
end
|
data/lib/more/facets/overload.rb
CHANGED
@@ -98,54 +98,3 @@ class Module
|
|
98
98
|
end
|
99
99
|
|
100
100
|
end
|
101
|
-
|
102
|
-
|
103
|
-
# _____ _
|
104
|
-
# |_ _|__ ___| |_
|
105
|
-
# | |/ _ \/ __| __|
|
106
|
-
# | | __/\__ \ |_
|
107
|
-
# |_|\___||___/\__|
|
108
|
-
#
|
109
|
-
|
110
|
-
=begin test
|
111
|
-
|
112
|
-
require 'test/unit'
|
113
|
-
|
114
|
-
class TCOverload < Test::Unit::TestCase
|
115
|
-
|
116
|
-
class X
|
117
|
-
|
118
|
-
def x
|
119
|
-
"hello"
|
120
|
-
end
|
121
|
-
|
122
|
-
overload :x, Integer do |i|
|
123
|
-
i
|
124
|
-
end
|
125
|
-
|
126
|
-
overload :x, String, String do |s1, s2|
|
127
|
-
[s1, s2]
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
def setup
|
133
|
-
@x = X.new
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_x
|
137
|
-
assert_equal( "hello", @x.x )
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_i
|
141
|
-
assert_equal( 1, @x.x(1) )
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_s
|
145
|
-
assert_equal( ["a","b"], @x.x("a","b") )
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
=end
|
151
|
-
|
data/lib/more/facets/paramix.rb
CHANGED
@@ -146,100 +146,3 @@ class Module
|
|
146
146
|
end
|
147
147
|
|
148
148
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
# _____ _
|
153
|
-
# |_ _|__ ___| |_
|
154
|
-
# | |/ _ \/ __| __|
|
155
|
-
# | | __/\__ \ |_
|
156
|
-
# |_|\___||___/\__|
|
157
|
-
#
|
158
|
-
|
159
|
-
=begin test
|
160
|
-
|
161
|
-
require 'test/unit'
|
162
|
-
require 'facets/kernel/metaid'
|
163
|
-
|
164
|
-
class TC01 < Test::Unit::TestCase
|
165
|
-
|
166
|
-
module M
|
167
|
-
def f
|
168
|
-
M(:p)
|
169
|
-
end
|
170
|
-
def self.included_with_parameters( base, parms )
|
171
|
-
base.class_eval do
|
172
|
-
define_method :check do
|
173
|
-
parms
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
class C
|
180
|
-
include M, :p => "check"
|
181
|
-
end
|
182
|
-
|
183
|
-
class D
|
184
|
-
include M, :p => "steak"
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_01_001
|
188
|
-
c = C.new
|
189
|
-
assert_equal( "check", c.M(:p) )
|
190
|
-
assert_equal( "check", c.f )
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_01_002
|
194
|
-
d = D.new
|
195
|
-
assert_equal( "steak", d.M(:p) )
|
196
|
-
assert_equal( "steak", d.f )
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_01_003
|
200
|
-
assert_equal( {M=>{:p => "check"}}, C.mixin_parameters )
|
201
|
-
assert_equal( {M=>{:p => "steak"}}, D.mixin_parameters )
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_01_004
|
205
|
-
c = C.new
|
206
|
-
assert_equal( {:p => "check"}, c.check )
|
207
|
-
d = D.new
|
208
|
-
assert_equal( {:p => "steak"}, d.check )
|
209
|
-
end
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
|
214
|
-
class TC02 < Test::Unit::TestCase
|
215
|
-
|
216
|
-
module M
|
217
|
-
def f
|
218
|
-
M(:p)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
class C
|
223
|
-
extend M, :p => "mosh"
|
224
|
-
end
|
225
|
-
|
226
|
-
class D
|
227
|
-
extend M, :p => "many"
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_02_001
|
231
|
-
assert_equal( "mosh", C.f )
|
232
|
-
end
|
233
|
-
|
234
|
-
def test_02_002
|
235
|
-
assert_equal( "many", D.f )
|
236
|
-
end
|
237
|
-
|
238
|
-
def test_02_003
|
239
|
-
assert_equal( {M=>{:p => "mosh"}}, C.eigenclass.mixin_parameters )
|
240
|
-
assert_equal( {M=>{:p => "many"}}, D.eigenclass.mixin_parameters )
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
=end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# TODO How useful is this really? Or, can it go in with something else?
|
2
|
+
|
3
|
+
require 'pp'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
module Kernel
|
7
|
+
|
8
|
+
# Returns a pretty-printed string of the object. Requires libraries +pp+ and
|
9
|
+
# +stringio+ from the Ruby standard library.
|
10
|
+
#
|
11
|
+
# The following code pretty-prints an object (much like +p+ plain-prints an
|
12
|
+
# object):
|
13
|
+
#
|
14
|
+
# pp object
|
15
|
+
#
|
16
|
+
# The following code captures the pretty-printing in +str+ instead of
|
17
|
+
# sending it to +STDOUT+.
|
18
|
+
#
|
19
|
+
# str = object.pp_s
|
20
|
+
#
|
21
|
+
# CREDIT Noah Gibbs
|
22
|
+
# CREDIT Gavin Sinclair
|
23
|
+
|
24
|
+
def pp_s
|
25
|
+
pps = StringIO.new
|
26
|
+
PP.pp(self, pps)
|
27
|
+
pps.string
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -25,7 +25,7 @@
|
|
25
25
|
#
|
26
26
|
# == Usage
|
27
27
|
#
|
28
|
-
# pbar =
|
28
|
+
# pbar = Console::ProgressBar.new( "Demo", 100 )
|
29
29
|
# 100.times { pbar.inc }
|
30
30
|
# pbar.finish
|
31
31
|
#
|
@@ -72,7 +72,7 @@ class Console::ProgressBar
|
|
72
72
|
convert_bytes(@current)
|
73
73
|
end
|
74
74
|
|
75
|
-
def format_time
|
75
|
+
def format_time(t)
|
76
76
|
t = t.to_i
|
77
77
|
sec = t % 60
|
78
78
|
min = (t / 60) % 60
|
@@ -147,7 +147,7 @@ class Console::ProgressBar
|
|
147
147
|
end
|
148
148
|
|
149
149
|
def show
|
150
|
-
arguments = @format_arguments.map
|
150
|
+
arguments = @format_arguments.map{|method| send(method)}
|
151
151
|
line = sprintf(@format, *arguments)
|
152
152
|
|
153
153
|
width = get_width
|
@@ -178,22 +178,26 @@ class Console::ProgressBar
|
|
178
178
|
|
179
179
|
public
|
180
180
|
def file_transfer_mode
|
181
|
-
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
181
|
+
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
182
182
|
end
|
183
183
|
|
184
|
-
def
|
184
|
+
def title=(str)
|
185
|
+
@title = str
|
186
|
+
end
|
187
|
+
|
188
|
+
def bar_mark=(mark)
|
185
189
|
@bar_mark = String(mark)[0..0]
|
186
190
|
end
|
187
191
|
|
188
|
-
def total_overflow=
|
192
|
+
def total_overflow=(boolv)
|
189
193
|
@total_overflow = boolv ? true : false
|
190
194
|
end
|
191
195
|
|
192
|
-
def format=
|
196
|
+
def format=(format)
|
193
197
|
@format = format
|
194
198
|
end
|
195
199
|
|
196
|
-
def format_arguments=
|
200
|
+
def format_arguments=(arguments)
|
197
201
|
@format_arguments = arguments
|
198
202
|
end
|
199
203
|
|
@@ -203,12 +207,16 @@ class Console::ProgressBar
|
|
203
207
|
show_progress
|
204
208
|
end
|
205
209
|
|
210
|
+
def flush
|
211
|
+
@out.flush
|
212
|
+
end
|
213
|
+
|
206
214
|
def halt
|
207
215
|
@is_finished = true
|
208
216
|
show_progress
|
209
217
|
end
|
210
218
|
|
211
|
-
def set
|
219
|
+
def set(count)
|
212
220
|
if count < 0
|
213
221
|
raise "invalid count less than zero: #{count}"
|
214
222
|
elsif count > @total
|
@@ -223,7 +231,7 @@ class Console::ProgressBar
|
|
223
231
|
@previous = @current
|
224
232
|
end
|
225
233
|
|
226
|
-
def inc
|
234
|
+
def inc(step = 1)
|
227
235
|
@current += step
|
228
236
|
@current = @total if @current > @total
|
229
237
|
show_progress
|
@@ -53,7 +53,7 @@ class Prototype
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def trait(obj)
|
56
|
-
|
56
|
+
traits << obj.new
|
57
57
|
end
|
58
58
|
|
59
59
|
def method_missing(s, *a, &b)
|
@@ -87,42 +87,3 @@ module Kernel
|
|
87
87
|
end
|
88
88
|
|
89
89
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
=begin test
|
94
|
-
|
95
|
-
require 'test/unit'
|
96
|
-
|
97
|
-
class TestPrototypeKernel < Test::Unit::TestCase
|
98
|
-
|
99
|
-
def test_new
|
100
|
-
q = nil
|
101
|
-
s = "Testing"
|
102
|
-
assert_nothing_raised { q = s.new }
|
103
|
-
assert_equal( s, q )
|
104
|
-
assert_not_equal( s.object_id, q.object_id )
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class TestPrototype < Test::Unit::TestCase
|
109
|
-
|
110
|
-
def setup
|
111
|
-
@person = prototype do
|
112
|
-
@name = ''
|
113
|
-
@age = 0
|
114
|
-
@announce = fn { |x| "#{x}, #{name} is #{age}" }
|
115
|
-
end
|
116
|
-
|
117
|
-
@person.name = 'Tom'
|
118
|
-
@person.age = 35
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_simple_case
|
122
|
-
assert_equal( "Peter, Tom is 35", @person.announce['Peter'])
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
=end
|
128
|
-
|
data/lib/more/facets/random.rb
CHANGED