Skip to content
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

Add an API method to require a library #253

Closed
mojavelinux opened this issue Dec 25, 2014 · 10 comments
Closed

Add an API method to require a library #253

mojavelinux opened this issue Dec 25, 2014 · 10 comments
Assignees
Milestone

Comments

@mojavelinux
Copy link
Member

Add a simple API method, preferably to the Asciidoctor interface, for requiring a library in the underlying runtime. For example:

Asciidoctor asciidoctor = ...;
asciidoctor.requireLibrary('asciidoctor-diagram');

The method require the library in whatever way is appropriate for the environment in use using the runtime associated with the Asciidoctor instance. This ensures the operation is declarative and not coupled to the underlying runtime.

@johncarl81
Copy link
Member

Should we include two require methods? One for Ruby and anther for Java?:

asciidoctor.requireRubyLibrary("asiidoctor-diagram");
asciidoctor.requireJavaLibrary(...);

@mojavelinux
Copy link
Member Author

I don't think we need one for requiring a Java library since that's handled very differently in the JVM. Ruby libraries are always loaded dynamically, as are JavaScript libraries. Thus, I think we can let the underlying implementation figure out how to handle the request.

@johncarl81
Copy link
Member

Ok, added the following to the api:

asciidoctor.requireLibrary("asciidoctor-diagram");
asciidoctor.requireLibrary("one", "two", "three");
asciidoctor.requireLibraries(libraryCollection);

Thoughts?

@abelsromero
Copy link
Member

I have a doubt about the use of the Ruby context. I've seen that internally it is stored in a static variable inside JRubyRuntimeContext class.
This means that if 2 or more instances of Asciidoctor are created, they share the same Ruby context instance, is that right?

@mojavelinux
Copy link
Member Author

Nope, it's the other way around. The JRubyRuntimeContext stores a link to the runtime being used by the Asciidoctor instance in the current thread. If anything, that pointer would be wrong. But the Ruby instance inside the Asciidoctor instance is isolated.

@mojavelinux
Copy link
Member Author

That's not to suggest that the way we handle the Ruby instance is absolutely correct. Just that if there is an issue, it's a broader discussion than this change here.

I actually think the way we lookup the Ruby runtime should require passing the Asciidoctor instance in rather than storing it as a single thread local. In other words, there is a two way mapping between the Ruby instance and the Asciidoctor instance so you always end up with the right one. But again, that's a separate discussion from this change because here we are working with the bound instance.

@abelsromero
Copy link
Member

I see, the new methods work on the context associated in the instance and do not use any of the static methods.
Thanks for the explanation and excuse the inconvenience 👍

@mojavelinux mojavelinux added this to the v1.5.3 milestone Dec 26, 2014
@lordofthejars
Copy link
Member

I don't close this issue until we have a green bar on CI in Windows environment.

@mojavelinux mojavelinux modified the milestones: v1.5.2.1, v1.5.3 Dec 27, 2014
@mojavelinux
Copy link
Member Author

Green bar!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants