Sha256: 2832fa6a0f9eaff123af5e472fdb6631286a8f942cb6c4e4e65049f3accfb864

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 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.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.0 lib/pod/src/rewriter.rb