Class: CassandraObject::Types::ArrayType

Inherits:
BaseType
  • Object
show all
Defined in:
lib/cassandra_object/types/array_type.rb

Defined Under Namespace

Classes: DirtyArray

Instance Attribute Summary

Attributes inherited from BaseType

#options

Instance Method Summary collapse

Methods inherited from BaseType

#initialize

Constructor Details

This class inherits a constructor from CassandraObject::Types::BaseType

Instance Method Details

#decode(str) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/cassandra_object/types/array_type.rb', line 63

def decode(str)
  return [] if str.blank?

  ActiveSupport::JSON.decode(str).tap do |array|
    array.uniq! if options[:unique]
  end
end

#defaultObject



54
55
56
# File 'lib/cassandra_object/types/array_type.rb', line 54

def default
  []
end

#encode(array) ⇒ Object

Raises:

  • (ArgumentError)


58
59
60
61
# File 'lib/cassandra_object/types/array_type.rb', line 58

def encode(array)
  raise ArgumentError.new("#{array.inspect} is not an Array") unless array.kind_of?(Array)
  array.to_a.to_json
end

#wrap(record, name, value) ⇒ Object



71
72
73
# File 'lib/cassandra_object/types/array_type.rb', line 71

def wrap(record, name, value)
  DirtyArray.new(record, name, Array(value), options)
end