Sha256: 335e10b1d881d952fff6eb2b738b271c1aab80db8be71c67ac3a31e715a574cb

Contents?: true

Size: 857 Bytes

Versions: 4

Compression:

Stored size: 857 Bytes

Contents

require 'base64'

module SafeYAML
  class Transform
    TRANSFORMERS = [
      Transform::ToSymbol.new,
      Transform::ToInteger.new,
      Transform::ToFloat.new,
      Transform::ToNil.new,
      Transform::ToBoolean.new,
      Transform::ToDate.new,
      Transform::ToTime.new
    ]

    def self.to_guessed_type(value, quoted=false)
      return value if quoted

      if value.is_a?(String)
        TRANSFORMERS.each do |transformer|
          success, transformed_value = transformer.transform?(value)
          return transformed_value if success
        end
      end

      value
    end

    def self.to_proper_type(value, quoted=false, tag=nil)
      case tag
      when "tag:yaml.org,2002:binary", "x-private:binary", "!binary"
        Base64.decode64(value)
      else
        self.to_guessed_type(value, quoted)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
safe_yaml-0.8.3 lib/safe_yaml/transform.rb
safe_yaml-0.8.2 lib/safe_yaml/transform.rb
safe_yaml-0.8.1 lib/safe_yaml/transform.rb
safe_yaml-0.8.0 lib/safe_yaml/transform.rb