module Sequel::Plugins::ForceEncoding::InstanceMethods

Public Instance Methods

merge_db_update(row) click to toggle source

Allow the force encoding plugin to work with the identity_map plugin by typecasting new values.

Calls superclass method
# File lib/sequel/plugins/force_encoding.rb, line 41
def merge_db_update(row)
  super(force_hash_encoding(row))
end
set_values(row) click to toggle source

Force the encoding of all string values when setting the instance's values.

Calls superclass method
# File lib/sequel/plugins/force_encoding.rb, line 46
def set_values(row)
  super(force_hash_encoding(row))
end

Private Instance Methods

force_hash_encoding(row) click to toggle source

Force the encoding for all string values in the given row hash.

# File lib/sequel/plugins/force_encoding.rb, line 53
def force_hash_encoding(row)
  fe = model.forced_encoding
  row.values.each{|v| v.force_encoding(fe) if v.is_a?(String)} if fe
  row
end
typecast_value(column, value) click to toggle source

Force the encoding of all returned strings to the model's forced_encoding.

Calls superclass method
# File lib/sequel/plugins/force_encoding.rb, line 60
def typecast_value(column, value)
  s = super
  if s.is_a?(String) && (fe = model.forced_encoding)
    s = s.dup if s.frozen?
    s.force_encoding(fe)
  end
  s
end