Sha256: d91e61e5f0a196b780cbed808ee55cd715551c5bc2554495f25f6f89f721449b

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module SourceURLRewriter
  # Used to provide rewritten urls
  # People using this pod would install as follows
  # plugin 'cocoapods-github_token_http_rewriter', {
  #   "pattern" => "replacement"
  # }
  class Rewriter
    def url_for(url)
      if user_options
        transformed_key = transform_key(url)

        if transformed_key
          rewritten_url = url.sub(transformed_key, user_options[transformed_key])
          Pod::UI.info("Transforming URL #{url} into #{rewritten_url}")
          return rewritten_url
        end
      else
        Pod::UI.notice('No options have been specified for rewriting.')
      end

      url
    end

    private

    def transform_key(url)
      user_options.keys.find do |key|
        url.start_with?(key)
      end
    end

    def user_options
      @options ||= podfile && podfile.plugins && podfile.plugins['cocoapods-git_url_rewriter']
      Pod::UI.notice('No options have been specified for rewriting') unless @options
      @options
    end

    def podfile
      Pod::Config.instance.podfile
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocoapods-git_url_rewriter-1.0.1 lib/pod/src/rewriter.rb