From 14ae6ff27fa5169876560dadb6095aeae56eff95 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Fri, 18 Jun 2010 14:52:31 +0200 Subject: [PATCH] added 2.0.4 CFPropertyList --- lib/cfpropertylist/rbCFPlistError.rb | 19 +++++++++++++++++++ lib/cfpropertylist/rbCFPropertyList.rb | 11 ++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 lib/cfpropertylist/rbCFPlistError.rb diff --git a/lib/cfpropertylist/rbCFPlistError.rb b/lib/cfpropertylist/rbCFPlistError.rb new file mode 100644 index 0000000..05d59ee --- /dev/null +++ b/lib/cfpropertylist/rbCFPlistError.rb @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# +# CFFormatError implementation +# +# Author:: Christian Kruse (mailto:cjk@wwwtech.de) +# Copyright:: Copyright (c) 2010 +# License:: MIT License + +class CFPlistError < Exception +end + +# Exception thrown when format errors occur +class CFFormatError < CFPlistError +end + +class CFTypeError < CFPlistError +end + +# eof diff --git a/lib/cfpropertylist/rbCFPropertyList.rb b/lib/cfpropertylist/rbCFPropertyList.rb index 3029c45..a129100 100644 --- a/lib/cfpropertylist/rbCFPropertyList.rb +++ b/lib/cfpropertylist/rbCFPropertyList.rb @@ -55,7 +55,7 @@ module CFPropertyList end dirname = File.dirname(__FILE__) -require dirname + '/rbCFFormatError.rb' +require dirname + '/rbCFPlistError.rb' require dirname + '/rbCFTypes.rb' require dirname + '/rbXMLCFPropertyList.rb' require dirname + '/rbBinaryCFPropertyList.rb' @@ -69,9 +69,12 @@ module CFPropertyList # 'a' => ['b','c','d'] # } # cftypes = CFPropertyList.guess(x) + # + # pass optional options hash. Only possible value actually: + # :convert_unknown_to_string => true + # + # cftypes = CFPropertyList.guess(x,:convert_unknown_to_string => true) def guess(object, options = {}) - return if object.nil? - if(object.is_a?(Fixnum) || object.is_a?(Integer)) then return CFInteger.new(object) elsif(object.is_a?(Float)) then @@ -103,6 +106,8 @@ module CFPropertyList return CFDictionary.new(hsh) elsif options[:convert_unknown_to_string] return CFString.new(object.to_s) + else + raise CFTypeError.new("Unknown class #{object.class.to_s}! Try using :convert_unknown_to_string if you want to use unknown object types!") end end