Class: CassandraObject::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra_object/attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, converter, expected_type, options) ⇒ Attribute

Returns a new instance of Attribute.



4
5
6
7
8
9
# File 'lib/cassandra_object/attributes.rb', line 4

def initialize(name, converter, expected_type, options)
  @name          = name.to_s
  @converter     = converter
  @expected_type = expected_type
  @options       = options
end

Instance Attribute Details

#converterObject (readonly)

Returns the value of attribute converter.



3
4
5
# File 'lib/cassandra_object/attributes.rb', line 3

def converter
  @converter
end

#expected_typeObject (readonly)

Returns the value of attribute expected_type.



3
4
5
# File 'lib/cassandra_object/attributes.rb', line 3

def expected_type
  @expected_type
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/cassandra_object/attributes.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/cassandra_object/attributes.rb', line 3

def options
  @options
end

Instance Method Details

#check_value!(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/cassandra_object/attributes.rb', line 11

def check_value!(value)
  return value if value.nil?
  if value.kind_of?(expected_type)
    value
  elsif converter.method(:decode).arity == 1
    converter.decode(value)
  else
    converter.decode(value, @options)
  end
end