facets 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGES +14 -6
  2. data/MANIFEST +35 -18
  3. data/NOTES +5 -15
  4. data/README +1 -11
  5. data/doc/{History.txt → history.rdoc} +0 -0
  6. data/doc/html/api/core/created.rid +1 -1
  7. data/doc/html/api/core/files/CHANGES.html +20 -4
  8. data/doc/html/api/core/files/NOTES.html +44 -15
  9. data/doc/html/api/more/created.rid +1 -1
  10. data/doc/html/api/more/files/CHANGES.html +20 -4
  11. data/doc/html/api/more/files/NOTES.html +46 -15
  12. data/doc/html/changes.html +19 -3
  13. data/doc/html/notes.html +43 -14
  14. data/doc/notes.rdoc +9 -0
  15. data/lib/facets/basex.rb +37 -0
  16. data/lib/facets/basicobject.rb +2 -2
  17. data/lib/facets/date.rb +16 -4
  18. data/lib/facets/exception.rb +1 -0
  19. data/lib/facets/exception/suppress.rb +21 -0
  20. data/lib/facets/hash/argumentize.rb +2 -1
  21. data/lib/facets/kernel.rb +9 -2
  22. data/lib/facets/kernel/__class__.rb +9 -0
  23. data/lib/facets/kernel/__get__.rb +10 -0
  24. data/lib/facets/kernel/__set__.rb +1 -0
  25. data/lib/facets/kernel/instance_assign.rb +41 -0
  26. data/lib/facets/kernel/instance_class.rb +24 -0
  27. data/lib/facets/kernel/instance_send.rb +7 -0
  28. data/lib/facets/kernel/instance_variables.rb +99 -0
  29. data/lib/facets/kernel/object_class.rb +10 -0
  30. data/lib/facets/kernel/object_hexid.rb +12 -0
  31. data/lib/facets/kernel/{object.rb → object_send.rb} +0 -21
  32. data/lib/facets/kernel/silence.rb +25 -19
  33. data/lib/facets/kernel/suppress.rb +18 -0
  34. data/lib/facets/module.rb +3 -0
  35. data/lib/facets/module/basename.rb +31 -0
  36. data/lib/facets/module/modspace.rb +22 -0
  37. data/lib/facets/module/nesting.rb +0 -66
  38. data/lib/facets/module/spacename.rb +25 -0
  39. data/lib/facets/net/smtp_tls.rb +5 -8
  40. data/lib/facets/openhash.rb +1 -0
  41. data/lib/facets/openobject.rb +2 -1
  42. data/lib/facets/paramix.rb +187 -0
  43. data/lib/facets/platform.rb +192 -0
  44. data/lib/facets/recorder.rb +1 -1
  45. data/lib/facets/string.rb +12 -0
  46. data/lib/facets/string/to_time.rb +1 -23
  47. data/lib/facets/style.rb +145 -64
  48. data/lib/facets/time.rb +5 -0
  49. data/lib/facets/time/to_time.rb +14 -0
  50. data/log/{Changelog-0.txt → changelog-0.rdoc} +0 -0
  51. data/log/{Changelog-1.txt → changelog-1.rdoc} +0 -0
  52. data/log/{Changelog.txt → changelog.rdoc} +18 -0
  53. data/log/{Fixme.txt → fixme.rdoc} +3 -3
  54. data/log/testlog.txt +645 -0
  55. data/log/{Todo.txt → todo.rdoc} +80 -89
  56. data/meta/project.yaml +14 -10
  57. data/meta/version +1 -1
  58. data/script/conflicts +28 -3
  59. data/script/methods +32 -43
  60. data/test/kernel/{test_instance.rb → test_instance_assign.rb} +2 -10
  61. data/test/kernel/test_instance_class.rb +12 -0
  62. data/test/kernel/{test_object.rb → test_object_class.rb} +2 -9
  63. data/test/kernel/test_object_hexid.rb +12 -0
  64. data/test/module/test_basename.rb +11 -0
  65. data/test/module/test_modspace.rb +13 -0
  66. data/test/module/test_nesting.rb +0 -17
  67. data/test/module/test_spacename.rb +14 -0
  68. data/test/test_date.rb +12 -0
  69. data/test/test_style.rb +1 -1
  70. data/test/{string → time}/test_to_time.rb +1 -9
  71. metadata +46 -26
  72. data/lib/facets/behavior.rb +0 -104
  73. data/lib/facets/kernel/instance.rb +0 -73
  74. data/lib/facets/string/stylize.rb +0 -73
  75. data/lib/facets/string/underscore.rb +0 -28
  76. data/log/Testlog.txt +0 -205
  77. data/meta/corelibs +0 -49
  78. data/test/string/test_stylize.rb +0 -52
  79. data/test/string/test_underscore.rb +0 -13
@@ -41,17 +41,13 @@ class Net::SMTP
41
41
  send :remove_method, :start
42
42
  end
43
43
 
44
- def self.start( address, port = nil,
45
- helo = 'localhost.localdomain',
46
- user = nil, secret = nil, authtype = nil, use_tls = false,
47
- &block) # :yield: smtp
44
+ def self.start(address, port=nil, helo='localhost.localdomain', user=nil, secret=nil, authtype=nil, use_tls=false, &block) # :yield: smtp
48
45
  new(address, port).start(helo, user, secret, authtype, use_tls, &block)
49
46
  end
50
47
 
51
48
  alias tls_old_start start
52
49
 
53
- def start( helo = 'localhost.localdomain',
54
- user = nil, secret = nil, authtype = nil, use_tls = false ) # :yield: smtp
50
+ def start(helo='localhost.localdomain', user=nil, secret=nil, authtype=nil, use_tls=false) # :yield: smtp
55
51
  start_method = use_tls ? :do_tls_start : :do_start
56
52
  if block_given?
57
53
  begin
@@ -75,7 +71,7 @@ class Net::SMTP
75
71
  sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
76
72
  @socket = Net::InternetMessageIO.new(sock)
77
73
  @socket.read_timeout = 60 #@read_timeout
78
- @socket.debug_output = STDERR #@debug_output
74
+ @socket.debug_output = STDERR if $DEBUG #@debug_output
79
75
 
80
76
  check_response(critical { recv_response() })
81
77
  do_helo(helodomain)
@@ -87,7 +83,7 @@ class Net::SMTP
87
83
  ssl.connect
88
84
  @socket = Net::InternetMessageIO.new(ssl)
89
85
  @socket.read_timeout = 60 #@read_timeout
90
- @socket.debug_output = STDERR #@debug_output
86
+ @socket.debug_output = STDERR if $DEBUG #@debug_output
91
87
  do_helo(helodomain)
92
88
 
93
89
  authenticate user, secret, authtype if user
@@ -132,3 +128,4 @@ class Net::SMTP
132
128
 
133
129
  end unless Net::SMTP.private_method_defined? :do_tls_start or
134
130
  Net::SMTP.method_defined? :tls?
131
+
@@ -15,6 +15,7 @@
15
15
  # an method_missing definition that routes to [] and []=.
16
16
  #
17
17
  class OpenHash < Hash
18
+ #private *instance_methods.select{|m| m !~ /^__/}
18
19
 
19
20
  # New OpenHash.
20
21
 
@@ -47,7 +47,8 @@
47
47
 
48
48
  require 'facets/hash/to_h'
49
49
  require 'facets/hash/to_proc'
50
- require 'facets/kernel/object' # object_class, object_hexid
50
+ require 'facets/kernel/object_class'
51
+ require 'facets/kernel/object_hexid'
51
52
 
52
53
  # = OpenObject
53
54
  #
@@ -0,0 +1,187 @@
1
+ # TITLE:
2
+ #
3
+ # Parametric Mixins
4
+ #
5
+ # SUMMARY:
6
+ #
7
+ # Parametric Mixins provides parameters for mixin modules.
8
+ #
9
+ # COPYRIGHT:
10
+ #
11
+ # Copyright (c) 2008 T. Sawyer
12
+ #
13
+ # LICENSE:
14
+ #
15
+ # Ruby License
16
+ #
17
+ # This module is free software. You may use, modify, and/or redistribute this
18
+ # software under the same terms as Ruby.
19
+ #
20
+ # This program is distributed in the hope that it will be useful, but WITHOUT
21
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22
+ # FOR A PARTICULAR PURPOSE.
23
+ #
24
+ # AUTHORS:
25
+ #
26
+ # - Thomas Sawyer
27
+
28
+ require 'facets/module/basename'
29
+ require 'facets/module/modspace'
30
+
31
+ # = Parametric Mixin
32
+ #
33
+ # Parametric Mixins provides parameters for mixin modules.
34
+ # Module parameters can be set at the time of inclusion or extension,
35
+ # then accessed via an instance method per mixin.
36
+ #
37
+ # module Mixin
38
+ # def hello
39
+ # puts "Hello from #{mixin_parameters[Mixin][:name]}"
40
+ # end
41
+ # end
42
+ #
43
+ # class MyClass
44
+ # include Mixin(:name => 'Ruby')
45
+ # end
46
+ #
47
+ # m = MyClass.new
48
+ # m.hello -> 'Hello from Ruby'
49
+ #
50
+ # You can view the full set of parameters via the #mixin_parameters
51
+ # class method, which returns a hash keyed on the included modules.
52
+ #
53
+ # MyClass.mixin_parameters #=> {Mixin=>{:name=>'Ruby'}}
54
+ # MyClass.mixin_parameters[Mixin] #=> {:name=>'Ruby'}
55
+ #
56
+ # To create _dynamic mixins_ you can use the #included callback
57
+ # method along with mixin_parameters method like so:
58
+ #
59
+ # module Mixin
60
+ # def self.included( base )
61
+ # parms = base.mixin_parameters[self]
62
+ # base.class_eval {
63
+ # def hello
64
+ # puts "Hello from #{parms(:name)}"
65
+ # end
66
+ # }
67
+ # end
68
+ # end
69
+ #
70
+ #--
71
+ # More conveniently a new callback has been added, #included_with_parameters,
72
+ # which passes in the parameters in addition to the base class/module.
73
+ #
74
+ # module Mixin
75
+ # def self.included_with_parameters( base, parms )
76
+ # base.class_eval {
77
+ # def hello
78
+ # puts "Hello from #{parms(:name)}"
79
+ # end
80
+ # }
81
+ # end
82
+ # end
83
+ #
84
+ # We would prefer to have passed the parameters through the #included callback
85
+ # method itself, but implementation of such a feature is much more complicated.
86
+ # If a reasonable solution presents itself in the future however, we will fix.
87
+ #++
88
+
89
+ module Paramix # or PatrametricMixin ?
90
+
91
+ def self.append_features(base)
92
+ base.modspace.module_eval %{
93
+ def #{base.basename.to_s}(parameters, &block)
94
+ Delegator.new(#{base}, parameters, &block)
95
+ end
96
+ }
97
+ end
98
+
99
+ # It you want to define the module method by hand. You
100
+ # can use Parmix.new instead of Parmix::Delegator.new.
101
+
102
+ def self.new(delegate_module, parameters={}, &base_block)
103
+ Delegator.new(delegate_module, parameters, &base_block)
104
+ end
105
+
106
+ #
107
+
108
+ class Delegator < Module
109
+
110
+ attr :delegate_module
111
+ attr :parameters
112
+ attr :base_block
113
+
114
+ def initialize(delegate_module, parameters={}, &base_block)
115
+ @delegate_module = delegate_module
116
+ @parameters = parameters
117
+ @base_block = base_block
118
+ end
119
+
120
+ def append_features(base)
121
+ base.__send__(:include, delegate_module)
122
+
123
+ base.mixin_parameters[delegate_module] = parameters
124
+
125
+ base.module_eval do
126
+ define_method(:mixin_parameters) do
127
+ base.mixin_parameters
128
+ end
129
+ end
130
+
131
+ base.module_eval(&@base_block) if base_block
132
+ end
133
+
134
+ def [](name)
135
+ @parameters[name]
136
+ end
137
+
138
+ end
139
+
140
+ end
141
+
142
+
143
+ class Module
144
+
145
+ # Store for parametric mixin parameters.
146
+ #
147
+ # Returns a hash, the keys of which are the parametric mixin module
148
+ # and the values are the parameters associacted with this module/class.
149
+ #
150
+ # class C
151
+ # include P(:x=>1)
152
+ # end
153
+ #
154
+ # C.mixin_parameters[P] #=> {:x=>1}
155
+ #
156
+ def mixin_parameters
157
+ @mixin_parameters ||= {}
158
+ end
159
+
160
+ end
161
+
162
+
163
+ if __FILE__ == $0
164
+
165
+ module O
166
+ include Paramix
167
+
168
+ def x
169
+ mixin_parameters[O][:x]
170
+ end
171
+ end
172
+
173
+ #def O(options)
174
+ # Paramix.new(O, options)
175
+ #end
176
+
177
+ class X
178
+ include O(:x=>1)
179
+ end
180
+
181
+ x = X.new
182
+ p x.x
183
+
184
+ p X.ancestors
185
+
186
+ end
187
+
@@ -0,0 +1,192 @@
1
+ # Copyright (c) 2007 Eric Hodel
2
+ #
3
+ # Available list of platforms.
4
+
5
+ require 'rbconfig'
6
+
7
+ class Platform
8
+
9
+ @local = nil
10
+ @supported = nil
11
+
12
+ attr_accessor :cpu
13
+
14
+ attr_accessor :os
15
+
16
+ attr_accessor :version
17
+
18
+ RbConfig = Config unless defined? ::RbConfig
19
+
20
+ DEPRECATED_CONSTS = [
21
+ :DARWIN,
22
+ :LINUX_586,
23
+ :MSWIN32,
24
+ :PPC_DARWIN,
25
+ :WIN32,
26
+ :X86_LINUX
27
+ ]
28
+
29
+ # Array of supported platforms (ie. pure-Ruby and local platform).
30
+
31
+ def self.supported
32
+ @suported ||= [Platform::RUBY, Platform.local]
33
+ end
34
+
35
+ def self.const_missing(name) # TODO remove six months from 2007/12
36
+ if DEPRECATED_CONSTS.include? name then
37
+ raise NameError, "#{name} has been removed, use CURRENT instead"
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ def self.local
44
+ arch = RbConfig::CONFIG['arch']
45
+ arch = "#{arch}_60" if arch =~ /mswin32$/
46
+ @local ||= new(arch)
47
+ end
48
+
49
+ def self.match(platform)
50
+ supported.any? do |local_platform|
51
+ platform.nil? or local_platform == platform or
52
+ (local_platform != Platform::RUBY and local_platform =~ platform)
53
+ end
54
+ end
55
+
56
+ def self.new(arch) # :nodoc:
57
+ case arch
58
+ when Platform::CURRENT then
59
+ Platform.local
60
+ when Platform::RUBY, nil, '' then
61
+ Platform::RUBY
62
+ else
63
+ super
64
+ end
65
+ end
66
+
67
+ def initialize(arch)
68
+ case arch
69
+ when Array then
70
+ @cpu, @os, @version = arch
71
+ when String then
72
+ arch = arch.split '-'
73
+
74
+ if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu
75
+ extra = arch.pop
76
+ arch.last << "-#{extra}"
77
+ end
78
+
79
+ cpu = arch.shift
80
+
81
+ @cpu = case cpu
82
+ when /i\d86/ then 'x86'
83
+ else cpu
84
+ end
85
+
86
+ if arch.length == 2 and arch.last =~ /^\d+$/ then # for command-line
87
+ @os, @version = arch
88
+ return
89
+ end
90
+
91
+ os, = arch
92
+ @cpu, os = nil, cpu if os.nil? # legacy jruby
93
+
94
+ @os, @version = case os
95
+ when /aix(\d+)/ then [ 'aix', $1 ]
96
+ when /cygwin/ then [ 'cygwin', nil ]
97
+ when /darwin(\d+)?/ then [ 'darwin', $1 ]
98
+ when /freebsd(\d+)/ then [ 'freebsd', $1 ]
99
+ when /hpux(\d+)/ then [ 'hpux', $1 ]
100
+ when /^java$/, /^jruby$/ then [ 'java', nil ]
101
+ when /^java([\d.]*)/ then [ 'java', $1 ]
102
+ when /linux/ then [ 'linux', $1 ]
103
+ when /mingw32/ then [ 'mingw32', nil ]
104
+ when /(mswin\d+)(\_(\d+))?/ then
105
+ os, version = $1, $3
106
+ @cpu = 'x86' if @cpu.nil? and os =~ /32$/
107
+ [os, version]
108
+ when /netbsdelf/ then [ 'netbsdelf', nil ]
109
+ when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ]
110
+ when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ]
111
+ # test
112
+ when /^(\w+_platform)(\d+)/ then [ $1, $2 ]
113
+ else [ 'unknown', nil ]
114
+ end
115
+ when Platform then
116
+ @cpu = arch.cpu
117
+ @os = arch.os
118
+ @version = arch.version
119
+ else
120
+ raise ArgumentError, "invalid argument #{arch.inspect}"
121
+ end
122
+ end
123
+
124
+ def inspect
125
+ "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a]
126
+ end
127
+
128
+ def to_a
129
+ [@cpu, @os, @version]
130
+ end
131
+
132
+ def to_s
133
+ to_a.compact.join '-'
134
+ end
135
+
136
+ def ==(other)
137
+ self.class === other and
138
+ @cpu == other.cpu and @os == other.os and @version == other.version
139
+ end
140
+
141
+ def ===(other)
142
+ return nil unless Platform === other
143
+
144
+ # cpu
145
+ (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and
146
+
147
+ # os
148
+ @os == other.os and
149
+
150
+ # version
151
+ (@version.nil? or other.version.nil? or @version == other.version)
152
+ end
153
+
154
+ def =~(other)
155
+ case other
156
+ when Platform then # nop
157
+ when String then
158
+ # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007
159
+ other = case other
160
+ when /^i686-darwin(\d)/ then ['x86', 'darwin', $1]
161
+ when /^i\d86-linux/ then ['x86', 'linux', nil]
162
+ when 'java', 'jruby' then [nil, 'java', nil]
163
+ when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2]
164
+ when 'powerpc-darwin' then ['powerpc', 'darwin', nil]
165
+ when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1]
166
+ when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8']
167
+ when /universal-darwin(\d)/ then ['universal', 'darwin', $1]
168
+ else other
169
+ end
170
+
171
+ other = Platform.new other
172
+ else
173
+ return nil
174
+ end
175
+
176
+ self === other
177
+ end
178
+
179
+ ##
180
+ # A pure-ruby gem that may use Gem::Specification#extensions to build
181
+ # binary files.
182
+
183
+ RUBY = 'ruby'
184
+
185
+ ##
186
+ # A platform-specific gem that is built for the packaging ruby's platform.
187
+ # This will be replaced with Gem::Platform::local.
188
+
189
+ CURRENT = 'current'
190
+
191
+ end
192
+
@@ -45,7 +45,7 @@
45
45
  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
46
46
  # FOR A PARTICULAR PURPOSE.
47
47
 
48
- require 'facets/kernel/object' # for object_class
48
+ require 'facets/kernel/object_class'
49
49
 
50
50
  # = Recorder
51
51
  #