From 54c393f5fa2dfd5ff5866cba74e7179f493732df Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 20 Sep 2006 09:34:29 +0000 Subject: Hash.create_from_xml has been renamed to Hash.from_xml, alias will exist until Rails 2.0 [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5149 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/cgi_ext/cgi_methods.rb | 2 +- activeresource/lib/active_resource/connection.rb | 2 +- activeresource/lib/active_resource/validations.rb | 2 +- activesupport/CHANGELOG | 4 +++- activesupport/lib/active_support/core_ext/hash/conversions.rb | 9 +++++++-- activesupport/test/core_ext/hash_ext_test.rb | 8 ++++---- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb index de412a4683..aec6ea9284 100755 --- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb +++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb @@ -49,7 +49,7 @@ class CGIMethods #:nodoc: when Proc strategy.call(raw_post_data) when :xml_simple - raw_post_data.blank? ? {} : Hash.create_from_xml(raw_post_data) + raw_post_data.blank? ? {} : Hash.from_xml(raw_post_data) when :yaml YAML.load(raw_post_data) when :xml_node diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 21573a34cb..920e5a15b0 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -43,7 +43,7 @@ module ActiveResource end def get(path) - Hash.create_from_xml(request(:get, path).body) + Hash.from_xml(request(:get, path).body) end def delete(path) diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb index 8414e93293..f1995a6070 100644 --- a/activeresource/lib/active_resource/validations.rb +++ b/activeresource/lib/active_resource/validations.rb @@ -87,7 +87,7 @@ module ActiveResource def from_xml(xml) clear humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.humanize => attr_name) } - messages = Hash.create_from_xml(xml)['errors']['error'] rescue [] + messages = Hash.from_xml(xml)['errors']['error'] rescue [] messages.each do |message| attr_message = humanized_attributes.keys.detect do |attr_name| if message[0, attr_name.size + 1] == "#{attr_name} " diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index b2a5cd1cd8..570b9b0988 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Hash.create_from_xml has been renamed to Hash.from_xml, alias will exist until Rails 2.0 [DHH] + * alias_method_chain works with accessor= methods also. #6153 [Caio Chassot] * Fix loadable_constants_for_path to handle load paths that do not end with a slash. [Nicholas Seckar] @@ -12,7 +14,7 @@ * Don't pad remaining places with in_groups_of if specified padding value is false. [Marcel Molina Jr.] -* Fix cases where empty xml nodes weren't being translated to nil in Hash.create_from_xml [Rick Olson] +* Fix cases where empty xml nodes weren't being translated to nil in Hash.create_from_xml [Rick Olso n] # => { :type => 'date' } # WRONG # => nil # RIGHT diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index fdc5a165b0..de67b0b00d 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -77,14 +77,19 @@ module ActiveSupport #:nodoc: end module ClassMethods - def create_from_xml(xml) + def from_xml(xml) # TODO: Refactor this into something much cleaner that doesn't rely on XmlSimple undasherize_keys(typecast_xml_value(XmlSimple.xml_in(xml, 'forcearray' => false, 'forcecontent' => true, 'keeproot' => true, 'contentkey' => '__content__') - )) + )) + end + + def create_from_xml(xml) + ActiveSupport::Deprecation.warn("Hash.create_from_xml has been renamed to Hash.from_xml", caller) + from_xml(xml) end private diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index d2372dcc32..df4aadfbcc 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -336,7 +336,7 @@ class HashToXmlTest < Test::Unit::TestCase :parent_id => nil }.stringify_keys - assert_equal expected_topic_hash, Hash.create_from_xml(topic_xml)["topic"] + assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["topic"] end def test_single_record_from_xml_with_nil_values @@ -360,7 +360,7 @@ class HashToXmlTest < Test::Unit::TestCase :parent_id => nil }.stringify_keys - assert_equal expected_topic_hash, Hash.create_from_xml(topic_xml)["topic"] + assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["topic"] end def test_multiple_records_from_xml @@ -406,7 +406,7 @@ class HashToXmlTest < Test::Unit::TestCase :parent_id => nil }.stringify_keys - assert_equal expected_topic_hash, Hash.create_from_xml(topics_xml)["topics"]["topic"].first + assert_equal expected_topic_hash, Hash.from_xml(topics_xml)["topics"]["topic"].first end def test_single_record_from_xml_with_attributes_other_than_type @@ -429,7 +429,7 @@ class HashToXmlTest < Test::Unit::TestCase :isfamily => "0", }.stringify_keys - assert_equal expected_topic_hash, Hash.create_from_xml(topic_xml)["rsp"]["photos"]["photo"] + assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] end def test_should_use_default_value_for_unknown_key -- cgit v1.2.3