Class | YAML::Syck::Emitter
In: | syck/rubyext.c
Parent: | Object

### Methods

emit new node_export reset set_resolver

### Public Class methods

new(...)

YAML::Syck::Emitter.reset( options )

[Source]

    /*
     * YAML::Syck::Emitter.reset( options )
     */
    VALUE
    syck_emitter_reset( argc, argv, self )
        int argc;
        VALUE *argv;
        VALUE self;
    {
        VALUE options, tmp;
        SyckEmitter *emitter;
        struct emitter_xtra *bonus;
        volatile VALUE hash;    /* protect from GC */

        Data_Get_Struct(self, SyckEmitter, emitter);
        bonus = (struct emitter_xtra *)emitter->bonus;
        if ( bonus != NULL ) S_FREE( bonus );

        bonus = S_ALLOC_N( struct emitter_xtra, 1 );
        bonus->port = rb_str_new2( "" );
        bonus->data = hash = rb_hash_new();

        if (rb_scan_args(argc, argv, "01", &options) == 0)
        {
            options = rb_hash_new();
            rb_ivar_set(self, s_options, options);
        }
        else if ( !NIL_P(tmp = rb_check_string_type(options)) )
        {
            bonus->port = tmp;
        }
        else if ( rb_respond_to( options, s_write ) )
        {
            bonus->port = options;
        }
        else
        {
            Check_Type(options, T_HASH);
            rb_ivar_set(self, s_options, options);
        }

        emitter->headless = 1;
        emitter->bonus = (void *)bonus;
        rb_ivar_set(self, s_level, INT2FIX(0));
        rb_ivar_set(self, s_resolver, Qnil);
        return self;
    }

### Public Instance methods

emit(...)

YAML::Syck::Emitter.emit( object_id ) { |out| … }

[Source]

    /*
     * YAML::Syck::Emitter.emit( object_id ) { |out| ... }
     */
    VALUE
    syck_emitter_emit( argc, argv, self )
        int argc;
        VALUE *argv;
        VALUE self;
    {
        VALUE oid, proc;
        char *anchor_name;
        SyckEmitter *emitter;
        struct emitter_xtra *bonus;
        SYMID symple;
        int level = FIX2INT(rb_ivar_get(self, s_level)) + 1;
        rb_ivar_set(self, s_level, INT2FIX(level));

        rb_scan_args(argc, argv, "1&", &oid, &proc);
        Data_Get_Struct(self, SyckEmitter, emitter);
        bonus = (struct emitter_xtra *)emitter->bonus;

        /* Calculate anchors, normalize nodes, build a simpler symbol table */
        bonus->oid = oid;
        if ( !NIL_P( oid ) && RTEST( rb_funcall( bonus->data, s_haskey, 1, oid ) ) ) {
            symple = rb_hash_aref( bonus->data, oid );
        } else {
            symple = rb_funcall( proc, s_call, 1, rb_ivar_get( self, s_out ) );
        }
        syck_emitter_mark_node( emitter, (st_data_t)symple );

        /* Second pass, build emitted string */
        level -= 1;
        rb_ivar_set(self, s_level, INT2FIX(level));
        if ( level == 0 )
        {
            syck_emit(emitter, (st_data_t)symple);
            syck_emitter_flush(emitter, 0);

            return bonus->port;
        }

        return symple;
    }

node_export(p1)

YAML::Syck::Emitter#node_export

[Source]

    /*
     * YAML::Syck::Emitter#node_export
     */
    VALUE
    syck_emitter_node_export( self, node )
        VALUE self, node;
    {
        return rb_funcall( node, s_to_yaml, 1, self );
    }

reset(...)

YAML::Syck::Emitter.reset( options )

[Source]

    /*
     * YAML::Syck::Emitter.reset( options )
     */
    VALUE
    syck_emitter_reset( argc, argv, self )
        int argc;
        VALUE *argv;
        VALUE self;
    {
        VALUE options, tmp;
        SyckEmitter *emitter;
        struct emitter_xtra *bonus;
        volatile VALUE hash;    /* protect from GC */

        Data_Get_Struct(self, SyckEmitter, emitter);
        bonus = (struct emitter_xtra *)emitter->bonus;
        if ( bonus != NULL ) S_FREE( bonus );

        bonus = S_ALLOC_N( struct emitter_xtra, 1 );
        bonus->port = rb_str_new2( "" );
        bonus->data = hash = rb_hash_new();

        if (rb_scan_args(argc, argv, "01", &options) == 0)
        {
            options = rb_hash_new();
            rb_ivar_set(self, s_options, options);
        }
        else if ( !NIL_P(tmp = rb_check_string_type(options)) )
        {
            bonus->port = tmp;
        }
        else if ( rb_respond_to( options, s_write ) )
        {
            bonus->port = options;
        }
        else
        {
            Check_Type(options, T_HASH);
            rb_ivar_set(self, s_options, options);
        }

        emitter->headless = 1;
        emitter->bonus = (void *)bonus;
        rb_ivar_set(self, s_level, INT2FIX(0));
        rb_ivar_set(self, s_resolver, Qnil);
        return self;
    }

set_resolver(p1)

YAML::Syck::Emitter#set_resolver

[Source]

    /*
     * YAML::Syck::Emitter#set_resolver
     */
    VALUE
    syck_emitter_set_resolver( self, resolver )
        VALUE self, resolver;
    {
        rb_ivar_set( self, s_resolver, resolver );
        return self;
    }

[Validate]