-
Notifications
You must be signed in to change notification settings - Fork 82
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
Cannot call Contract in AS#included block #176
Comments
Still no idea what causes this yet, too many commits to read :S |
I have the following AR model: require "contracts"
require "contracts/version"
class Agency < ActiveRecord::Base
p Contracts::VERSION
include Contracts
p respond_to?(:Contract)
p method(:Contract).source_location
p Contract None => Any
def whatever_1
end
include ConcernModule
module ConcernModule
extend ActiveSupport::Concern
included do
include Contracts
p respond_to?(:Contract)
p method(:Contract).source_location
p None => Any
def whatever_2
end
end
end
# rest
end For
For
|
Ugh, wonder how this happened. Thanks for reporting. |
Might be related to engine refactoring. If you look at the output of And YourClass # => YourClass
_.class # => Class
_.class # => Class:Class <------ this is exactly what `Contract` try to being called on.. |
|
Any update on this yet? |
Nope...I need to do a git bisect when I have some time... |
I will look into it today (2-2.5 hours) later. |
@PikachuEXE I don't have this problem on Which version of |
Just tried following versions too, and all of them worked:
|
And what about ruby version, BTW ? |
Sorry for not providing those ;P |
So if you say, that code is AS/AR independent, can it be rewritten like this?: class Something
module WithSettings
def self.included(base)
base.class_eval do
include Contracts
Contract None => ArrayOf[String]
def emails
#...
end
end
end
end
end ? |
So, I'm trying to run this guy: https://gist.github.com/waterlink/ca3080bfee096fa7d08a
And I don't get any strange error. Everything works just fine.. @PikachuEXE do you see anything I am not doing correctly to reproduce the bug? |
Let me create a test script that can reproduce the bug at work... |
OK test script gist created: https://gist.github.com/PikachuEXE/e7efb3a58ef3c9764722 |
Well, code definitely is |
Nailed it down to: https://gist.github.com/waterlink/0018249f6c3b86403d87 |
Got a more simple version than my previous gist: https://gist.github.com/PikachuEXE/1672d5c0434863bee6ae Not much different from https://gist.github.com/waterlink/0018249f6c3b86403d87
|
…'extend' to work
…'extend' to work
Env
MRI
2.2.2
or2.2.3
What happened
Post
) with a module (e.g.ClassMethods
) whereClassMethods
has includedContracts
Contract
method insidePost
after includingClassMethods
:0.9
0.10.1
or0.11.0
(see theError
section below)To reproduce the error please look at the test script gist
Too long to read? Shorter version: https://gist.github.com/PikachuEXE/1672d5c0434863bee6ae
Error
Message from application: undefined method `Contract' for Class:Class (NoMethodError)
Updates
Update 1: Even after I have removed
ActiveSupport::Concern
usage (and switch toModule#included
, it's still failing. So I updated the code to ensure it's not AS related.Update 2: Included Ruby versions
Update 3: Added test script gist
Update 4: Update the test script again (removed AS dependency)
The text was updated successfully, but these errors were encountered: