oneops icon indicating copy to clipboard operation
oneops copied to clipboard

`<top (required)>': Inductor is not a class (TypeError)

Open rameshjanjyam opened this issue 7 years ago • 0 comments

reason behind this error is that you cannot have same name for a module and a class.

Inductor is chosen as module name at - https://github.com/oneops/oneops/blob/master/oneops-admin/lib/version.rb Inductor is chosen as class name at - https://github.com/oneops/oneops/blob/master/oneops-admin/lib/inductor.rb

version.rb is only invoked in .gemspec to get the Inductor JAR. My understanding till now is that this .gemspec is only invoked during gem build and gem install but it seems it is not the case.

circuit or inductor commands on commmand line in oneops vagrant box works as expected when you invoke them from any directory other than the oneops-admin gem directory

on the vagrant box /usr/local/rvm/gems/ruby-2.3.3/gems/oneops-admin-1.0.0 this is where oneops-admin gem installed. if you invoke inductor command from this directory you can see that .gemspec is again invoked

cd /usr/local/rvm/gems/ruby-2.3.3/gems/oneops-admin-1.0.0
[vagrant@localhost oneops-admin-1.0.0]$ inductor
.gemspec invoked ##I have added this puts in .gemspec to see whether it is invoked or not
/usr/local/rvm/gems/ruby-2.3.3/gems/oneops-admin-1.0.0/lib/inductor.rb:6:in `<top (required)>': Inductor is not a class (TypeError)
	from /usr/local/rvm/gems/ruby-2.3.3/gems/oneops-admin-1.0.0/bin/inductor:3:in `require'
	from /usr/local/rvm/gems/ruby-2.3.3/gems/oneops-admin-1.0.0/bin/inductor:3:in `<top (required)>'
	from /usr/local/rvm/gems/ruby-2.3.3/bin/inductor:23:in `load'
	from /usr/local/rvm/gems/ruby-2.3.3/bin/inductor:23:in `<main>'
	from /usr/local/rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `eval'
	from /usr/local/rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in `<main>'

when .gemspec is invoked, you are loading version.rb which loads Inductor module. and when the Inductor class is also loaded by calling Inductor on command line ruby threw this error saying that we cannot choose same name for both module and class.

This shouldn't happen in 99% of cases because as an user, we don't normally invoke Inductor command on command line. I am not sure why .gemspec is loaded only when you invoke inductor command from oneops-admin gem directory but the issue is we cannot use same name for both module and class

rameshjanjyam avatar Aug 22 '17 15:08 rameshjanjyam