jruby/src/jruby/java/java_package_module_template.rb does not include
an implementation of const_get().
AFAIK the solution is to add
def const_get(const)
JavaUtilities.get_proxy_class(@package_name + const.to_s)
end
to JavaPackageModuleTemplate
The challenge is this file is in the jruby.jar so it makes it tough to
monkey patch...
Any ideas ?
use case:
Leveraging extends and include`s, I've added ActiveModel support to
java pojos. This works well and I can now use pojos as full fledged
models in rails apps. This is quite useful for integration.
see
http://yehudakatz.com/2010/01/10/activemodel-make-...
However, some gems (ActiveSupport) pass the class
intoActiveSupport::Dependencies.constantize(resource_class_name). This
in turn callsactive_support/inflector/methods.constantize() for each
module which finally calls constant.const_get().
I've added a few trace statements and have seen the following
resource_class_name=::Java::ComMyCoPocModel::CardApplicant
constantize Object Java
constantize Java ComMyCoPocModel
constantize Java::ComMyCoPocModel CardApplicant
ArgumentError: Java package com.myco.poc.model' does not have a
methodconst_get'
Looking at the code JavaPackageModuleTemplate, would an implementation
of const_get() be similar toconst_missing() ie call to
JavaUtilities.get_proxy_class
-Brian Walsh
const_get() missing from jruby/src/jruby/java/java_package_module_template.rb does not include an im
on 2012-12-11 07:26
Re: const_get() missing from jruby/src/jruby/java/java_package_module_template.rb does not include a
on 2012-12-12 16:51
I think we can consider adding: method_alias :const_get, :const_missing The const_missing already throws a NameError and is what you are monkey patching in. Is it weird that this will try and force a load of a new package or java Class? Not so much in the case that these packages cannot know what constants they actually might have. The only downside I can see to this is now people cannot have a class or package called const_get, but this seems exceedingly unlikely to me. Can you think of any other downsides to us just adding this to JRuby itself? I sort of feel the contract for constants should be const_missing/const_get/const_set, but const_set does not seem to have meaning for this scenario. -Tom On Tue, Dec 11, 2012 at 12:25 AM, Brian Walsh <brian@bwalsh.com> wrote: > to JavaPackageModuleTemplate > > > JavaUtilities.get_proxy_class > > > -Brian Walsh > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > -- blog: http://blog.enebo.com twitter: tom_enebo mail: tom.enebo@gmail.com
Re: const_get() missing from jruby/src/jruby/java/java_package_module_template.rb does not include a
on 2012-12-14 05:14
Thomas, Thank you. I agree about the contract for constants. I think loading the java class would be an expected behavior. I can try the alias you suggest asap and let you know. -Brian Walsh
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.