ext/iodine/iodine_connection.c
/** Tests the `subscribe` Ruby arguments */
Tests the `subscribe` Ruby arguments
Tests the ` subscribe ` Ruby arguments
static iodine_sub_args_s iodine_subscribe_args(int argc, VALUE *argv) {
  iodine_sub_args_s ret = {.channel = Qnil, .block = Qnil};
  VALUE rb_opt = 0;
  switch (argc) {
  case 2:
    ret.channel = argv[0];
    rb_opt = argv[1];
    break;
  case 1:
    if (TYPE(argv[0]) == T_HASH) {
      rb_opt = argv[0];
      ret.channel = rb_hash_aref(argv[0], to_id);
      if (ret.channel == Qnil || ret.channel == Qfalse) {
        ret.channel = rb_hash_aref(argv[0], channel_id);
        if (ret.channel != Qnil) {
          FIO_LOG_WARNING("use of :channel in subscribe is deprecated.");
        }
      }
    } else {
      ret.channel = argv[0];
    }
    break;
  default:
    rb_raise(rb_eArgError, "method accepts 1 or 2 arguments.");
    return ret;
  }
  if (ret.channel == Qnil || ret.channel == Qfalse) {
    rb_raise(rb_eArgError,
             "a target (:to) subject / stream / channel is required.");
    return ret;
  }
  if (TYPE(ret.channel) == T_SYMBOL)
    ret.channel = rb_sym2str(ret.channel);
  Check_Type(ret.channel, T_STRING);
  if (rb_opt) {
    if (rb_hash_aref(rb_opt, as_id) == binary_id) {
      ret.binary = 1;
    }
    if (rb_hash_aref(rb_opt, match_id) == redis_id) {
      ret.pattern = FIO_MATCH_GLOB;
    }
    ret.block = rb_hash_aref(rb_opt, handler_id);
    if (ret.block != Qnil) {
      IodineStore.add(ret.block);
    }
  }
  if (ret.block == Qnil) {
    if (rb_block_given_p()) {
      ret.block = rb_block_proc();
      IodineStore.add(ret.block);
    }
  }
  return ret;
}
static iodine_sub_args_s iodine_subscribe_args ( int argc , VALUE * argv ) { iodine_sub_args_s ret = { . channel = Qnil , . block = Qnil } ; VALUE rb_opt = 0 ; switch ( argc ) { case 2 : ret . channel = argv [ 0 ] ; rb_opt = argv [ 1 ] ; break ; case 1 : if ( TYPE ( argv [ 0 ] ) == T_HASH ) { rb_opt = argv [ 0 ] ; ret . channel = rb_hash_aref ( argv [ 0 ] , to_id ) ; if ( ret . channel == Qnil || ret . channel == Qfalse ) { ret . channel = rb_hash_aref ( argv [ 0 ] , channel_id ) ; if ( ret . channel != Qnil ) { FIO_LOG_WARNING ( " " ) ; } } } else { ret . channel = argv [ 0 ] ; } break ; default : rb_raise ( rb_eArgError , " " ) ; return ret ; } if ( ret . channel == Qnil || ret . channel == Qfalse ) { rb_raise ( rb_eArgError , " " ) ; return ret ; } if ( TYPE ( ret . channel ) == T_SYMBOL ) ret . channel = rb_sym2str ( ret . channel ) ; Check_Type ( ret . channel , T_STRING ) ; if ( rb_opt ) { if ( rb_hash_aref ( rb_opt , as_id ) == binary_id ) { ret . binary = 1 ; } if ( rb_hash_aref ( rb_opt , match_id ) == redis_id ) { ret . pattern = FIO_MATCH_GLOB ; } ret . block = rb_hash_aref ( rb_opt , handler_id ) ; if ( ret . block != Qnil ) { IodineStore . add ( ret . block ) ; } } if ( ret . block == Qnil ) { if ( rb_block_given_p ( ) ) { ret . block = rb_block_proc ( ) ; IodineStore . add ( ret . block ) ; } } return ret ; }
Tests the `subscribe` Ruby arguments
Tests the ` subscribe ` Ruby arguments
/* single argument must be a Hash / channel name */ /* temporary backport support */