blob: b8deb2283deea6d320a39e2aa2b58dee085fa2cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}
}
|