Sha256: 6e99648f464f8c188b464880fae9a2842fdd873ec17fc9d8dcbc99b9ec969f1c
Contents?: true
Size: 1.86 KB
Versions: 2
Compression:
Stored size: 1.86 KB
Contents
# frozen_string_literal: true module Bundler module Alive # Represents a source code repository class SourceCodeRepositoryUrl # service domain with service DOMAIN_WITH_SERVICES = { "github.com" => SourceCodeRepository::Service::GITHUB, "www.github.com" => SourceCodeRepository::Service::GITHUB }.freeze private_constant :DOMAIN_WITH_SERVICES # # Judge supported url or not # # @param [String] url # # @return [Boolean] # def self.support_url?(url) return false if url.nil? uri = URI.parse(url) host = uri.host DOMAIN_WITH_SERVICES.key?(host) end # No supported URL Error class UnSupportedUrl < StandardError # # @param [String] :url # @param [String] :name # # @return [UnSupportedUrl] # def initialize(url:, name:) decorated_url = if url.nil? || url == "" "(blank)" else url end message = "[#{name}] is not support URL: #{decorated_url}" super(message) end end attr_reader :url, :service_name, :gem_name # # Creates a `SourceCodeRepositoryUrl` # # @param [String] url # @param [String] name # # @raise [UnSupportedUrl] # def initialize(url, name) raise UnSupportedUrl.new(url: url, name: name) if url.nil? @url = url @service_name = service(url: url, name: name) @gem_name = name end private def service(url:, name:) uri = URI.parse(url) host = uri.host raise UnSupportedUrl.new(url: url, name: name) unless DOMAIN_WITH_SERVICES.key?(host) DOMAIN_WITH_SERVICES[host] end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bundler-alive-0.1.4 | lib/bundler/alive/source_code_repository_url.rb |
bundler-alive-0.1.3 | lib/bundler/alive/source_code_repository_url.rb |