Class: Cassandra::Types::Custom

Inherits:
Cassandra::Type show all
Defined in:
lib/cassandra/types.rb

Instance Attribute Summary collapse

Attributes inherited from Cassandra::Type

#kind

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Custom

Returns a new instance of Custom.



1371
1372
1373
1374
# File 'lib/cassandra/types.rb', line 1371

def initialize(name)
  super(:custom)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



1369
1370
1371
# File 'lib/cassandra/types.rb', line 1369

def name
  @name
end

Instance Method Details

#assert(value, message = nil, &block) ⇒ void

This method returns an undefined value.

Asserts that a given value is of this type

Parameters:

  • value (Object)

    value to be validated

  • message (String) (defaults to: nil)

    error message to use when assertion fails

Yield Returns:

  • (String)

    error message to use when assertion fails

Raises:

  • (ArgumentError)

    if the value is invalid



1391
1392
1393
1394
# File 'lib/cassandra/types.rb', line 1391

def assert(value, message = nil, &block)
  Util.assert_instance_of(CustomData, value, message, &block)
  Util.assert_equal(self, value.class.type, message, &block)
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:



1410
1411
1412
# File 'lib/cassandra/types.rb', line 1410

def eql?(other)
  other.is_a?(Custom) && @name == other.name
end

#hashObject



1401
1402
1403
1404
1405
1406
1407
1408
# File 'lib/cassandra/types.rb', line 1401

def hash
  @hash ||= begin
    h = 17
    h = 31 * h + @kind.hash
    h = 31 * h + @name.hash
    h
  end
end

#new(*value) ⇒ Object

Coerces a given value to this type

Parameters:

  • value (*Object)

    value to be coerced

Returns:

  • (Object)

    a value of this type

Raises:

  • (::NotImplementedError)


1380
1381
1382
1383
# File 'lib/cassandra/types.rb', line 1380

def new(*value)
  raise ::NotImplementedError,
        "unable to create a value for custom type: #{@name.inspect}"
end

#to_sString

Returns a cassandra representation of this type.

Returns:

  • (String)

    a cassandra representation of this type



1397
1398
1399
# File 'lib/cassandra/types.rb', line 1397

def to_s
  "'#{@name}'"
end