Пример #1
0
  public static void createTemplate(Ruby runtime, RubyModule mASN1) {
    mTemplate = runtime.defineModuleUnder("Template", mASN1);
    RubyModule mParser = runtime.defineModuleUnder("Parser", mTemplate);
    cTemplateValue =
        mTemplate.defineClassUnder(
            "Value", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);

    CODEC = runtime.newSymbol("codec");
    OPTIONS = runtime.newSymbol("options");
    DEFAULT = runtime.newSymbol("default");
    NAME = runtime.newSymbol("name");
    TYPE = runtime.newSymbol("type");
    OPTIONAL = runtime.newSymbol("optional");
    TAG = runtime.newSymbol("tag");
    TAGGING = runtime.newSymbol("tagging");
    LAYOUT = runtime.newSymbol("layout");
    MIN_SIZE = runtime.newSymbol("min_size");

    CODEC_PRIMITIVE = runtime.newSymbol("PRIMITIVE");
    CODEC_TEMPLATE = runtime.newSymbol("TEMPLATE");
    CODEC_SEQUENCE = runtime.newSymbol("SEQUENCE");
    CODEC_SET = runtime.newSymbol("SET");
    CODEC_SEQUENCE_OF = runtime.newSymbol("SEQUENCE_OF");
    CODEC_SET_OF = runtime.newSymbol("SET_OF");
    CODEC_ANY = runtime.newSymbol("ANY");
    CODEC_CHOICE = runtime.newSymbol("CHOICE");

    mTemplate.defineAnnotatedMethods(RubyAsn1Template.class);
    mParser.defineAnnotatedMethods(TemplateParser.class);
    cTemplateValue.defineAnnotatedMethods(RubyAsn1Template.class);
  }
Пример #2
0
  @Override
  public boolean basicLoad(final Ruby ruby) throws IOException {
    RubyModule jr_jackson = ruby.defineModule("JrJackson");

    RubyModule jr_jackson_raw = ruby.defineModuleUnder("Raw", jr_jackson);
    jr_jackson_raw.defineAnnotatedMethods(JrJacksonRaw.class);

    RubyClass runtimeError = ruby.getRuntimeError();
    RubyClass parseError =
        jr_jackson.defineClassUnder("ParseError", runtimeError, runtimeError.getAllocator());
    return true;
  }
Пример #3
0
  @Override
  public void load(Ruby ruby, boolean wrap) throws IOException {
    RubyModule pg = ruby.defineModule("PG");
    ruby.defineClassUnder(
        "Error", ruby.getStandardError(), ruby.getStandardError().getAllocator(), pg);
    RubyModule pgConstants = ruby.defineModuleUnder("Constants", pg);

    // create the connection status constants
    for (ConnectionState status : ConnectionState.values())
      pgConstants.defineConstant(status.name(), ruby.newFixnum(status.ordinal()));

    for (TransactionStatus status : TransactionStatus.values())
      pgConstants.defineConstant(status.name(), ruby.newFixnum(status.ordinal()));

    for (ResultStatus status : ResultStatus.values())
      pgConstants.defineConstant(status.name(), ruby.newFixnum(status.ordinal()));

    // create the large object constants
    pgConstants.defineConstant("INV_READ", new RubyFixnum(ruby, LargeObjectAPI.READ));
    pgConstants.defineConstant("INV_WRITE", new RubyFixnum(ruby, LargeObjectAPI.WRITE));
    pgConstants.defineConstant("SEEK_SET", new RubyFixnum(ruby, LargeObjectAPI.SEEK_SET));
    pgConstants.defineConstant("SEEK_END", new RubyFixnum(ruby, LargeObjectAPI.SEEK_END));
    pgConstants.defineConstant("SEEK_CUR", new RubyFixnum(ruby, LargeObjectAPI.SEEK_CUR));

    // create error fields objects
    for (ErrorField field : ErrorResponse.ErrorField.values())
      pgConstants.defineConstant(field.name(), ruby.newFixnum(field.getCode()));

    pg.getSingletonClass().defineAnnotatedMethods(Postgresql.class);

    try {
      for (java.lang.reflect.Field field : Oid.class.getDeclaredFields()) {
        String name = field.getName();
        int value = field.getInt(null);
        pgConstants.defineConstant("OID_" + name, ruby.newFixnum(value));
      }
    } catch (Exception e) {
      ruby.newRuntimeError(e.getLocalizedMessage());
    }

    pgConstants.defineConstant("INVALID_OID", ruby.newFixnum(Oid.UNSPECIFIED));
    pg.includeModule(pgConstants);
    Connection.define(ruby, pg, pgConstants);
    Result.define(ruby, pg, pgConstants);
  }
Пример #4
0
 public static void load(Ruby runtime) {
   RubyModule humboldtModule = runtime.defineModule("Humboldt");
   RubyModule typeConverterModule = runtime.defineModuleUnder("TypeConverter", humboldtModule);
   RubyClass binaryClass =
       runtime.defineClassUnder(
           "Binary", runtime.getObject(), BINARY_ALLOCATOR, typeConverterModule);
   binaryClass.defineAnnotatedMethods(BinaryConverter.class);
   runtime.defineClassUnder("Encoded", binaryClass, BINARY_ALLOCATOR, typeConverterModule);
   RubyClass textClass =
       runtime.defineClassUnder("Text", runtime.getObject(), TEXT_ALLOCATOR, typeConverterModule);
   textClass.defineAnnotatedMethods(TextConverter.class);
   runtime.defineClassUnder("Json", textClass, TEXT_ALLOCATOR, typeConverterModule);
   RubyClass longClass =
       runtime.defineClassUnder("Long", runtime.getObject(), LONG_ALLOCATOR, typeConverterModule);
   longClass.defineAnnotatedMethods(LongConverter.class);
   RubyClass noneClass =
       runtime.defineClassUnder("None", runtime.getObject(), NONE_ALLOCATOR, typeConverterModule);
   noneClass.defineAnnotatedMethods(NoneConverter.class);
 }
Пример #5
0
 public static void createHex(Ruby runtime, RubyModule krypt, RubyClass kryptError) {
   RubyModule mHex = runtime.defineModuleUnder("Hex", krypt);
   mHex.defineClassUnder("HexError", kryptError, kryptError.getAllocator());
   mHex.defineAnnotatedMethods(RubyHex.class);
 }