Sha256: 9de1e90f6e9d922a806920f49b67086f0ac787cf6c4d739d2dc6dee3aa06194e

Contents?: true

Size: 680 Bytes

Versions: 13

Compression:

Stored size: 680 Bytes

Contents

# frozen_string_literal: true

require_relative '../checks'

module Github
  # Methods for dealing with GitHub paths.
  class Paths
    class << self
      include Checks

      # "<owner>/<repo>/<ref>/<some_path>"
      PATH_PATTERN = %r{^(?:[^/]+/){3}.*[^/]$}
      private_constant :PATH_PATTERN

      # Parses a path like "<owner>/<repo>/<ref>/<some_path>" into owner, repo, ref, path.
      def parse_file_path(path)
        check_non_empty_string(path: path)
        raise "invalid path: #{path}" unless PATH_PATTERN.match?(path)

        owner, repo, ref, *path = path.split('/')
        path = path.join('/')

        [owner, repo, ref, path]
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sqlui-0.1.84 app/github/paths.rb
sqlui-0.1.83 app/github/paths.rb
sqlui-0.1.82 app/github/paths.rb
sqlui-0.1.81 app/github/paths.rb
sqlui-0.1.80 app/github/paths.rb
sqlui-0.1.79 app/github/paths.rb
sqlui-0.1.78 app/github/paths.rb
sqlui-0.1.77 app/github/paths.rb
sqlui-0.1.76 app/github/paths.rb
sqlui-0.1.75 app/github/paths.rb
sqlui-0.1.74 app/github/paths.rb
sqlui-0.1.73 app/github/paths.rb
sqlui-0.1.72 app/github/paths.rb