Pistos (owner)

Revisions

gist: 143406 Download_button fork
public
Public Clone URL: git://gist.github.com/143406.git
Embed All Files: show embed
dbi-row.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
        # DBI::Row.new(columns, column_types, size_or_array=nil)
        #
        # Returns a new DBI::Row object using +columns+. The +size_or_array+
        # argument may either be an Integer or an Array. If it is not provided,
        # it defaults to the length of +columns+.
        #
        # Column types is a corresponding Array of Class/Module objects that
        # conform to the DBI::Type interface. These will be used to convert types
        # as they are returned.
        #
        # DBI::Row is a delegate of the Array class, so all of the Array
        # instance methods are available to your DBI::Row object (keeping in
        # mind that initialize, [], and []= have been explicitly overridden).
        #
        def initialize(columns, column_types, size_or_array=nil, convert_types=true)
 
m4dbi-model.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    def self.create( hash = {} )
      if block_given?
        row = DBI::Row.new(
          columns.collect { |c| c[ 'name' ] },
          [ M4DBI_UNASSIGNED ] * columns.size
        )
        yield row
        hash = row.to_h
        puts "hash: #{hash.inspect}"
        hash.to_a.each do |key,value|
          if value == M4DBI_UNASSIGNED
            hash.delete( key )
          end
        end
      end