Sha256: 2cd302188000fc235a2c9e4241f147715a4e42ea8ba6c6c0ba0be5a63d62c0e1

Contents?: true

Size: 664 Bytes

Versions: 1

Compression:

Stored size: 664 Bytes

Contents

module ActiveLoader
  UnknownTypeError = Class.new(TypeError)

  class LoaderDispatcher
    def initialize(content, type)
      @content = content
      @type = type
    end

    def call
      if type == :json
        load_json
      elsif [:yaml, :yml].include?(type)
        load_yaml
      else
        raise UnknownTypeError, "Unknown type of file: #{type}."
      end
    end

    private

      attr_reader :content, :type

      def load_yaml
        require "active_loader/yaml_loader"
        YamlLoader.new(content).call
      end

      def load_json
        require "active_loader/json_loader"
        JsonLoader.new(content).call
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_loader-1.0.0 lib/active_loader/loader_dispatcher.rb