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

Add a Contracts::Attrs module containing attribute w/ contracts utilities. #255

Merged
merged 3 commits into from
Apr 20, 2017

Conversation

frewsxcv
Copy link
Contributor

This pull request adds a new module Contracts::Attrs containing three methods to assist in using contracts with object attributes:

  • attr_reader_with_contract <symbol>..., <contract>
    • Wraps attr_reader, validates contract upon 'getting'
  • attr_writer_with_contract <symbol>..., <contract>
    • Wraps attr_writer, validates contract upon 'setting'
  • attr_accessor_with_contract <symbol>..., <contract>
    • Wraps attr_accessor, validates contract upon 'getting' or 'setting'

@frewsxcv
Copy link
Contributor Author

On a side note: thanks for making and maintaining contracts.ruby, it's an awesome project! 👌

@frewsxcv frewsxcv force-pushed the attrs branch 2 times, most recently from a85c12d to 14b0abc Compare April 17, 2017 14:47
@frewsxcv
Copy link
Contributor Author

@egonSchiele Any thoughts about dropping support for Ruby 1.8? It's been EOL and hasn't received security updates for a few years, so to me it feels like a safe decision. If you're onboard with that, I can open a new PR for that and then rebase this on top of that.

@egonSchiele
Copy link
Owner

I like this 👍
I agree that we can drop support for Ruby 1.8.

frewsxcv added a commit to frewsxcv/contracts.ruby that referenced this pull request Apr 18, 2017
As per the conversation in:

egonSchiele#255
@frewsxcv
Copy link
Contributor Author

PR opened: #256

egonSchiele pushed a commit that referenced this pull request Apr 20, 2017
* Drop support for Ruby 1.8.

As per the conversation in:

#255

* Address rubocop violation.

* Mention 1.8 support drop in changelog.
@egonSchiele
Copy link
Owner

can you merge master into this branch? ci should pass, and then I'll merge

@frewsxcv
Copy link
Contributor Author

Rebased.

@frewsxcv
Copy link
Contributor Author

Is that error related to my change here? 8e6d4ee#diff-eacde0c7f8149b55a880ae5fdcd84b3aL7

@egonSchiele
Copy link
Owner

Looks like the issue is, methods created using attr_* don't have a source_location, which makes sense since they are generated dynamically. This diff fixes ci:

diff --git a/lib/contracts/support.rb b/lib/contracts/support.rb
index 780455c..f3efa20 100644
--- a/lib/contracts/support.rb
+++ b/lib/contracts/support.rb
@@ -5,7 +5,11 @@ module Contracts
         return method.method_position if method.is_a?(MethodReference)

         file, line = method.source_location
-        file + ":" + line.to_s
+        if file.nil? || line.nil?
+          ""
+        else
+          file + ":" + line.to_s
+        end
       end

       def method_name(method)

I can merge this branch and fix.

@egonSchiele egonSchiele merged commit 56c2075 into egonSchiele:master Apr 20, 2017
@egonSchiele
Copy link
Owner

thank you!

@frewsxcv frewsxcv deleted the attrs branch April 20, 2017 22:48
@frewsxcv
Copy link
Contributor Author

More inportantly, thanks for maintaining this great library :)

end
end

include Attrs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this is included in place?
Allow people to just include ::Contract & use all methods?

Copy link
Owner

Choose a reason for hiding this comment

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

good point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't remember why i added that line; feel free to remove it

jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Jun 4, 2017
## v0.16.0

- **Support for Ruby 1.8 has been discontinued** - [Corey Farwell](https://github.com/frewsxcv) [#256](egonSchiele/contracts.ruby#256)
- Enhancement: Add a `Contracts::Attrs` module containing attribute w/ contracts utilities - [Corey Farwell](https://github.com/frewsxcv) [#255](egonSchiele/contracts.ruby#255)
- Bugfix: Fix StrictHash contract for extra keys - [Maciej Malecki](https://github.com/smt116) [#254](egonSchiele/contracts.ruby#254)

## v0.15.0
- Bugfix: Func contract's return value isn't enforced with blocks - [Piotr Szmielew](https://github.com/esse) [#251](egonSchiele/contracts.ruby#251)
- Bugfx: Fix contracts used in AR-models - [Gert Goet](https://github.com/eval) [#237](egonSchiele/contracts.ruby#237)
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.

4 participants