Class: Jekyll::GitHubMetadata::RepositoryFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-github-metadata/repository_finder.rb

Constant Summary collapse

NoRepositoryError =
Class.new(Jekyll::Errors::FatalException)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ RepositoryFinder

Returns a new instance of RepositoryFinder


9
10
11
# File 'lib/jekyll-github-metadata/repository_finder.rb', line 9

def initialize(site)
  @site = site
end

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site


8
9
10
# File 'lib/jekyll-github-metadata/repository_finder.rb', line 8

def site
  @site
end

Instance Method Details

#nwoObject

Public: fetches the repository name with owner to fetch metadata for. In order of precedence, this method uses:

  1. the environment variable $PAGES_REPO_NWO

  2. 'repository' variable in the site config

  3. the 'origin' git remote's URL

site - the Jekyll::Site being processed

Return the name with owner (e.g. 'parkr/my-repo') or raises an error if one cannot be found.


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jekyll-github-metadata/repository_finder.rb', line 23

def nwo
  @nwo ||= begin
    nwo_from_env || \
      nwo_from_config || \
      nwo_from_git_origin_remote || \
      proc do
        raise NoRepositoryError, "No repo name found. " \
          "Specify using PAGES_REPO_NWO environment variables, " \
          "'repository' in your configuration, or set up an 'origin' " \
          "git remote pointing to your github.com repository."
      end.call
  end
end