Class: Lafcadio::SqlValueConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/lafcadio/objectStore/SqlValueConverter.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objectType, rowHash) ⇒ SqlValueConverter

Returns a new instance of SqlValueConverter.



5
6
7
8
# File 'lib/lafcadio/objectStore/SqlValueConverter.rb', line 5

def initialize(objectType, rowHash)
	@objectType = objectType
	@rowHash = rowHash
end

Instance Attribute Details

#objectTypeObject (readonly)

Returns the value of attribute objectType.



3
4
5
# File 'lib/lafcadio/objectStore/SqlValueConverter.rb', line 3

def objectType
  @objectType
end

#rowHashObject (readonly)

Returns the value of attribute rowHash.



3
4
5
# File 'lib/lafcadio/objectStore/SqlValueConverter.rb', line 3

def rowHash
  @rowHash
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lafcadio/objectStore/SqlValueConverter.rb', line 10

def []( key )
	if key == 'pkId'
		if ( field_val = @rowHash[@objectType.sqlPrimaryKeyName] ).nil?
			error_msg = "The field \"" + @objectType.sqlPrimaryKeyName +
			            "\" can\'t be found in the table \"" + 
			            @objectType.tableName + "\"."
			raise FieldMatchError, error_msg, caller
		else
			field_val.to_i
		end
	else
		begin
			field = @objectType.getField( key )
			field.valueFromSQL( @rowHash[ field.dbFieldName ] )
		rescue MissingError
			nil
		end
	end
end