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

Projects
None yet
4 participants
@frewsxcv
Contributor

frewsxcv commented Apr 17, 2017

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

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Apr 17, 2017

Contributor

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

Contributor

frewsxcv commented Apr 17, 2017

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

@frewsxcv

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Apr 17, 2017

Contributor

@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.

Contributor

frewsxcv commented Apr 17, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@egonSchiele

egonSchiele Apr 18, 2017

Owner

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

Owner

egonSchiele commented Apr 18, 2017

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

Drop support for Ruby 1.8.
As per the conversation in:

egonSchiele#255
@frewsxcv

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Apr 18, 2017

Contributor

PR opened: #256

Contributor

frewsxcv commented Apr 18, 2017

PR opened: #256

egonSchiele added a commit that referenced this pull request Apr 20, 2017

Drop support for Ruby 1.8. (#256)
* Drop support for Ruby 1.8.

As per the conversation in:

#255

* Address rubocop violation.

* Mention 1.8 support drop in changelog.
@egonSchiele

This comment has been minimized.

Show comment
Hide comment
@egonSchiele

egonSchiele Apr 20, 2017

Owner

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

Owner

egonSchiele commented Apr 20, 2017

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

@frewsxcv

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Apr 20, 2017

Contributor

Rebased.

Contributor

frewsxcv commented Apr 20, 2017

Rebased.

@frewsxcv

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Apr 20, 2017

Contributor

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

Contributor

frewsxcv commented Apr 20, 2017

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

@egonSchiele

This comment has been minimized.

Show comment
Hide comment
@egonSchiele

egonSchiele Apr 20, 2017

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.

Owner

egonSchiele commented Apr 20, 2017

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

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
@egonSchiele

This comment has been minimized.

Show comment
Hide comment
@egonSchiele

egonSchiele Apr 20, 2017

Owner

thank you!

Owner

egonSchiele commented Apr 20, 2017

thank you!

@frewsxcv frewsxcv deleted the frewsxcv:attrs branch Apr 20, 2017

@frewsxcv

This comment has been minimized.

Show comment
Hide comment
@frewsxcv

frewsxcv Apr 20, 2017

Contributor

More inportantly, thanks for maintaining this great library :)

Contributor

frewsxcv commented Apr 20, 2017

More inportantly, thanks for maintaining this great library :)

end
end
include Attrs

This comment has been minimized.

@PikachuEXE

PikachuEXE Apr 26, 2017

Contributor

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

@PikachuEXE

PikachuEXE Apr 26, 2017

Contributor

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

This comment has been minimized.

@egonSchiele

egonSchiele Apr 28, 2017

Owner

good point

@egonSchiele

egonSchiele Apr 28, 2017

Owner

good point

This comment has been minimized.

@frewsxcv

frewsxcv Apr 28, 2017

Contributor

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

@frewsxcv

frewsxcv Apr 28, 2017

Contributor

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

taca
Update ruby-contracts to 0.16.0.
## 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