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

Added enum contract #181

Merged
merged 1 commit into from Jul 16, 2015
Merged

Added enum contract #181

merged 1 commit into from Jul 16, 2015

Conversation

ghost
Copy link

@ghost ghost commented Jul 16, 2015

I use contracts.ruby within a configuration class. Some options only allows a given subset of values - symbols. I added a custom contract for that, but thought it might be valueable for others as well.

@@ -201,6 +201,17 @@ def to_s
end
end

# Takes a list of values, e.g. +[:a, :b, :c]A+. If argument is included in the list, the contract passes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you break the comment at 80 characters?

Can you add an example like this # Example: <tt>Enum[:a, :b, :c]</tt>?

@alex-fedorov
Copy link
Collaborator

Can you provide short description for this Pull Request?

Can you add it to list of builtin contracts in TUTORIAL.md?

@ghost
Copy link
Author

ghost commented Jul 16, 2015

Fixed.

@ghost
Copy link
Author

ghost commented Jul 16, 2015

Can you prepare a new release? Are you going to follow semver? I saw that your version number has only two digits....

@alex-fedorov
Copy link
Collaborator

Yes I do want it. But I do not know if @egonSchiele is ok with that. Actually I have bumped to 0.10.1 making it a semver, but I do not have rubygems push rights. So we are waiting for @egonSchiele

@@ -88,6 +88,7 @@ contracts.ruby comes with a lot of built-in contracts, including the following:
* [`SetOf`](http://www.rubydoc.info/gems/contracts/Contracts/SetOf) – checks that the argument is a set, and all elements pass the given contract, e.g. `SetOf[Num]`
* [`HashOf`](http://www.rubydoc.info/gems/contracts/Contracts/HashOf) – checks that the argument is a hash, and all keys and values pass the given contract, e.g. `HashOf[Symbol => String]` or `HashOf[Symbol,String]`
* [`RangeOf`](http://www.rubydoc.info/gems/contracts/Contracts/RangeOf) – checks that the argument is a range whose elements (#first and #last) pass the given contract, e.g. `RangeOf[Date]`
* [`RangeOf`](http://www.rubydoc.info/gems/contracts/Contracts/Enum) – checks that the argument is part of a given collection of objects, e.g. `Enum[:a, :b; :c]`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo in links title: RangeOf => Enum

Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo in example: ; => ,

@egonSchiele
Copy link
Owner

Nice contract! Just waiting on responses to @alex-fedorov 's comments before I merge. I agree we should switch to semver.

@ghost
Copy link
Author

ghost commented Jul 16, 2015

Fixed. Sorry for the mistakes.

@waterlink
Copy link
Collaborator

@dg-ratiodata no problem :)

LGTM, merging

waterlink added a commit that referenced this pull request Jul 16, 2015
@waterlink waterlink merged commit 8a41dae into egonSchiele:master Jul 16, 2015
@waterlink
Copy link
Collaborator

Thanks @dg-ratiodata!

Do you need this to be released right away or this can wait?

@ghost
Copy link
Author

ghost commented Jul 17, 2015

This one can wait. I've got a custom contract for that. The same is true for the PR I filed some minutes ago.

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.

3 participants