Class: Object::Syck::Emitter

Inherits:
Object
  • Object
show all
Defined in:
rubyext.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

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



1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
# File 'rubyext.c', line 1958

VALUE
syck_emitter_reset(int argc, VALUE *argv, VALUE self)
{
    VALUE options, tmp;
    SyckEmitter *emitter;
    struct emitter_xtra *bonus;

    Data_Get_Struct(self, SyckEmitter, emitter);
    bonus = (struct emitter_xtra *)emitter->bonus;

    bonus->oid = Qnil;
    bonus->port = rb_str_new2( "" );
    bonus->data = id_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 = 0;
    rb_ivar_set(self, s_level, INT2FIX(0));
    rb_ivar_set(self, s_resolver, Qnil);
    return self;
}

Instance Attribute Details

#levelObject

Instance Method Details

#emitObject

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



2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
# File 'rubyext.c', line 2000

VALUE
syck_emitter_emit(int argc, VALUE *argv, VALUE self)
{
    VALUE oid, proc;
    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_exportObject

YAML::Syck::Emitter#node_export



2040
2041
2042
2043
2044
# File 'rubyext.c', line 2040

VALUE
syck_emitter_node_export(VALUE self, VALUE node)
{
    return rb_funcall( node, s_to_yaml, 1, self );
}

#resetObject

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



1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
# File 'rubyext.c', line 1958

VALUE
syck_emitter_reset(int argc, VALUE *argv, VALUE self)
{
    VALUE options, tmp;
    SyckEmitter *emitter;
    struct emitter_xtra *bonus;

    Data_Get_Struct(self, SyckEmitter, emitter);
    bonus = (struct emitter_xtra *)emitter->bonus;

    bonus->oid = Qnil;
    bonus->port = rb_str_new2( "" );
    bonus->data = id_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 = 0;
    rb_ivar_set(self, s_level, INT2FIX(0));
    rb_ivar_set(self, s_resolver, Qnil);
    return self;
}

#set_resolverObject

YAML::Syck::Emitter#set_resolver



2049
2050
2051
2052
2053
2054
# File 'rubyext.c', line 2049

VALUE
syck_emitter_set_resolver(VALUE self, VALUE resolver)
{
    rb_ivar_set( self, s_resolver, resolver );
    return self;
}