egonSchiele / contracts.ruby

Contracts for Ruby.
http://egonschiele.github.com/contracts.ruby
BSD 2-Clause "Simplified" License
1.44k stars 82 forks source link

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

Closed frewsxcv closed 7 years ago

frewsxcv commented 7 years ago

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

frewsxcv commented 7 years ago

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

frewsxcv commented 7 years ago

@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 commented 7 years ago

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

frewsxcv commented 7 years ago

PR opened: https://github.com/egonSchiele/contracts.ruby/pull/256

egonSchiele commented 7 years ago

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

frewsxcv commented 7 years ago

Rebased.

frewsxcv commented 7 years ago

Is that error related to my change here? https://github.com/egonSchiele/contracts.ruby/commit/8e6d4eec01bc64bff50192a63ac236ee34449401#diff-eacde0c7f8149b55a880ae5fdcd84b3aL7

egonSchiele commented 7 years ago

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 commented 7 years ago

thank you!

frewsxcv commented 7 years ago

More inportantly, thanks for maintaining this great library :)