Author: kkaempf Date: Tue May 27 14:27:33 2008 New Revision: 10237 URL: http://svn.opensuse.org/viewcvs/zypp?rev=10237&view=rev Log: Ruby: raise exception on unknown attribute Ruby: implement Solvable::attr?() to check attribute existance Modified: trunk/sat-solver/bindings/solvable.i Modified: trunk/sat-solver/bindings/solvable.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/solvable.i?rev=10237&r1=10236&r2=10237&view=diff ============================================================================== --- trunk/sat-solver/bindings/solvable.i (original) +++ trunk/sat-solver/bindings/solvable.i Tue May 27 14:27:33 2008 @@ -194,7 +194,6 @@ { return my_id2str( $self->pool, xsolvable_solvable($self)->arch ); } const char *evr() { return my_id2str( $self->pool, xsolvable_solvable($self)->evr ); } - const char *vendor() { return my_id2str( $self->pool, xsolvable_solvable($self)->vendor ); } #if defined(SWIGRUBY) @@ -293,6 +292,7 @@ /* * Attributes (from Repodata / Repokey) */ + #if defined(SWIGRUBY) /* @@ -317,16 +317,20 @@ else name = StringValuePtr( attrname ); - if (name) { - Id key; - key = str2id( $self->pool, name, 0); - if (key != ID_NULL) { /* key existing in pool ? */ - VALUE result = Qnil; - Solvable *s = xsolvable_solvable($self); - if (repo_lookup( s, key, xsolvable_attr_lookup_callback, &result )) - return result; - } - } + if (!name) + rb_raise( rb_eArgError, "Solvable::[] called with empty arg" ); + + /* key existing in pool ? */ + Id key; + key = str2id( $self->pool, name, 0); + if (key == ID_NULL) + rb_raise( rb_eArgError, "No such attribute '%s'", name ); + + VALUE result = Qnil; + Solvable *s = xsolvable_solvable($self); + if (repo_lookup( s, key, xsolvable_attr_lookup_callback, &result )) + return result; + return Qnil; } @@ -341,6 +345,34 @@ } + /* + * check existance of attribute + */ + %rename( "attr?" ) attr_exists( VALUE attrname ); + VALUE attr_exists( VALUE attrname ) + { + char *name; + + if (SYMBOL_P(attrname)) { + char *colon; + name = rb_id2name( SYM2ID( attrname ) ); + colon = name; + while ((colon = strchr( colon, '_'))) { + *colon++ = ':'; + } + } + else + name = StringValuePtr( attrname ); + + if (!name) + return Qfalse; + + /* key existing in pool ? */ + Id key; + key = str2id( $self->pool, name, 0); + return (key == ID_NULL) ? Qfalse : Qtrue; + } + #endif /* SWIGRUBY */ } -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org