class Patriot::Util::DBClient::HashRecord
a record implementation based on Hash
Public Class Methods
new(record)
click to toggle source
@param record [Hash]
# File lib/patriot/util/db_client/hash_record.rb, line 10 def initialize(record) @record = {} # ignore fixnum which is not column name record.each{|k,v| @record[k.to_sym] = v unless k.is_a?(Fixnum)} end
Public Instance Methods
get_id()
click to toggle source
@see Patriot::Util::DBClient::Record#get_id
# File lib/patriot/util/db_client/hash_record.rb, line 17 def get_id return @record[:id] end
method_missing(mth, *args, &blk)
click to toggle source
used as accessors
Calls superclass method
# File lib/patriot/util/db_client/hash_record.rb, line 29 def method_missing(mth, *args, &blk) key = mth type = :get if key.to_s.end_with?("=") key = key.to_s.slice(0..-2).to_sym type = :set end if type == :get if @record.has_key?(mth) return @record[mth] else return nil end elsif type == :set @record[key] = args[0] return end super end
to_hash(keys = @record.keys)
click to toggle source
@see Patriot::Util::DBClient::Record#to_mash
# File lib/patriot/util/db_client/hash_record.rb, line 22 def to_hash(keys = @record.keys) hash = {} keys.each{|k| hash[k] = @record[k]} return hash end