Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose repo license #106

Merged
merged 5 commits into from
Aug 14, 2017
Merged

Expose repo license #106

merged 5 commits into from
Aug 14, 2017

Conversation

benbalter
Copy link
Contributor

A follow up to #105, this PR exposes the repository's licenses as site.github.license. I'd like to use this to conditionally expose an "This site is open source, help improve this page" link if a repo is public and has an open source license (versus public but not necessarily looking for contributions).

In doing this, I realized that we had a handful of very similar methods on the Repository model that simply delegated to a hash. Forwardable can't delegate to [], only to the method itself, so I created a quick def_hash_delegator helper, to allow us to DRY things up a bit and delegate a method more easily to a hash key. It works exactly like def_delegator, e.g. def_hash_delegator :repo_info, :license is the same as:

def license
  repo_info["license"]
end

and def_hash_delegator :repo_info, :description, :tagline is the same as:

def tagline
  repo_info["description"]
end

@benbalter benbalter requested a review from parkr August 9, 2017 15:22
Copy link
Member

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One style request, but otherwise 👍 😍

# If not specified, defaults to the hash key
#
# Returns a symbol representing the instance method
def self.def_hash_delegator(hash, key, method = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of these is hard to read. I think this is easier to read:

def self.def_hash_delegator(method, hash, key)

Having the method name only some of the times is hard to grok.

I guess matching it with def_delegator is a noble goal. In that case, I'd say we should always require the method argument. Also, for 👀 sake, maybe align each argument in a table-like format for easy scanning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Implemented via 211fe3d.

@benbalter
Copy link
Contributor Author

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit fefcb85 into master Aug 14, 2017
@jekyllbot jekyllbot deleted the expose-repo-license branch August 14, 2017 14:19
jekyllbot added a commit that referenced this pull request Aug 14, 2017
@benbalter benbalter mentioned this pull request Aug 15, 2017
@jekyll jekyll locked and limited conversation to collaborators Apr 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants