diff options
author | Charles Oliver Nutter <headius@headius.com> | 2010-08-03 12:21:11 -0500 |
---|---|---|
committer | Charles Oliver Nutter <headius@headius.com> | 2010-08-03 12:21:11 -0500 |
commit | 2288d74466463d34a5054ef413e099c850cd832b (patch) | |
tree | 76db71c439f26b5c3b7e60fb15178a2bce92c2fb /src/json/ext/GeneratorService.java | |
parent | 6ebee56297dfd9c380f8f8fb6c0b8bb5254901b7 (diff) | |
download | json-2288d74466463d34a5054ef413e099c850cd832b.tar.gz |
Merge JRuby-compatible extension into json proper.
Diffstat (limited to 'src/json/ext/GeneratorService.java')
-rw-r--r-- | src/json/ext/GeneratorService.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/json/ext/GeneratorService.java b/src/json/ext/GeneratorService.java new file mode 100644 index 0000000..b8deb22 --- /dev/null +++ b/src/json/ext/GeneratorService.java @@ -0,0 +1,42 @@ +/* + * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. + * + * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files + * for details. + */ +package json.ext; + +import java.io.IOException; + +import org.jruby.Ruby; +import org.jruby.RubyClass; +import org.jruby.RubyModule; +import org.jruby.runtime.load.BasicLibraryService; + +/** + * The service invoked by JRuby's {@link org.jruby.runtime.load.LoadService LoadService}. + * Defines the <code>JSON::Ext::Generator</code> module. + * @author mernen + */ +public class GeneratorService implements BasicLibraryService { + public boolean basicLoad(Ruby runtime) throws IOException { + runtime.getLoadService().require("json/common"); + RuntimeInfo info = RuntimeInfo.initRuntime(runtime); + + info.jsonModule = runtime.defineModule("JSON"); + RubyModule jsonExtModule = info.jsonModule.defineModuleUnder("Ext"); + RubyModule generatorModule = jsonExtModule.defineModuleUnder("Generator"); + + RubyClass stateClass = + generatorModule.defineClassUnder("State", runtime.getObject(), + GeneratorState.ALLOCATOR); + stateClass.defineAnnotatedMethods(GeneratorState.class); + info.generatorStateClass = stateClass; + + RubyModule generatorMethods = + generatorModule.defineModuleUnder("GeneratorMethods"); + GeneratorMethods.populate(info, generatorMethods); + + return true; + } +} |