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 --- 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 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support') 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 --- .../lib/active_support/core_ext/big_decimal/conversions.rb | 7 +------ activesupport/lib/active_support/ordered_hash.rb | 6 +----- 2 files changed, 2 insertions(+), 11 deletions(-) (limited to 'activesupport/lib/active_support') 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| -- 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(-) (limited to 'activesupport/lib/active_support') 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(-) (limited to 'activesupport/lib/active_support') 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(-) (limited to 'activesupport/lib/active_support') 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(-) (limited to 'activesupport/lib/active_support') 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