Class Informix::Slob::Stat
In: ext/informixc.c
Parent: Object

An instance of the Slob::Stat class is returned when an Slob is queried about its status information (Slob#stat).

Methods

<=>   atime   ctime   mtime   new   refcnt   size  

Included Modules

Comparable

Public Class methods

Creates an Slob::Stat object with status information for the given Slob object.

[Source]

/*
 * call-seq:
 * Slob::Stat.new(slob)  => stat
 *
 * Creates an Slob::Stat object with status information for the given Slob
 * object.
 */
static VALUE
rb_slobstat_initialize(VALUE self, VALUE slob)
{
        mint ret;
        slob_t *sb;
        slobstat_t *stat;
        ifx_lo_stat_t *st;
/*
 *      EXEC SQL begin declare section;
 */
#line 297 "informixc.ec"
#line 298 "informixc.ec"
  char *did;
/*
 *      EXEC SQL end   declare section;
 */
#line 299 "informixc.ec"


        Data_Get_Struct(slob, slob_t, sb);
        Data_Get_Struct(self, slobstat_t, stat);

        if (sb->fd == -1)
                rb_raise(rb_eProgrammingError,
                        "Open the Slob object before getting its status");

        did = sb->database_id;
/*
 *      EXEC SQL set connection :did;
 */
#line 309 "informixc.ec"
  {
#line 309 "informixc.ec"
  sqli_connect_set(0, did, 0);
#line 309 "informixc.ec"
  }
        if (SQLCODE < 0)
                raise_ifx_extended();

        ret = ifx_lo_stat(sb->fd, &st);

        if (ret < 0)
                raise_ifx_extended();

        stat->atime = ifx_lo_stat_atime(st);
        stat->ctime = ifx_lo_stat_ctime(st);
        stat->mtime = ifx_lo_stat_mtime_sec(st);
        stat->refcnt = ifx_lo_stat_refcnt(st);
        ret = ifx_lo_stat_size(st, &stat->size);

        ifx_lo_stat_free(st);

        if (stat->atime == -1 || stat->ctime == -1 || stat->mtime == -1 ||
            stat->refcnt == -1 || ret == -1) {
                rb_raise(rb_eOperationalError, "Unable to get status");
        }

        return self;
}

Public Instance methods

Compares with another Slob::Stat object by comparing their modification times.

[Source]

/*
 * call-seq:
 * stat <=> other_stat  => -1, 0, 1
 *
 * Compares with another <code>Slob::Stat</code> object by comparing their
 * modification times.
 */
static VALUE
rb_slobstat_cmp(VALUE self, VALUE other)
{
        if (rb_obj_is_kind_of(other, rb_obj_class(self))) {
                slobstat_t *stat;
                time_t t1, t2;

                Data_Get_Struct(self, slobstat_t, stat);  t1 = stat->mtime;
                Data_Get_Struct(other, slobstat_t, stat); t2 = stat->mtime;

                if (t1 == t2)
                        return INT2FIX(0);
                else if (t1 < t2)
                        return INT2FIX(-1);
                else
                        return INT2FIX(1);
        }

        return Qnil;
}

Returns the time of last access as a Time object.

[Source]

/*
 * call-seq:
 * stat.atime  => time
 *
 * Returns the time of last access as a Time object.
 */
static VALUE
rb_slobstat_atime(VALUE self)
{
        slobstat_t *stat;

        Data_Get_Struct(self, slobstat_t, stat);
        return rb_time_new(stat->atime, 0);
}

Returns the time of last change in status as a Time object.

[Source]

/*
 * call-seq:
 * stat.ctime  => time
 *
 * Returns the time of last change in status as a Time object.
 */
static VALUE
rb_slobstat_ctime(VALUE self)
{
        slobstat_t *stat;

        Data_Get_Struct(self, slobstat_t, stat);
        return rb_time_new(stat->ctime, 0);
}

Returns the time of last modification as a Time object.

[Source]

/*
 * call-seq:
 * stat.mtime  => time
 *
 * Returns the time of last modification as a Time object.
 */
static VALUE
rb_slobstat_mtime(VALUE self)
{
        slobstat_t *stat;

        Data_Get_Struct(self, slobstat_t, stat);
        return rb_time_new(stat->mtime, 0);
}

Returns the number of references

[Source]

/*
 * call-seq:
 * stat.refcnt  => fixnum
 *
 * Returns the number of references
 */
static VALUE
rb_slobstat_refcnt(VALUE self)
{
        slobstat_t *stat;

        Data_Get_Struct(self, slobstat_t, stat);
        return INT2FIX(stat->refcnt);
}

Returns the size in bytes

[Source]

/*
 * call-seq:
 * stat.size  => fixnum or bignum
 *
 * Returns the size in bytes
 */
static VALUE
rb_slobstat_size(VALUE self)
{
        slobstat_t *stat;
        VALUE size;

        Data_Get_Struct(self, slobstat_t, stat);
        INT82NUM(&stat->size, size);

        return size;
}

[Validate]