From 0bf51e9805260243ec0bbe5fca8f8b9364fdd970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 12:55:11 -0300 Subject: No need to check if YAML::ENGINE is defined since ruby 1.9 does that --- activerecord/lib/active_record/core.rb | 2 +- activesupport/lib/active_support/core_ext/big_decimal/conversions.rb | 2 +- activesupport/lib/active_support/core_ext/string/output_safety.rb | 2 +- activesupport/lib/active_support/ordered_hash.rb | 2 +- activesupport/lib/active_support/time_with_zone.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 980f8fe50f..ee7ff7a2d7 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -319,7 +319,7 @@ module ActiveRecord # Hackery to accomodate Syck. Remove for 4.0. def to_yaml(opts = {}) #:nodoc: - if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? + if !YAML::ENGINE.syck? super else coder = {} diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index 391bdc925d..403e8beac5 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -16,7 +16,7 @@ class BigDecimal # # Note that reconstituting YAML floats to native floats may lose precision. def to_yaml(opts = {}) - return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck? + return super if !YAML::ENGINE.syck? YAML.quick_emit(nil, opts) do |out| string = to_s diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 6cb2ea68b3..4e5675cc8d 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -137,7 +137,7 @@ module ActiveSupport #:nodoc: end def to_yaml(*args) - return super() if defined?(YAML::ENGINE) && !YAML::ENGINE.syck? + return super() if !YAML::ENGINE.syck? to_str.to_yaml(*args) end diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index d4f309fbd7..fdf4a2bda3 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -30,7 +30,7 @@ module ActiveSupport end def to_yaml(opts = {}) - if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? + if !YAML::ENGINE.syck? return super end diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index d3adf671a0..50fe58a006 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -147,7 +147,7 @@ module ActiveSupport end def to_yaml(options = {}) - return super if defined?(YAML::ENGINE) && !YAML::ENGINE.syck? + return super if !YAML::ENGINE.syck? utc.to_yaml(options) end -- cgit v1.2.3 From 761b049b2e51a035eaf9c18f4d0200409848a28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 13:30:57 -0300 Subject: No need to use rescue block to require psych --- activerecord/lib/active_record/base.rb | 6 +--- activerecord/lib/active_record/fixtures.rb | 7 +---- activerecord/lib/active_record/fixtures/file.rb | 6 +--- activerecord/test/cases/yaml_serialization_test.rb | 32 ++++++++++------------ .../core_ext/big_decimal/conversions.rb | 7 +---- activesupport/lib/active_support/ordered_hash.rb | 6 +--- activesupport/test/ordered_hash_test.rb | 22 ++++++--------- activesupport/test/safe_buffer_test.rb | 6 +--- railties/lib/rails/commands/dbconsole.rb | 7 +---- 9 files changed, 30 insertions(+), 69 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d29cf82dad..5ce78ca1c6 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1,8 +1,4 @@ -begin - require 'psych' -rescue LoadError -end - +require 'psych' require 'yaml' require 'set' require 'active_support/benchmarkable' diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 9ea8cf864c..8ae09d3e27 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -1,10 +1,5 @@ require 'erb' - -begin - require 'psych' -rescue LoadError -end - +require 'psych' require 'yaml' require 'zlib' require 'active_support/dependencies' diff --git a/activerecord/lib/active_record/fixtures/file.rb b/activerecord/lib/active_record/fixtures/file.rb index 6bad36abb9..f6fc883ee0 100644 --- a/activerecord/lib/active_record/fixtures/file.rb +++ b/activerecord/lib/active_record/fixtures/file.rb @@ -1,8 +1,4 @@ -begin - require 'psych' -rescue LoadError -end - +require 'psych' require 'erb' require 'yaml' diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index 2b4ec81199..dfdb27e5ab 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -1,4 +1,5 @@ -require "cases/helper" +require 'psych' +require 'cases/helper' require 'models/topic' class YamlSerializationTest < ActiveRecord::TestCase @@ -36,22 +37,17 @@ class YamlSerializationTest < ActiveRecord::TestCase assert_equal({'attributes' => topic.attributes}, coder) end - begin - require 'psych' - - def test_psych_roundtrip - topic = Topic.first - assert topic - t = Psych.load Psych.dump topic - assert_equal topic, t - end - - def test_psych_roundtrip_new_object - topic = Topic.new - assert topic - t = Psych.load Psych.dump topic - assert_equal topic.attributes, t.attributes - end - rescue LoadError + def test_psych_roundtrip + topic = Topic.first + assert topic + t = Psych.load Psych.dump topic + assert_equal topic, t + end + + def test_psych_roundtrip_new_object + topic = Topic.new + assert topic + t = Psych.load Psych.dump topic + assert_equal topic.attributes, t.attributes end end diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index 403e8beac5..c2faa1ebe0 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -1,10 +1,5 @@ require 'bigdecimal' - -begin - require 'psych' -rescue LoadError -end - +require 'psych' require 'yaml' class BigDecimal diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index fdf4a2bda3..7fd4168363 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -1,8 +1,4 @@ -begin - require 'psych' -rescue LoadError -end - +require 'psych' require 'yaml' YAML.add_builtin_type("omap") do |type, val| diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 8119b36491..841088e7e7 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -1,3 +1,4 @@ +require 'psych' require 'abstract_unit' require 'active_support/json' require 'active_support/core_ext/object/to_json' @@ -291,21 +292,16 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal @ordered_hash.values, @deserialized_ordered_hash.values end - begin - require 'psych' + def test_psych_serialize + @deserialized_ordered_hash = Psych.load(Psych.dump(@ordered_hash)) - def test_psych_serialize - @deserialized_ordered_hash = Psych.load(Psych.dump(@ordered_hash)) - - values = @deserialized_ordered_hash.map { |_, value| value } - assert_equal @values, values - end + values = @deserialized_ordered_hash.map { |_, value| value } + assert_equal @values, values + end - def test_psych_serialize_tag - yaml = Psych.dump(@ordered_hash) - assert_match '!omap', yaml - end - rescue LoadError + def test_psych_serialize_tag + yaml = Psych.dump(@ordered_hash) + assert_match '!omap', yaml end def test_has_yaml_tag diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 8d9911ea01..e569e04180 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -1,9 +1,5 @@ require 'abstract_unit' -begin - require 'psych' -rescue LoadError -end - +require 'psych' require 'active_support/core_ext/string/inflections' require 'yaml' diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index d425c9db6c..d71e7f5271 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -1,10 +1,5 @@ require 'erb' - -begin - require 'psych' -rescue LoadError -end - +require 'psych' require 'yaml' require 'optparse' require 'rbconfig' -- cgit v1.2.3 From d8ed247c7f11b1ca4756134e145d2ec3bfeb8eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 14:10:55 -0300 Subject: No need to override the to_yaml method in BigDecimal --- .../active_support/core_ext/big_decimal/conversions.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index c2faa1ebe0..3ec7e576c8 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -1,24 +1,9 @@ require 'bigdecimal' -require 'psych' require 'yaml' class BigDecimal - YAML_TAG = 'tag:yaml.org,2002:float' YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' } - # This emits the number without any scientific notation. - # This is better than self.to_f.to_s since it doesn't lose precision. - # - # Note that reconstituting YAML floats to native floats may lose precision. - def to_yaml(opts = {}) - return super if !YAML::ENGINE.syck? - - YAML.quick_emit(nil, opts) do |out| - string = to_s - out.scalar(YAML_TAG, YAML_MAPPING[string] || string, :plain) - end - end - def encode_with(coder) string = to_s coder.represent_scalar(nil, YAML_MAPPING[string] || string) -- cgit v1.2.3 From ae7dcb4bec3dd274c8773503bc68513c01dae6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 14:14:16 -0300 Subject: No need to override the to_yaml method in ActiveSupporte::SafeBuffer --- activesupport/lib/active_support/core_ext/string/output_safety.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 4e5675cc8d..73aa7dd89a 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -136,11 +136,6 @@ module ActiveSupport #:nodoc: coder.represent_scalar nil, to_str end - def to_yaml(*args) - return super() if !YAML::ENGINE.syck? - to_str.to_yaml(*args) - end - UNSAFE_STRING_METHODS.each do |unsafe_method| if 'String'.respond_to?(unsafe_method) class_eval <<-EOT, __FILE__, __LINE__ + 1 -- cgit v1.2.3 From 25c76ec8e2e17cc3eb42a824c38f78fb9e23e70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 14:15:11 -0300 Subject: No need to override to_yaml method in ActiveSupport::OrderedHash --- activesupport/lib/active_support/ordered_hash.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 7fd4168363..8edd3960c7 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -1,4 +1,3 @@ -require 'psych' require 'yaml' YAML.add_builtin_type("omap") do |type, val| @@ -25,20 +24,6 @@ module ActiveSupport coder.represent_seq '!omap', map { |k,v| { k => v } } end - def to_yaml(opts = {}) - if !YAML::ENGINE.syck? - return super - end - - YAML.quick_emit(self, opts) do |out| - out.seq(taguri) do |seq| - each do |k, v| - seq.add(k => v) - end - end - end - end - def nested_under_indifferent_access self end -- cgit v1.2.3 From b65bdb1527dbf42d94e5722f6764cebac73d103c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 14:16:48 -0300 Subject: No need to override to_yaml method in ActiveSupport::TimeWithZone --- activesupport/lib/active_support/time_with_zone.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 50fe58a006..1cb71012ef 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -1,4 +1,4 @@ -require "active_support/values/time_zone" +require 'active_support/values/time_zone' require 'active_support/core_ext/object/acts_like' require 'active_support/core_ext/object/inclusion' @@ -146,12 +146,6 @@ module ActiveSupport end end - def to_yaml(options = {}) - return super if !YAML::ENGINE.syck? - - utc.to_yaml(options) - end - def httpdate utc.httpdate end -- cgit v1.2.3 From bdc49dcb4ee2af23599965e98fec1bfe21561c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 14:28:01 -0300 Subject: No need to override to_yaml and yaml_initialize methods in ActiveRecord::Core --- activerecord/lib/active_record/core.rb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index ee7ff7a2d7..0755379a74 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -317,26 +317,6 @@ module ActiveRecord "#<#{self.class} #{inspection}>" end - # Hackery to accomodate Syck. Remove for 4.0. - def to_yaml(opts = {}) #:nodoc: - if !YAML::ENGINE.syck? - super - else - coder = {} - encode_with(coder) - YAML.quick_emit(self, opts) do |out| - out.map(taguri, to_yaml_style) do |map| - coder.each { |k, v| map.add(k, v) } - end - end - end - end - - # Hackery to accomodate Syck. Remove for 4.0. - def yaml_initialize(tag, coder) #:nodoc: - init_with(coder) - end - private # Under Ruby 1.9, Array#flatten will call #to_ary (recursively) on each of the elements -- cgit v1.2.3 From 7d26fad384a99aea27e478474f5b8d24ae33b704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 4 Jan 2012 14:29:13 -0300 Subject: No need to require psych since require yaml does that. --- activerecord/lib/active_record/base.rb | 1 - activerecord/lib/active_record/fixtures.rb | 1 - activerecord/lib/active_record/fixtures/file.rb | 1 - activerecord/test/cases/yaml_serialization_test.rb | 1 - activesupport/test/ordered_hash_test.rb | 1 - activesupport/test/safe_buffer_test.rb | 1 - railties/lib/rails/commands/dbconsole.rb | 1 - 7 files changed, 7 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5ce78ca1c6..5c8dbd1b47 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1,4 +1,3 @@ -require 'psych' require 'yaml' require 'set' require 'active_support/benchmarkable' diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 8ae09d3e27..339ba1e19e 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -1,5 +1,4 @@ require 'erb' -require 'psych' require 'yaml' require 'zlib' require 'active_support/dependencies' diff --git a/activerecord/lib/active_record/fixtures/file.rb b/activerecord/lib/active_record/fixtures/file.rb index f6fc883ee0..6547791144 100644 --- a/activerecord/lib/active_record/fixtures/file.rb +++ b/activerecord/lib/active_record/fixtures/file.rb @@ -1,4 +1,3 @@ -require 'psych' require 'erb' require 'yaml' diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index dfdb27e5ab..302913e095 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -1,4 +1,3 @@ -require 'psych' require 'cases/helper' require 'models/topic' diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 841088e7e7..78de7fb6ab 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -1,4 +1,3 @@ -require 'psych' require 'abstract_unit' require 'active_support/json' require 'active_support/core_ext/object/to_json' diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index e569e04180..2fde07995b 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'psych' require 'active_support/core_ext/string/inflections' require 'yaml' diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index d71e7f5271..6fc127efae 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -1,5 +1,4 @@ require 'erb' -require 'psych' require 'yaml' require 'optparse' require 'rbconfig' -- cgit v1.2.3