Skip to content

Commit

Permalink
Merge pull request #160 from jekyll/site-owner-should-be-a-hash
Browse files Browse the repository at this point in the history
site.owner should be a Hash in the final value
  • Loading branch information
parkr authored Feb 11, 2019
2 parents 7d3eb76 + b64a6d3 commit 390dea6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
15 changes: 8 additions & 7 deletions lib/jekyll-github-metadata/owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,22 @@ def initialize(owner_login)
@owner_login = owner_login
end

def to_s
require "json"
JSON.pretty_generate to_h
end
alias_method :to_str, :to_s

def to_h
self.class.content_methods.each_with_object({}) { |method, hash| hash[method] = public_send(method) }
@to_h ||= self.class.content_methods
.each_with_object({}) { |method, hash| hash[method.to_s] = public_send(method) }
end
alias_method :to_hash, :to_h
def_delegator :to_h, :to_json, :to_json

def_delegator :to_h, :to_s, :to_s
alias_method :to_str, :to_s

private

def owner_info
@owner_info ||= begin
Value.new(
"owner",
proc do |c|
(c.organization(owner_login) || c.user(owner_login) || {}).to_h
end
Expand Down
16 changes: 8 additions & 8 deletions lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ def repo_compat
def repo_info
@repo_info ||= begin
options = { :accept => "application/vnd.github.drax-preview+json" }
(Value.new(proc { |c| c.repository(nwo, options) }).render || {})
(Value.new("repo_info", proc { |c| c.repository(nwo, options) }).render || {})
end
end

def repo_pages_info
@repo_pages_info ||= (Value.new(proc { |c| c.pages(nwo, repo_pages_info_opts) }).render || {})
@repo_pages_info ||= (Value.new("repo_pages_info", proc { |c| c.pages(nwo, repo_pages_info_opts) }).render || {})
end

def repo_pages_info_opts
Expand Down Expand Up @@ -103,29 +103,29 @@ def wiki_url
end

def organization_repository?
memoize_value :@is_organization_repository, Value.new(proc { |c| !!c.organization(owner) })
memoize_value :@is_organization_repository, Value.new("organization_repository?", proc { |c| !!c.organization(owner) })
end

def owner_public_repositories
memoize_value :@owner_public_repositories, Value.new(proc { |c| c.list_repos(owner, "type" => "public") })
memoize_value :@owner_public_repositories, Value.new("owner_public_repositories", proc { |c| c.list_repos(owner, "type" => "public") })
end

def organization_public_members
memoize_value :@organization_public_members, Value.new(proc do |c|
memoize_value :@organization_public_members, Value.new("organization_public_members", proc do |c|
c.organization_public_members(owner) if organization_repository?
end)
end

def contributors
memoize_value :@contributors, Value.new(proc { |c| c.contributors(nwo) })
memoize_value :@contributors, Value.new("contributors", proc { |c| c.contributors(nwo) })
end

def releases
memoize_value :@releases, Value.new(proc { |c| c.releases(nwo) })
memoize_value :@releases, Value.new("releases", proc { |c| c.releases(nwo) })
end

def latest_release
memoize_value :@latest_release, Value.new(proc { |c| c.latest_release(nwo) })
memoize_value :@latest_release, Value.new("latest_release", proc { |c| c.latest_release(nwo) })
end

def source
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll-github-metadata/sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def sanitize(resource)
true
when NilClass
nil
when String
resource
else
if resource.respond_to?(:to_hash)
sanitize_resource(resource)
Expand Down
4 changes: 4 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@
expect(stub).to have_been_requested
end
end

it "presents the owner data as a Hash" do
expect(subject["owner"]).to be_a(Hash)
end
end
2 changes: 1 addition & 1 deletion spec/spec_helpers/integration_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def expected_values
"build_revision" => %r![a-f0-9]{40}!,
"project_title" => "github-metadata",
"project_tagline" => ":octocat: `site.github`",
"owner" => Regexp.new('"html_url": "https://github.com/jekyll",\s+"id": 3083652'),
"owner" => Regexp.new('"html_url"=>"https://github.com/jekyll",\s+"id"=>3083652'),
"owner_name" => "jekyll",
"owner_url" => "https://github.com/jekyll",
"owner_gravatar_url" => "https://github.com/jekyll.png",
Expand Down

0 comments on commit 390dea6

Please sign in to comment.