activesupport 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,4 +1,17 @@
1
- *1.0.2*
1
+ *1.0.3* (27th March, 2005)
2
+
3
+ * Fixed Inflector.pluralize to handle capitalized words #932 [bitsweat]
4
+
5
+ * Added Object#suppress which allows you to make a saner choice around with exceptions to swallow #980. Example:
6
+
7
+ suppress(ZeroDivisionError) { 1/0 }
8
+
9
+ ...instead of:
10
+
11
+ 1/0 rescue nil # BAD, EVIL, DIRTY.
12
+
13
+
14
+ *1.0.2* (22th March, 2005)
2
15
 
3
16
  * Added Kernel#returning -- a Ruby-ized realization of the K combinator, courtesy of Mikael Brockman.
4
17
 
@@ -0,0 +1,38 @@
1
+ class MissingSourceFile < LoadError
2
+ attr_reader :path
3
+ def initialize(message, path)
4
+ super(message)
5
+ @path = path
6
+ end
7
+
8
+ def is_missing?(path)
9
+ path.gsub(/\.rb$/, '') == self.path.gsub(/\.rb$/, '')
10
+ end
11
+
12
+ def self.from_message(message)
13
+ REGEXPS.each do |regexp, capture|
14
+ match = regexp.match(message)
15
+ return MissingSourceFile.new(message, match[capture]) unless match.nil?
16
+ end
17
+ nil
18
+ end
19
+
20
+ REGEXPS = [
21
+ [/^no such file to load -- (.+)$/i, 1],
22
+ [/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2],
23
+ [/^Missing API definition file in (.+)$/i, 1]
24
+ ]
25
+ end
26
+
27
+ module ActiveSupport
28
+ module CoreExtensions
29
+ module LoadErrorExtensions
30
+ module LoadErrorClassMethods
31
+ def new(*args)
32
+ (self == LoadError && MissingSourceFile.from_message(args.first)) || super
33
+ end
34
+ end
35
+ ::LoadError.extend(LoadErrorClassMethods)
36
+ end
37
+ end
38
+ end
@@ -21,6 +21,13 @@ class Object #:nodoc:
21
21
  !self
22
22
  end
23
23
  end
24
+
25
+ def suppress(*exception_classes)
26
+ begin yield
27
+ rescue Exception => e
28
+ raise unless exception_classes.any? {|cls| e.kind_of? cls}
29
+ end
30
+ end
24
31
  end
25
32
 
26
33
  class Class #:nodoc:
@@ -21,8 +21,6 @@ module Dependencies
21
21
  require_or_load(file_name)
22
22
  rescue LoadError
23
23
  raise unless swallow_load_errors
24
- rescue Object => e
25
- raise ScriptError, "#{e.message}"
26
24
  end
27
25
  end
28
26
  end
@@ -179,8 +177,8 @@ class Object #:nodoc:
179
177
  begin
180
178
  require_or_load(class_id.to_s.demodulize.underscore)
181
179
  if Object.const_defined?(class_id) then return Object.const_get(class_id) else raise LoadError end
182
- rescue LoadError
183
- raise NameError, "uninitialized constant #{class_id}"
180
+ rescue LoadError => e
181
+ raise NameError.new("uninitialized constant #{class_id}").copy_blame!(e)
184
182
  end
185
183
  end
186
184
  end
@@ -216,4 +214,9 @@ class Exception
216
214
  return nil if blamed_files.empty?
217
215
  "This error occured while loading the following files:\n #{blamed_files.join "\n "}"
218
216
  end
217
+
218
+ def copy_blame!(exc)
219
+ @blamed_files = exc.blamed_files.clone
220
+ self
221
+ end
219
222
  end
@@ -57,39 +57,39 @@ module Inflector
57
57
  private
58
58
  def plural_rules #:doc:
59
59
  [
60
- [/fish$/, 'fish'], # fish
61
- [/(x|ch|ss|sh)$/, '\1es'], # search, switch, fix, box, process, address
62
- [/series$/, '\1series'],
63
- [/([^aeiouy]|qu)ies$/, '\1y'],
64
- [/([^aeiouy]|qu)y$/, '\1ies'], # query, ability, agency
65
- [/(?:([^f])fe|([lr])f)$/, '\1\2ves'], # half, safe, wife
66
- [/sis$/, 'ses'], # basis, diagnosis
67
- [/([ti])um$/, '\1a'], # datum, medium
68
- [/person$/, 'people'], # person, salesperson
69
- [/man$/, 'men'], # man, woman, spokesman
70
- [/child$/, 'children'], # child
71
- [/s$/, 's'], # no change (compatibility)
60
+ [/(fish)$/i, '\1\2'], # fish
61
+ [/(x|ch|ss|sh)$/i, '\1es'], # search, switch, fix, box, process, address
62
+ [/(series)$/i, '\1\2'],
63
+ [/([^aeiouy]|qu)ies$/i, '\1y'],
64
+ [/([^aeiouy]|qu)y$/i, '\1ies'], # query, ability, agency
65
+ [/(?:([^f])fe|([lr])f)$/i, '\1\2ves'], # half, safe, wife
66
+ [/sis$/i, 'ses'], # basis, diagnosis
67
+ [/([ti])um$/i, '\1a'], # datum, medium
68
+ [/(p)erson$/i, '\1\2eople'], # person, salesperson
69
+ [/(m)an$/i, '\1\2en'], # man, woman, spokesman
70
+ [/(c)hild$/i, '\1\2hildren'], # child
71
+ [/s$/i, 's'], # no change (compatibility)
72
72
  [/$/, 's']
73
73
  ]
74
74
  end
75
75
 
76
76
  def singular_rules #:doc:
77
77
  [
78
- [/fish$/, 'fish'],
79
- [/(x|ch|ss|sh)es$/, '\1'],
80
- [/movies$/, 'movie'],
81
- [/series$/, 'series'],
82
- [/([^aeiouy]|qu)ies$/, '\1y'],
83
- [/([lr])ves$/, '\1f'],
84
- [/([^f])ves$/, '\1fe'],
85
- [/(analy|ba|diagno|parenthe|progno|synop|the)ses$/, '\1sis'],
86
- [/([ti])a$/, '\1um'],
87
- [/people$/, 'person'],
88
- [/men$/, 'man'],
89
- [/status$/, 'status'],
90
- [/children$/, 'child'],
91
- [/news$/, 'news'],
92
- [/s$/, '']
78
+ [/(f)ish$/i, '\1\2ish'],
79
+ [/(x|ch|ss|sh)es$/i, '\1'],
80
+ [/(m)ovies$/i, '\1\2ovie'],
81
+ [/(s)eries$/i, '\1\2eries'],
82
+ [/([^aeiouy]|qu)ies$/i, '\1y'],
83
+ [/([lr])ves$/i, '\1f'],
84
+ [/([^f])ves$/i, '\1fe'],
85
+ [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis'],
86
+ [/([ti])a$/i, '\1um'],
87
+ [/(p)eople$/i, '\1\2erson'],
88
+ [/(m)en$/i, '\1\2an'],
89
+ [/(s)tatus$/i, '\1\2tatus'],
90
+ [/(c)hildren$/i, '\1\2hild'],
91
+ [/(n)ews$/i, '\1\2ews'],
92
+ [/s$/i, '']
93
93
  ]
94
94
  end
95
95
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.8
3
3
  specification_version: 1
4
4
  name: activesupport
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.2
7
- date: 2005-03-22
6
+ version: 1.0.3
7
+ date: 2005-03-27
8
8
  summary: Support and utility classes used by the Rails framework.
9
9
  require_paths:
10
10
  - lib
@@ -47,6 +47,7 @@ files:
47
47
  - lib/active_support/core_ext/hash
48
48
  - lib/active_support/core_ext/hash.rb
49
49
  - lib/active_support/core_ext/kernel.rb
50
+ - lib/active_support/core_ext/load_error.rb
50
51
  - lib/active_support/core_ext/numeric
51
52
  - lib/active_support/core_ext/numeric.rb
52
53
  - lib/active_support/core_ext/object_and_class.rb