Sha256: 8d37042505b791d59283241a7f3b2c45188bde09f003e9d41721680ec3ee6cc2
Contents?: true
Size: 819 Bytes
Versions: 2
Compression:
Stored size: 819 Bytes
Contents
# frozen_string_literal: true module Zilla::LoaderFactory class UnknownLoader < Zilla::Error; end class << self def build(input, faraday_config: {}, &block) case input when Hash Zilla::Loaders::Hash when String for_string(input) end.new(input, faraday_config:, faraday_config_block: block) rescue NoMethodError raise UnknownLoader, "cannot find loader for #{input.inspect}" end private def for_string(string) if File.exist?(string) Zilla::Loaders::File elsif ["http", "https"].any? { string.start_with?(_1) } Zilla::Loaders::HTTP elsif json?(string) Zilla::Loaders::String end end def json?(string) Oj.load(string) true rescue Oj::ParseError false end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
zilla-0.1.5 | lib/zilla/loader_factory.rb |
zilla-0.1.4 | lib/zilla/loader_factory.rb |