Sha256: 07d4d479f67268d0826d62d44e307603da12a3d5040aeed8413f3b77d6af4957

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

module Integrity
  module Helpers
    module Urls
      def root_url
        @url ||= Addressable::URI.parse(base_url)
      end

      def root_path(path="")
        url(path).path
      end

      def project_url(project, *path)
        url("/" << [project.permalink, *path].flatten.join("/"))
      end

      def project_path(project, *path)
        project_url(project, path).path
      end

      def commit_url(commit)
        project_url(commit.project, "commits", commit.identifier)
      end

      def commit_path(commit, *path)
        commit_url(commit).path
      end

      def build_path(build, *path)
        warn "#build_path is deprecated, use #commit_path instead (#{caller[0]})"
        commit_path build.commit, *path
      end

      def build_url(build)
        warn "#build_url is deprecated, use #commit_url instead (#{caller[0]})"
        commit_url build.commit
      end

      def push_url_for(project)
        Addressable::URI.parse(project_url(project, "push")).tap do |url|
          if Integrity.config[:use_basic_auth]
            url.user     = Integrity.config[:admin_username]
            url.password = Integrity.config[:hash_admin_password] ?
              "<password>" : Integrity.config[:admin_password]
          end
        end.to_s
      end

      private
        def url(path="")
          root_url.dup.tap { |url| url.path = root_url.path + path }
        end

        def base_url
          Integrity.config[:base_uri] || ((respond_to?(:request) &&
            request.respond_to?(:url)) ? request.url : fail("set base_uri"))
        end
    end
  end
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
alphasights-integrity-0.1.9.3 lib/integrity/helpers/urls.rb
alphasights-integrity-0.1.9.4 lib/integrity/helpers/urls.rb
alphasights-integrity-0.1.9.5 lib/integrity/helpers/urls.rb
alphasights-integrity-0.1.9.6 lib/integrity/helpers/urls.rb
alphasights-integrity-0.1.9.7 lib/integrity/helpers/urls.rb
alphasights-integrity-0.1.9.8 lib/integrity/helpers/urls.rb
foca-integrity-0.1.9.2 lib/integrity/helpers/urls.rb
foca-integrity-0.1.9.3 lib/integrity/helpers/urls.rb
gforces-integrity-0.1.9.3 lib/integrity/helpers/urls.rb
gforces-integrity-0.1.9.4 lib/integrity/helpers/urls.rb
imbriaco-integrity-0.1.9.2.1 lib/integrity/helpers/urls.rb
imbriaco-integrity-0.1.9.2 lib/integrity/helpers/urls.rb
integrity-integrity-0.1.9.3 lib/integrity/helpers/urls.rb
integrity-0.1.9.3 lib/integrity/helpers/urls.rb
integrity-0.1.9.2 lib/integrity/helpers/urls.rb