Sha256: 6017c35ed21d295f8fe2cd315d8d35866fddf5c2b954575b4ad25de34d13f63d

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8

module NativeQuery

    ##
    # Represents one ORM row.
    #
     
    class Row
    
        ##
        # Brings data.
        #
        
        @data
        
        ##
        # Processed data cache.
        #
        
        @__data
        
        ##
        # Constructor.
        #
        
        def initialize(data)
            @data = data
        end
        
        ##
        # Maps unknown calls to data fields. 
        #
        
        def method_missing(sym, *args, &block)
            __data[sym]
        end
        
        ##
        # Indicates, rows exists.
        #
        
        def any?
           not __data.nil? 
        end
        
        ##
        # Returns data field.
        #
        
        private
        def __data
            if @__data.nil?
           
                # Calls for data and converts string keys of hash 
                # to symbols.
                
                data = @data
                @__data = { }
                
                if not data.nil?
                    @data = nil
                    data.each_pair do |k, v|
                        @__data[k.to_sym] = v
                    end
                else
                    @__data = nil
                end
                
            end

            return @__data
        end
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
native-query-0.9.5 lib/native-query/row.rb
native-query-0.9.4 lib/native-query/row.rb
native-query-0.9.3 lib/native-query/row.rb
native-query-0.9.2 lib/native-query/row.rb
native-query-0.9.1 lib/native-query/row.rb
native-query-0.9.0 lib/native-query/row.rb