rextra 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1,3 @@
1
1
  require 'rextra/cutting'
2
+ require 'rextra/debug'
3
+ include Rextra::Debug::DebugHelper
@@ -1,3 +1,4 @@
1
+ # -----------------------------------------------------------------------------
1
2
  class Object
2
3
  def __meta() class << self; self end end
3
4
  def meta_eval(&blk) __meta.instance_eval( &blk ) end
@@ -42,24 +43,9 @@ module Rextra
42
43
  @master.map do |e| e.send sym, *args end
43
44
  end
44
45
  end
45
- class Do < SimpleObject
46
- def initialize( master ) @master = master.clone end
47
- def method_missing( sym, *args )
48
- @master.map! do |e| e.send sym, *args end
49
- self
50
- end
51
- def end() @master end
52
- end
53
46
  end
54
47
  end
55
48
  module Enumerable
56
49
  def all() Rextra::Enumerable::All.new self end
57
- def do () Rextra::Enumerable::Do.new self end
58
50
  end
59
51
  # -----------------------------------------------------------------------------
60
- #module Kernel
61
- # def caller_name deep = 1
62
- # /:in `(\S*)'$/.match(caller[deep])[1]
63
- # end
64
- # def method_name() caller_name end
65
- #end
@@ -1,51 +1,53 @@
1
- ################################################################################
2
1
  module Rextra
3
- module Debug
4
- ################################################################################
5
- module DebugHelper
6
- def self.prepare
7
- output("\n" + Term::ANSIColor::yellow{ '_/\\_' * 20 }) if
8
- (require('term/ansicolor') rescue nil)
9
- end
10
- ################################################################################
11
- def self.output *args
12
- outs = [STDERR]
13
- #outs << logger if defined? RAILS_ENV # FIXME
14
- args.each do |arg|
2
+ module Debug
3
+ module DebugHelper
4
+ def self.puts arg, color = :green
5
+ require 'term/ansicolor' rescue nil
6
+ outs = [STDERR]
15
7
  outs.each do |out|
16
8
  out.puts(
17
9
  if defined? Term::ANSIColor
18
- Term::ANSIColor::green { arg.to_s }
10
+ Term::ANSIColor.send(color) { arg.to_s }
19
11
  else
20
12
  arg.to_s
21
13
  end
22
14
  )
23
15
  end
24
16
  end
17
+ def self.output *args
18
+ puts('-' * 80)
19
+ args.each do |arg| puts arg.to_s.chomp, :yellow end
20
+ end
25
21
  end
26
22
  end
27
- ################################################################################
28
- if (defined? RAILS_ENV and RAILS_ENV != 'production') or $DEBUG or $REXTRA_DEBUG
29
- def __here *args
30
- __d(*['here'].concat(args))
31
- end
32
- def __d *args
33
- DebugHelper::prepare
34
- DebugHelper::output *args
35
- end
36
- def __e *args
37
- require 'binding_of_caller'
38
- Binding.of_caller do |b|
39
- args.each do |arg|
40
- __d "[[#{arg}]] ==>" , (eval(arg,b).to_yaml rescue '[ERROR OUTPUTING]')
41
- end
42
- end
23
+ end
24
+
25
+ if (defined? RAILS_ENV and RAILS_ENV != 'production') or $DEBUG or ENV['REXTRA_DEBUG']
26
+ def __here *args
27
+ __d(*['here'].concat(args))
28
+ end
29
+ def __d *args
30
+ Rextra::Debug::DebugHelper::output *args
31
+ end
32
+ def __e *args
33
+ require 'binding_of_caller'
34
+ Binding.of_caller do |b|
35
+ Rextra::Debug::DebugHelper::output *(args.map do |arg|
36
+ "||| #{arg} ==> #{eval(arg,b).to_yaml}" rescue '[ERROR OUTPUTING]'
37
+ end)
43
38
  end
44
- else
45
- def __here(*args) end
46
- def __d(*args) end
47
- def __e(*args) end
48
39
  end
49
- end
40
+ def __stack
41
+ __d caller.to_yaml
42
+ end
43
+ def __pause
44
+ __d '[PRESS ENTER]'
45
+ STDIN.getc
46
+ end
47
+ else
48
+ def __here(*args) end
49
+ def __d(*args) end
50
+ def __e(*args) end
51
+ def __stack() end
52
+ def __pause() end
50
53
  end
51
- ################################################################################
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rextra
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.0.4
7
- date: 2006-11-02 00:00:00 -07:00
6
+ version: 2.0.5
7
+ date: 2006-12-07 00:00:00 -07:00
8
8
  summary: Ruby extras.
9
9
  require_paths:
10
10
  - lib
@@ -35,10 +35,8 @@ files:
35
35
  - test/ts_rextra.rb
36
36
  - lib/rextra
37
37
  - lib/rextra.rb
38
- - lib/rextra/bleeding.rb
39
38
  - lib/rextra/cutting.rb
40
39
  - lib/rextra/debug.rb
41
- - lib/rextra/enddata.rb
42
40
  - README
43
41
  test_files:
44
42
  - test/ts_rextra.rb
@@ -1,222 +0,0 @@
1
- #--
2
- # rapid/rextra.rb
3
- # USE "rdoc rapid/rextra.rb" to build the docs for this file.
4
- #++
5
- #
6
- # == Example Use
7
- # TBD
8
- #
9
- # == Credits
10
- # Michael Garriss
11
- #
12
- # == Licence
13
- # TBD
14
-
15
- #--
16
- # TODO review this
17
- # TODO test test test
18
- #++
19
-
20
- require 'rextra/cutting'
21
-
22
- def __TBD
23
- raise 'TBD'
24
- end
25
-
26
- #def ObjectSpace.make_proc str
27
- # eval "proc {#{str}}"
28
- #end
29
- #
30
- #module Kernel
31
- # def call_stack
32
- # require 'ostruct'
33
- # caller.map do |c|
34
- # # TODO rewrite this regexp
35
- # m = /^([\.a-zA-Z_0-9()\/]*):(\d*)(?::in `(\S*)')?$/.match c
36
- # OpenStruct.new(:file=>m[1],:line=>m[2],:call=>m[3]) rescue nil
37
- # end.compact
38
- # end
39
- # def caller_name deep = 1
40
- # /:in `(\S*)'$/.match( caller[deep] )[1]
41
- # end
42
- # def method_name() caller_name end
43
- #end
44
- #
45
- #class Object
46
- # def this
47
- # require 'weakref'
48
- # WeakRef.new self
49
- # end
50
- # def destructor str
51
- # ObjectSpace.define_finalizer this, ObjectSpace.make_proc( str )
52
- # end
53
- #end
54
- #
55
- #class Module
56
- # def module () self end
57
- # def modules() [self] + modules_up end
58
- # def module_up() eval name.sub( /(::)?\w+$/, '' ) end
59
- # def modules_up result = []
60
- # (r = module_up) ? r.modules_up( result << r ) : result end
61
- # def def_advice meth, &block
62
- # prev = self.instance_method meth.
63
- # define_method( meth ) do |*args|
64
- # block.call( prev.bind(self), *args )
65
- # end
66
- # end
67
- #
68
- # # TODO fix #const to look in global module
69
- # class Const
70
- # def initialize mod
71
- # @mod = mod
72
- # end
73
- # def method_missing( sym, *args )
74
- # @mod.modules.each do |mod|
75
- # return mod.const_get( sym ) if mod.const_defined? sym.to_s
76
- # end
77
- # #raise NameError, "uninitialized constant #{sym}"
78
- # nil
79
- # end
80
- # end
81
- #
82
- # def const
83
- # Const.new self.module
84
- # end
85
- #
86
- # def consts *syms
87
- # start, inc = 0, 1
88
- # start = syms.shift if syms.first.kind_of? Integer
89
- # inc = syms.pop if syms.last.kind_of? Integer
90
- # syms.each do |sym|
91
- # class_eval "#{sym.to_s.upcase} = #{start}"
92
- # start += inc
93
- # end
94
- # end
95
- #
96
- #end
97
- #
98
- #def parallel_each( *args )
99
- # args.shift.zip( *args ).each do |e|
100
- # yield( *e )
101
- # end
102
- #end
103
- #
104
- #module Rapid
105
- #
106
- # class ThreadPool
107
- # def initialize size = 10
108
- # @count, @max = 0, size
109
- # @mutex, @cond = Mutex.new, ConditionVariable.new
110
- # end
111
- # def thread *args, &block
112
- # @mutex.synchronize do
113
- # @cond.wait @mutex unless @count < @max
114
- # @count += 1
115
- # result = Thread.new(args,Thread.current,block) do |args,th,block|
116
- # begin
117
- # block.call *args
118
- # rescue => e
119
- # th.raise e
120
- # ensure
121
- # release
122
- # end end end
123
- # end
124
- # def max=(size) @mutex.synchronize { @max = size } end
125
- # private
126
- # def release
127
- # @mutex.synchronize do
128
- # @count -= 1
129
- # @cond.signal
130
- # end
131
- # end
132
- # end
133
- #
134
- # VERSION = '0.0.2'
135
- #
136
- # def self.tempfile name = nil
137
- # require 'tempfile'
138
- # tf = Tempfile.new name
139
- # yield tf
140
- # ensure
141
- # tf.close true
142
- # end
143
- #
144
- # def self.start_daemon *args, &block
145
- # :$VERBOSE.temporary nil do
146
- # #EndData.close if $leftovers
147
- # Process.fork do
148
- # fork and exit
149
- # trap( 'INT' ) { Thread.current.kill }
150
- # $stderr = $stdout = $stdin = NullDevice.new
151
- # Process.setsid
152
- # block.call( *args )
153
- # end
154
- # end
155
- # end
156
- #
157
- # def self.term_size
158
- # require 'curses'
159
- # Curses.init_screen
160
- # x, y = Curses.cols, Curses.lines
161
- # Curses.close_screen
162
- # [x, y]
163
- # ensure
164
- # Curses.close_screen
165
- # end
166
- #
167
- # def self.filename
168
- # File.basename $0
169
- # end
170
- #
171
- # def self.create_key size = 16 # copied from cgi/session.rb
172
- # require 'digest/md5'
173
- # md5 = Digest::MD5::new
174
- # md5.update(String(Time::now))
175
- # md5.update(String(rand(0)))
176
- # md5.update(String($$))
177
- # md5.hexdigest[0,size]
178
- # end
179
- #
180
- #module Kernel
181
- #
182
- # def modules() self.class.modules end
183
- # def module() self.class.module end
184
- # def module_up() self.class.module_up end
185
- # def modules_up() self.class.modules_up end
186
- #
187
- #end
188
- #
189
- #def required
190
- # result = []
191
- # $".each do |file|
192
- # $:.each do |path|
193
- # if File.exists?( path + '/' + file )
194
- # result << (path + '/' + file)
195
- # next
196
- # end
197
- # end
198
- # end
199
- # result
200
- #end
201
- #
202
- #def required? file
203
- # (el = required.grep( /#{file}(\.rb|\.so)?$/ ).to_el).empty? ? false : el
204
- #end
205
- #
206
- #class Array
207
- # def to_el # TODO better name
208
- # size == 1 ? first : self
209
- # end
210
- #end
211
- #
212
- #class Numeric
213
- # def commify
214
- # to_s.reverse.scan(/\d{3}|\d+/).join(',').reverse
215
- # end
216
- #end
217
- #
218
- #class Float
219
- # def to_s_cut x = 3
220
- # to_s.scan(/\d*\.\d{0,#{x}}/)
221
- # end
222
- #end
File without changes