Module: CassandraObject::Inspect

Included in:
Base, CounterBase
Defined in:
lib/cassandra_object/inspect.rb

Instance Method Summary collapse

Instance Method Details

#attribute_for_inspect(value) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/cassandra_object/inspect.rb', line 15

def attribute_for_inspect(value)
  if value.is_a?(String) && value.length > 50
    "#{value[0..50]}...".inspect
  elsif value.is_a?(Date) || value.is_a?(Time)
    %("#{value.to_s(:db)}")
  else
    value.inspect
  end
end

#inspectObject



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/cassandra_object/inspect.rb', line 3

def inspect
  inspection = ["#{self.class.primary_key}: #{id.inspect}"]

  @attributes.each do |attribute, value|
    if value.present?
      inspection << "#{attribute}: #{attribute_for_inspect(value)}"
    end
  end

  "#<#{self.class} #{inspection * ', '}>"
end