Skip to content

Make things a bit more OO #39

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

Merged
merged 13 commits into from
Feb 12, 2016
Merged

Make things a bit more OO #39

merged 13 commits into from
Feb 12, 2016

Conversation

benbalter
Copy link
Contributor

This pull request started out as an attempt to add a Repository class, that could accept a repository name and retrieve the repository's CNAME, but expanded to abstract much of the check logic out of a single giant class, into more object-oriented classes. Specifically:

  • Move domain-specific checks to the Domain class
  • Add new repo-level checks to a Repository class
  • Create a new Site class to encompass Domain and Repository checks
  • Abstract check!, valid? and reason logic to a Checkable class
  • Create an Errors class to autoload all errors
  • Make GitHubPages and HealthCheck modules, not classes

Still to do:

  • Tests

@benbalter benbalter self-assigned this Feb 12, 2016

class GitHubPages
class HealthCheck
if File.exists?(File.expand_path ".env", File.dirname(__FILE__))
Copy link
Contributor

Choose a reason for hiding this comment

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

You'd vendor a .env inside of lib/?

attr_reader :host

def initialize(host)
@host = host_from_uri(host)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to defensively check the input here:

raise ArgumentError, "Expected string, got #{host.class}" unless host.is_a? String

I see a lot of undefined method for NilClass:nil in our future without it :)


def initialize(name_with_owner, access_token: nil)
unless name_with_owner =~ REPO_REGEX
raise GitHubPages::HealthCheck::Errors::InvalidRepositoryError
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with the rest of the class, this should either be Errors::InvalidRepositoryError, or all the others should have GitHubPages::HealthCheck:: 😄

@benbalter
Copy link
Contributor Author

@parkr believe this should be ready for one more 👀, when you're ready. I believe I implemented everything you mentioned, plus tests, and simplified the to_hash logic by moving the methods that should become part of the hash logic to checkable.

@benbalter benbalter changed the title WIP: Make things a bit more OO Make things a bit more OO Feb 12, 2016
> check.valid?
=> false
> check.valid!
=> GitHubPages::HealthCheck::InvalidCNAME
=> GitHubPages::HealthCheck::Errors::InvalidCNAMEError
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this return the class or raise an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Raises. What's the best way to note that?

@parkr
Copy link
Contributor

parkr commented Feb 12, 2016

:shipit:

Can we also ship #37?

@benbalter
Copy link
Contributor Author

Can we also ship #37?

Looks like the conflict should be minimal. Once this merges, I can work on reconcile #37 and we can release a new version.

benbalter added a commit that referenced this pull request Feb 12, 2016
Make things a bit more OO
@benbalter benbalter merged commit 7f402ee into master Feb 12, 2016
@benbalter benbalter deleted the moar-oo branch February 12, 2016 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants