Sha256: 047e6104935df06967cdfc70c4afcce0d0311cc93ad7c2dd53b78c7fd31a5e1f

Contents?: true

Size: 605 Bytes

Versions: 4

Compression:

Stored size: 605 Bytes

Contents

module CassandraObject
  module Types
    class StringType < BaseType
      def encode(str)
        raise ArgumentError.new("#{str.inspect} is not a String") unless str.kind_of?(String)

        unless str.encoding == Encoding::UTF_8
          (str.frozen? ? str.dup : str).force_encoding('UTF-8')
        else
          str
        end
      end
      
      def decode(str)
        begin
          (str.frozen? ? str.dup : str).force_encoding('UTF-8') if str
        rescue Exception => e
          str.to_s
        end
      end

      def typecast(value)
        value.to_s
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
extendi-cassandra_object-1.0.7 lib/cassandra_object/types/string_type.rb
extendi-cassandra_object-1.0.6 lib/cassandra_object/types/string_type.rb
extendi-cassandra_object-1.0.5 lib/cassandra_object/types/string_type.rb
extendi-cassandra_object-1.0.4 lib/cassandra_object/types/string_type.rb