Sha256: e95e5d1bb6c2e95654628e44e113b163ba01d57075ace79d487b3edad807e4b7

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 KB

Contents

require 'tempfile'

module Dandelion
  module Backend
    class MissingFileError < StandardError; end
    class UnsupportedSchemeError < StandardError; end
    
    class MissingDependencyError < StandardError
      attr_reader :gems
      
      def initialize(gems)
        @gems = gems
      end
    end

    class Base
      class << self
        @@backends = {}
        
        def create(config)
          Dir.glob(File.join(File.dirname(__FILE__), 'backend', '*.rb')) { |file| require file }
          raise UnsupportedSchemeError unless @@backends.include?(config['scheme'])
          begin
            @@backends[config['scheme']].new(config)
          rescue LoadError
            raise MissingDependencyError.new(@@backends[config['scheme']].gem_list)
          end
        end
        
        def scheme(scheme)
          @@backends[scheme] = self
        end
        
        def gems(*gems)
          @gems = gems
        end
        
        def gem_list
          @gems
        end
      end

      protected

      def temp(file, data)
        tmp = Tempfile.new(file.gsub('/', '.'))
        tmp << data
        tmp.flush
        yield(tmp.path)
        tmp.close
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dandelion-0.3.15 lib/dandelion/backend.rb
dandelion-0.3.14 lib/dandelion/backend.rb
dandelion-0.3.13 lib/dandelion/backend.rb
dandelion-0.3.12 lib/dandelion/backend.rb
dandelion-0.3.11 lib/dandelion/backend.rb
dandelion-0.3.10 lib/dandelion/backend.rb
dandelion-0.3.9 lib/dandelion/backend.rb
dandelion-0.3.8 lib/dandelion/backend.rb
dandelion-0.3.7 lib/dandelion/backend.rb
dandelion-0.3.6 lib/dandelion/backend.rb
dandelion-0.3.5 lib/dandelion/backend.rb
dandelion-0.3.4 lib/dandelion/backend.rb
dandelion-0.3.3 lib/dandelion/backend.rb
dandelion-0.3.2 lib/dandelion/backend.rb
dandelion-0.3.1 lib/dandelion/backend.rb
dandelion-0.3.0 lib/dandelion/backend.rb