Sha256: 25ee15442d3110232025a30f94c48cb1e4bd0eb948be0db089cfeea31631b211

Contents?: true

Size: 1.29 KB

Versions: 91

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'active_support/core_ext/module/delegation'
require 'eac_ruby_utils/core_ext'
require 'yaml'

module Aranha
  module Parsers
    class SourceAddress
      require_sub __FILE__

      class << self
        SUBS = [
          ::Aranha::Parsers::SourceAddress::HashHttpGet,
          ::Aranha::Parsers::SourceAddress::HashHttpPost,
          ::Aranha::Parsers::SourceAddress::HttpGet,
          ::Aranha::Parsers::SourceAddress::File
        ].freeze

        def detect_sub(source)
          return source.sub if source.is_a?(self)

          SUBS.each do |sub|
            return sub.new(source) if sub.valid_source?(source)
          end
          raise "No content fetcher found for source \"#{source}\""
        end

        def deserialize(string)
          new(string =~ %r{\A[a-z]+://} ? string.strip : ::YAML.load(string)) # rubocop:disable Security/YAMLLoad
        end

        def from_file(path)
          deserialize(::File.read(path))
        end
      end

      enable_simple_cache
      common_constructor :source
      delegate :content, :url, to: :sub

      def to_s
        sub.url
      end

      def serialize
        sub.serialize.strip + "\n"
      end

      private

      def sub_uncached
        self.class.detect_sub(source)
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 3 rubygems

Version Path
eac_tools-0.55.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.54.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.53.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.52.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.51.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.50.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.49.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.48.1 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.48.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.47.2 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.47.1 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.47.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.46.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.45.2 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.45.1 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.45.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.44.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.43.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.42.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb
eac_tools-0.41.0 sub/aranha-parsers/lib/aranha/parsers/source_address.rb