Last active
August 29, 2015 14:03
-
-
Save mbj/a5f9f40d71e7ebffc8f8 to your computer and use it in GitHub Desktop.
Check for ruby {Class,Module}#name contract violations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectSpace.each_object(Module).each do |object| | |
method = object.method(:name) | |
name = | |
begin | |
object.name | |
rescue | |
puts "#{method} from object: #{object.inspect} raised exception" | |
next | |
end | |
case name | |
when String | |
result = name.split('::').reduce(Object) do |current, name| | |
begin | |
current.const_get(name) | |
rescue NameError | |
puts "#{method} from object: #{object.inspect} returned unresolvable name" | |
break | |
end | |
end | |
if result && !result.equal?(object) | |
puts "#{method} from object: #{object.inspect} returned a name #{name} that does not resolve back to object returned: #{result.inspect} instead" | |
end | |
when NilClass | |
else | |
puts "#{method} from object: #{object.inspect} did not returned String or nil, was #{name.inspect}" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#<Method: Class(Module)#name> from object: fatal returned unresolvable name | |
#<Method: Module#name> from object: IO::generic_readable returned unresolvable name | |
#<Method: Class(Module)#name> from object: Complex::compatible returned unresolvable name | |
#<Method: Class(Module)#name> from object: Rational::compatible returned unresolvable name | |
#<Method: Module#name> from object: Math returned a name Math that does not resolve back to object returned: CMath instead | |
#<Method: Class(Module)#name> from object: ARGF.class returned unresolvable name | |
#<Method: Class(Module)#name> from object: NameError::message returned unresolvable name | |
#<Method: Module#name> from object: IO::generic_writable returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::Stamps.name> from object: ActiveMerchant::Shipping::Stamps returned unresolvable name | |
#<Method: ActiveSupport::TimeWithZone.name> from object: ActiveSupport::TimeWithZone returned a name Time that does not resolve back to object returned: Time instead | |
#<Method: Sprockets::Processor.name> from object: Sprockets::Processor returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::NewZealandPost.name> from object: ActiveMerchant::Shipping::NewZealandPost returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::CanadaPost.name> from object: ActiveMerchant::Shipping::CanadaPost returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::Kunaki.name> from object: ActiveMerchant::Shipping::Kunaki returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::Shipwire.name> from object: ActiveMerchant::Shipping::Shipwire returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::FedEx.name> from object: ActiveMerchant::Shipping::FedEx returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::USPS.name> from object: ActiveMerchant::Shipping::USPS returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::UPS.name> from object: ActiveMerchant::Shipping::UPS returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::BogusCarrier.name> from object: ActiveMerchant::Shipping::BogusCarrier returned unresolvable name | |
#<Method: ActiveMerchant::Shipping::BenchmarkCarrier.name> from object: ActiveMerchant::Shipping::BenchmarkCarrier returned unresolvable name | |
#<Method: Class(ActiveRecord::Delegation::ClassSpecificRelation::ClassMethods)#name> from object: ActiveRecord::Relation::ActiveRecord_Relation_Spree_Preference returned a name ActiveRecord::Relation that does not resolve back to object returned: ActiveRecord::Relation instead | |
#<Method: Class(ActiveRecord::Delegation::ClassSpecificRelation::ClassMethods)#name> from object: ActiveRecord::Relation::ActiveRecord_Relation_Spree_Order returned a name ActiveRecord::Relation that does not resolve back to object returned: ActiveRecord::Relation instead | |
#<Method: #<class(Pry::Command "$")>(Pry::Command).name> from object: #<class(Pry::Command "$")> returned unresolvable name | |
#<Method: #<class(Pry::Command "show-method")>(Pry::Command).name> from object: #<class(Pry::Command "show-method")> returned unresolvable name | |
#<Method: #<class(Pry::Command "@")>(Pry::Command).name> from object: #<class(Pry::Command "@")> returned unresolvable name | |
#<Method: #<class(Pry::Command "quit-program")>(Pry::Command).name> from object: #<class(Pry::Command "quit-program")> returned unresolvable name | |
#<Method: #<class(Pry::Command "!!!")>(Pry::Command).name> from object: #<class(Pry::Command "!!!")> returned unresolvable name | |
#<Method: #<class(Pry::Command "reload-method")>(Pry::Command).name> from object: #<class(Pry::Command "reload-method")> returned unresolvable name | |
#<Method: #<class(Pry::Command "show-command")>(Pry::Command).name> from object: #<class(Pry::Command "show-command")> returned unresolvable name | |
#<Method: #<class(Pry::Command "edit-method")>(Pry::Command).name> from object: #<class(Pry::Command "edit-method")> returned unresolvable name | |
#<Method: #<class(Pry::Command "clipit")>(Pry::Command).name> from object: #<class(Pry::Command "clipit")> returned unresolvable name | |
#<Method: #<class(Pry::Command "history")>(Pry::Command).name> from object: #<class(Pry::Command "history")> returned unresolvable name | |
#<Method: Class(ActiveRecord::Delegation::ClassSpecificRelation::ClassMethods)#name> from object: ActiveRecord::Relation::ActiveRecord_Relation_Spree_User returned a name ActiveRecord::Relation that does not resolve back to object returned: ActiveRecord::Relation instead | |
#<Method: #<class(Pry::Command "test-ansi")>(Pry::Command).name> from object: #<class(Pry::Command "test-ansi")> returned unresolvable name | |
#<Method: #<class(Pry::Command "pessoa-poem")>(Pry::Command).name> from object: #<class(Pry::Command "pessoa-poem")> returned unresolvable name | |
#<Method: #<class(Pry::Command "cohen-poem")>(Pry::Command).name> from object: #<class(Pry::Command "cohen-poem")> returned unresolvable name | |
#<Method: #<class(Pry::Command "east-coker")>(Pry::Command).name> from object: #<class(Pry::Command "east-coker")> returned unresolvable name | |
#<Method: #<class(Pry::Command "get-naked")>(Pry::Command).name> from object: #<class(Pry::Command "get-naked")> returned unresolvable name | |
#<Method: #<class(Pry::Command /!s\/(.*?)\/(.*?)/)>(Pry::Command).name> from object: #<class(Pry::Command /!s\/(.*?)\/(.*?)/)> returned unresolvable name | |
#<Method: #<class(Pry::Command "nyan-cat")>(Pry::Command).name> from object: #<class(Pry::Command "nyan-cat")> returned unresolvable name | |
#<Method: Class(ActiveRecord::Delegation::ClassSpecificRelation::ClassMethods)#name> from object: ActiveRecord::Relation::ActiveRecord_Relation_Spree_Asset returned a name ActiveRecord::Relation that does not resolve back to object returned: ActiveRecord::Relation instead | |
#<Method: Class(ActiveRecord::Delegation::ClassSpecificRelation::ClassMethods)#name> from object: ActiveRecord::Relation::ActiveRecord_Relation_Spree_Role returned a name ActiveRecord::Relation that does not resolve back to object returned: ActiveRecord::Relation instead | |
#<Method: #<class(Pry::Command "?")>(Pry::Command).name> from object: #<class(Pry::Command "?")> returned unresolvable name | |
#<Method: Net::SSH::Transport::IdentityCipher.name> from object: Net::SSH::Transport::IdentityCipher returned unresolvable name | |
#<Method: #<class(Pry::Command "quit")>(Pry::Command).name> from object: #<class(Pry::Command "quit")> returned unresolvable name | |
#<Method: #<class(Pry::Command "file-mode")>(Pry::Command).name> from object: #<class(Pry::Command "file-mode")> returned unresolvable name | |
#<Method: #<class(Pry::Command "!!@")>(Pry::Command).name> from object: #<class(Pry::Command "!!@")> returned unresolvable name | |
#<Method: NewRelic::Agent::Instrumentation::ControllerInstrumentation::TransactionNamer.name> from object: NewRelic::Agent::Instrumentation::ControllerInstrumentation::TransactionNamer raised exception | |
#<Method: NewRelic::Agent::Samplers::CpuSampler(NewRelic::Agent::Sampler).name> from object: NewRelic::Agent::Samplers::CpuSampler did not returned String or nil, was :cpu | |
#<Method: NewRelic::Agent::Samplers::ObjectSampler(NewRelic::Agent::Sampler).name> from object: NewRelic::Agent::Samplers::ObjectSampler did not returned String or nil, was :object | |
#<Method: NewRelic::Agent::Samplers::MemorySampler(NewRelic::Agent::Sampler).name> from object: NewRelic::Agent::Samplers::MemorySampler did not returned String or nil, was :memory | |
#<Method: NewRelic::Agent::Samplers::DelayedJobSampler(NewRelic::Agent::Sampler).name> from object: NewRelic::Agent::Samplers::DelayedJobSampler did not returned String or nil, was :delayed_job | |
#<Method: NewRelic::Agent::Samplers::VMSampler(NewRelic::Agent::Sampler).name> from object: NewRelic::Agent::Samplers::VMSampler did not returned String or nil, was :vm | |
#<Method: #<class(Pry::Command "show-middleware")>(Pry::Command).name> from object: #<class(Pry::Command "show-middleware")> returned unresolvable name | |
#<Method: #<class(Pry::Command "recognize-path")>(Pry::Command).name> from object: #<class(Pry::Command "recognize-path")> returned unresolvable name | |
#<Method: #<class(Pry::Command "show-routes")>(Pry::Command).name> from object: #<class(Pry::Command "show-routes")> returned unresolvable name | |
#<Method: Class(ActiveRecord::Delegation::ClassSpecificRelation::ClassMethods)#name> from object: ActiveRecord::Relation::ActiveRecord_Relation_Spree_OptionValue returned a name ActiveRecord::Relation that does not resolve back to object returned: ActiveRecord::Relation instead |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment