activesupport 1.0.0 → 1.0.1

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,3 +1,16 @@
1
+ *1.0.1* (7th March, 2005)
2
+
3
+ * Fixed Hash#indifferent_access to also deal with include? and fetch and nested hashes #726 [Nicholas Seckar]
4
+
5
+ * Added Object#blank? -- see http://redhanded.hobix.com/inspect/objectBlank.html #783 [_why the lucky stiff]
6
+
7
+ * Added inflection rules for "sh" words, like "wish" and "fish" #755 [phillip@pjbsoftware.com]
8
+
9
+ * Fixed an exception when using Ajax based requests from Safari because Safari appends a \000 to the post body. Symbols can't have \000 in them so indifferent access would throw an exception in the constructor. Indifferent hashes now use strings internally instead. #746 [Tobias Luetke]
10
+
11
+ * Added String#to_time and String#to_date for wrapping ParseDate
12
+
13
+
1
14
  *1.0.0* (24th February, 2005)
2
15
 
3
16
  * Added TimeZone as the first of a number of value objects that among others Active Record can use rich value objects using composed_of #688 [Jamis Buck]
@@ -23,6 +23,10 @@
23
23
 
24
24
  $:.unshift(File.dirname(__FILE__))
25
25
 
26
+ require 'active_support/class_attribute_accessors'
27
+ require 'active_support/class_inheritable_attributes'
28
+ require 'active_support/inflector'
29
+
26
30
  require 'active_support/core_ext'
27
31
  require 'active_support/clean_logger'
28
32
  require 'active_support/misc'
@@ -1,8 +1,9 @@
1
+ # This implementation is HODEL-HASH-9600 compliant
1
2
  class HashWithIndifferentAccess < Hash
2
- def initialize(constructor)
3
+ def initialize(constructor = {})
3
4
  if constructor.is_a?(Hash)
4
5
  super()
5
- update(constructor.symbolize_keys)
6
+ update(constructor.stringify_keys)
6
7
  else
7
8
  super(constructor)
8
9
  end
@@ -12,7 +13,7 @@ class HashWithIndifferentAccess < Hash
12
13
 
13
14
  def [](key)
14
15
  case key
15
- when Symbol: regular_reader(key) || regular_reader(key.to_s)
16
+ when Symbol: regular_reader(key.to_s) || regular_reader(key)
16
17
  when String: regular_reader(key) || regular_reader(key.to_sym)
17
18
  else regular_reader(key)
18
19
  end
@@ -21,8 +22,35 @@ class HashWithIndifferentAccess < Hash
21
22
  alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
22
23
 
23
24
  def []=(key, value)
24
- regular_writer(key.is_a?(String) ? key.to_sym : key, value)
25
+ regular_writer(convert_key(key), convert_value(value))
25
26
  end
27
+ def update(hash)
28
+ hash.each {|key, value| self[key] = value}
29
+ end
30
+
31
+ def key?(key)
32
+ super(convert_key(key))
33
+ end
34
+
35
+ alias_method :include?, :key?
36
+ alias_method :has_key?, :key?
37
+ alias_method :member?, :key?
38
+
39
+ def fetch(key, *extras)
40
+ super(convert_key(key), *extras)
41
+ end
42
+
43
+ def values_at(*indices)
44
+ indices.collect {|key| self[convert_key(key)]}
45
+ end
46
+
47
+ protected
48
+ def convert_key(key)
49
+ key.kind_of?(Symbol) ? key.to_s : key
50
+ end
51
+ def convert_value(value)
52
+ value.is_a?(Hash) ? value.with_indifferent_access : value
53
+ end
26
54
  end
27
55
 
28
56
  module ActiveSupport #:nodoc:
@@ -11,6 +11,16 @@ class Object #:nodoc:
11
11
  end
12
12
  subclasses
13
13
  end
14
+
15
+ def blank?
16
+ if respond_to? :empty?
17
+ empty?
18
+ elsif respond_to? :zero?
19
+ zero?
20
+ else
21
+ !self
22
+ end
23
+ end
14
24
  end
15
25
 
16
26
  class Class #:nodoc:
@@ -1,5 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/string/inflections'
2
+ require File.dirname(__FILE__) + '/string/conversions'
2
3
 
3
4
  class String #:nodoc:
4
5
  include ActiveSupport::CoreExtensions::String::Inflections
6
+ include ActiveSupport::CoreExtensions::String::Conversions
5
7
  end
@@ -0,0 +1,19 @@
1
+ require 'parsedate'
2
+
3
+ module ActiveSupport #:nodoc:
4
+ module CoreExtensions #:nodoc:
5
+ module String #:nodoc:
6
+ # Converting strings to other objects
7
+ module Conversions
8
+ # Form can be either :utc (default) or :local.
9
+ def to_time(form = :utc)
10
+ ::Time.send(form, *ParseDate.parsedate(self))
11
+ end
12
+
13
+ def to_date
14
+ ::Date.new(*ParseDate.parsedate(self)[0..2])
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -36,7 +36,8 @@ module Dependencies
36
36
  end
37
37
 
38
38
  def require_or_load(file_name)
39
- load? ? load("#{file_name}.rb") : require(file_name)
39
+ file_name = "#{file_name}.rb" unless ! load? || /\.rb$/ =~ file_name
40
+ load? ? load(file_name) : require(file_name)
40
41
  end
41
42
 
42
43
  def remove_subclasses_for(*classes)
@@ -62,6 +63,7 @@ module Dependencies
62
63
  @root = root
63
64
  end
64
65
 
66
+ def root?() self.root == self end
65
67
  def load_paths() self.root.load_paths end
66
68
 
67
69
  # Load missing constants if possible.
@@ -78,10 +80,19 @@ module Dependencies
78
80
  next unless fs_path
79
81
 
80
82
  if File.directory?(fs_path)
81
- self.const_set name, LoadingModule.new(self.root, self.path + [name])
83
+ new_module = LoadingModule.new(self.root, self.path + [name])
84
+ self.const_set name, new_module
85
+ if self.root?
86
+ raise NameError, "Cannot load controller module named #{name}: An object of type #{Object.const_get(name).class.to_s} already exists." \
87
+ if Object.const_defined?(name)
88
+ Object.const_set(name, new_module)
89
+ end
82
90
  break
83
91
  elsif File.file?(fs_path)
84
92
  self.root.load_file!(fs_path)
93
+
94
+ # Import the loaded constant from Object provided we are the root node.
95
+ self.const_set(name, Object.const_get(name)) if self.root? && Object.const_defined?(name)
85
96
  break
86
97
  end
87
98
  end
@@ -109,17 +120,13 @@ module Dependencies
109
120
 
110
121
  # Load the source file at the given file path
111
122
  def load_file!(file_path)
112
- begin root.module_eval(IO.read(file_path), file_path, 1)
113
- rescue Object => exception
114
- exception.blame_file! file_path
115
- raise
116
- end
123
+ require_dependency(file_path)
117
124
  end
118
125
 
119
126
  # Erase all items in this module
120
127
  def clear!
121
128
  constants.each do |name|
122
- Object.send(:remove_const, name) if Object.const_defined?(name) && self.path.empty?
129
+ Object.send(:remove_const, name) if Object.const_defined?(name)
123
130
  self.send(:remove_const, name)
124
131
  end
125
132
  end
@@ -57,6 +57,7 @@ module Inflector
57
57
  private
58
58
  def plural_rules #:doc:
59
59
  [
60
+ [/fish$/, 'fish'], # fish
60
61
  [/(x|ch|ss|sh)$/, '\1es'], # search, switch, fix, box, process, address
61
62
  [/series$/, '\1series'],
62
63
  [/([^aeiouy]|qu)ies$/, '\1y'],
@@ -74,7 +75,8 @@ module Inflector
74
75
 
75
76
  def singular_rules #:doc:
76
77
  [
77
- [/(x|ch|ss)es$/, '\1'],
78
+ [/fish$/, 'fish'],
79
+ [/(x|ch|ss|sh)es$/, '\1'],
78
80
  [/movies$/, 'movie'],
79
81
  [/series$/, 'series'],
80
82
  [/([^aeiouy]|qu)ies$/, '\1y'],
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.4
2
+ rubygems_version: 0.8.6
3
3
  specification_version: 1
4
4
  name: activesupport
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2005-02-24
6
+ version: 1.0.1
7
+ date: 2005-03-07
8
8
  summary: Support and utility classes used by the Rails framework.
9
9
  require_paths:
10
10
  - lib
@@ -58,6 +58,7 @@ files:
58
58
  - lib/active_support/core_ext/hash/keys.rb
59
59
  - lib/active_support/core_ext/numeric/bytes.rb
60
60
  - lib/active_support/core_ext/numeric/time.rb
61
+ - lib/active_support/core_ext/string/conversions.rb
61
62
  - lib/active_support/core_ext/string/inflections.rb
62
63
  - lib/active_support/core_ext/time/calculations.rb
63
64
  - lib/active_support/core_ext/time/conversions.rb