Base class for all Rows.

Methods
Public Class methods
column_order()

Getter for the order of columns. The order is built from columns.keys.

# File lib/momomoto/row.rb, line 22
    def self.column_order
      @column_order
    end
columns()

Getter for the columns of this Row‘s table.

# File lib/momomoto/row.rb, line 16
    def self.columns
      @columns
    end
new( data = [] )

Creates a new Row instance.

# File lib/momomoto/row.rb, line 71
    def initialize( data = [] )
      @data = data
      @new_record = false
      clean_dirty
    end
table()

Getter for the table this Row is using.

# File lib/momomoto/row.rb, line 11
    def self.table
      @table
    end
Public Instance methods
==( other )

Compares +@data+ value of the row with other.

# File lib/momomoto/row.rb, line 45
    def ==( other )
      @data == other.instance_variable_get( :@data )
    end
[]( fieldname )

Gets the value of a given fieldname.

  feed = Feeds.select( {:url => 'https://www.c3d2.de/news-atom.xml' )[0]
  feed[:url] == 'https://www.c3d2.de/news-atom.xml'
    => true
# File lib/momomoto/row.rb, line 32
    def []( fieldname )
      get_column( fieldname )
    end
[]=( fieldname, value )

Sets fieldname to value.

  feed = Feeds.select( {:url => 'http://www.c3d2.de/news-atom.xml' )[0]
  feed[:url_host] = 'https://www.c3d2.de/'
# File lib/momomoto/row.rb, line 40
    def []=( fieldname, value )
      set_column( fieldname, value )
    end
clean_dirty()

Removes all fields from dirty.

# File lib/momomoto/row.rb, line 66
    def clean_dirty
      @dirty = []
    end
delete()

delete the row

# File lib/momomoto/row.rb, line 94
    def delete
      self.class.table.delete( self )
    end
dirty()

Getter for +@dirty+ which holds all changed fields of a row.

# File lib/momomoto/row.rb, line 50
    def dirty
      @dirty
    end
dirty?()

Returns true if there are fields in +@dirty+.

# File lib/momomoto/row.rb, line 55
    def dirty?
      @dirty.length > 0
    end
get_column( column )

generic getter for column values

# File lib/momomoto/row.rb, line 136
    def get_column( column )
      raise "Unknown column #{column}" if not self.class.column_order.member?( column.to_sym )
      table = self.class.table
      index = self.class.column_order.index( column.to_sym )
      if table.columns[column.to_sym].respond_to?( :filter_get )
        table.columns[column.to_sym].filter_get( @data[index] )
      else
        @data[index]
      end
    end
mark_dirty( field )

Marks a field as dirty.

# File lib/momomoto/row.rb, line 60
    def mark_dirty( field )
      field = field.to_sym
      @dirty.push( field ) if not @dirty.member?( field )
    end
new_record=( value )

Sets +@new_record+ to true or false.

# File lib/momomoto/row.rb, line 84
    def new_record=( value )
      @new_record = !!value
    end
new_record?()

Returns true if the row is newly created.

# File lib/momomoto/row.rb, line 78
    def new_record?
      @new_record
    end
set_column( column, value )

Generic setter for column values. You should use this method when you are defining your own setter. This is useful for preprocessing value before it is written to database:

  class Person < Momomoto::Table
    module Methods
      def nickname=( value )
        set_column( :nickname, value.downcase )
      end
    end
  end

This defines a custom setter nickname= which invokes downcase on the given value.

# File lib/momomoto/row.rb, line 121
    def set_column( column, value )
      raise "Unknown column #{column}" if not self.class.column_order.member?( column.to_sym )
      table = self.class.table
      if not new_record? and table.primary_keys.member?( column.to_sym )
        raise Error, "Setting primary keys(#{column}) is only allowed for new records"
      end
      value = table.columns[column.to_sym].filter_set( value )
      index = self.class.column_order.index( column.to_sym )
      if !table.columns[column.to_sym].equal( value, @data[index] )
        mark_dirty( column )
        @data[index] = value
      end
    end
to_hash()

converts row to hash

# File lib/momomoto/row.rb, line 99
    def to_hash
      hash = {}
      self.class.columns.keys.each do | key |
        hash[key] = self[key]
      end
      hash
    end
write()

write the row to the database

# File lib/momomoto/row.rb, line 89
    def write
      self.class.table.write( self )
    end