lib/daijobu/scheme_set.rb in sander6-daijobu-0.2.1 vs lib/daijobu/scheme_set.rb in sander6-daijobu-0.3.0

- old
+ new

@@ -5,16 +5,19 @@ DEFAULT = [ :marshal, :json, :yaml, :eval ] attr_reader :current - # SchemeSet.new takes a single symbol or array of symbols and initializes a new Scheme + # SchemeSet.new takes a single symbol or array of symbols and initializes a new Parser # object of the appropriate type for each one. def initialize(schemes = nil) + @schemes = [] schemes = Array(schemes) schemes = DEFAULT if schemes.empty? - @schemes = schemes.collect { |scheme| Daijobu::Scheme.get(scheme) } + schemes.each do |scheme| + @schemes << (scheme.is_a?(Daijobu::Parser) ? scheme : Daijobu::Parser.get(scheme)) + end @current = 0 end # Returns the next scheme object in the stack. Raises Daijobu::NoFallbackScheme when there # are no more schemes. @@ -32,11 +35,11 @@ # (I know, I know). def reset @current = 0 end - # Tries the parse (load) the string with each scheme in turn. + # Tries to parse (load) the string with each scheme in turn. # Assumes (defensibly) that parsing failed if any non Daijobu::Error exceptions are raised # and moves on to the next scheme. def parse(str) begin obj = self.next.parse(str) @@ -49,10 +52,10 @@ end self.reset obj end - # Tries the unparse (dump) the string with each scheme in turn. + # Tries to unparse (dump) the object with each scheme in turn. # Assumes (defensibly) that unparsing failed if any non Daijobu::Error exceptions are raised # and moves on to the next scheme. def unparse(obj) begin str = self.next.unparse(obj) \ No newline at end of file