Class: CassandraObject::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming, ActiveRecord::Delegation::DelegateCache, ActiveSupport::DescendantsTracker
Includes:
ActiveModel::Conversion, Arel, Associations, Attributes, Batches, Callbacks, Configuration, Connection, Consistency, Dirty, FinderMethods, Identity, Migrations, Mocking, NestedAttributes, Persistence, RowTTL, Serialization, Timestamps, Validations
Defined in:
lib/cassandra_object/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NestedAttributes

#_destroy

Methods included from Callbacks

#destroy, #touch

Methods included from Validations

#save, #save!, #valid?

Methods included from Dirty

#save, #save!, #write_attribute

Methods included from Persistence

#destroy, #destroyed?, #new_record?, #persisted?, #reload, #save, #save!, #update_attribute, #update_attributes, #update_attributes!

Methods included from Attributes

#attributes=, #read_attribute, #write_attribute

Methods included from Identity

#id, #id=

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



77
78
79
80
81
82
83
84
85
86
# File 'lib/cassandra_object/base.rb', line 77

def initialize(attributes={})
  @key = attributes.delete(:key)
  @new_record = true
  @destroyed = false
  @readonly = false
  @attributes = {}.with_indifferent_access
  @association_cache = {}
  self.attributes = attributes
  @schema_version = self.class.current_schema_version
end

Instance Attribute Details

#association_cacheObject

Returns the value of attribute association_cache.



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

def association_cache
  @association_cache
end

#keyObject

Returns the value of attribute key.



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

def key
  @key
end

#schema_versionObject

Returns the value of attribute schema_version.



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

def schema_version
  @schema_version
end

Class Method Details

.base_classObject



20
21
22
23
24
25
26
# File 'lib/cassandra_object/base.rb', line 20

def base_class
  klass = self
  while klass.superclass != Base
    klass = klass.superclass
  end
  klass
end

.column_familyObject Also known as: table_name



15
16
17
# File 'lib/cassandra_object/base.rb', line 15

def column_family
  @column_family || name.pluralize
end

.column_family=(column_family) ⇒ Object Also known as: table_name=



10
11
12
# File 'lib/cassandra_object/base.rb', line 10

def column_family=(column_family)
  @column_family = column_family
end

.columns_hashObject



36
37
38
# File 'lib/cassandra_object/base.rb', line 36

def columns_hash
  connection.schema_cache.columns_hash table_name
end

.compute_type(*args) ⇒ Object



28
29
30
# File 'lib/cassandra_object/base.rb', line 28

def compute_type(*args)
  ActiveRecord::Base.send :compute_type, *args
end

.loggerObject



40
41
42
# File 'lib/cassandra_object/base.rb', line 40

def logger
  ActiveRecord::Base.logger
end

.primary_keyObject



32
33
34
# File 'lib/cassandra_object/base.rb', line 32

def primary_key
  'id'
end

Instance Method Details

#==(comparison_object) ⇒ Object



114
115
116
117
118
119
# File 'lib/cassandra_object/base.rb', line 114

def ==(comparison_object)
  comparison_object.equal?(self) ||
    (comparison_object.instance_of?(self.class) &&
      comparison_object.key == key &&
      !comparison_object.new_record?)
end

#[](attr_name) ⇒ Object

Returns the value of the attribute identified by attr_name after it has been typecast (for example, “2004-12-12” in a data column is cast to a date object, like Date.new(2004, 12, 12)). (Alias for the protected read_attribute method).



128
129
130
# File 'lib/cassandra_object/base.rb', line 128

def [](attr_name)
  read_attribute(attr_name)
end

#[]=(attr_name, value) ⇒ Object

Updates the attribute identified by attr_name with the specified value. (Alias for the protected write_attribute method).



134
135
136
# File 'lib/cassandra_object/base.rb', line 134

def []=(attr_name, value)
  write_attribute(attr_name, value)
end

#attributesObject



102
103
104
# File 'lib/cassandra_object/base.rb', line 102

def attributes
  @attributes.merge(:id => id)
end

#eql?(comparison_object) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/cassandra_object/base.rb', line 121

def eql?(comparison_object)
  self == (comparison_object)
end

#hashObject



110
111
112
# File 'lib/cassandra_object/base.rb', line 110

def hash
  id.hash
end

#loggerObject



45
46
47
# File 'lib/cassandra_object/base.rb', line 45

def logger
  self.class.logger
end

#readonly!Object

Marks this record as read only.



98
99
100
# File 'lib/cassandra_object/base.rb', line 98

def readonly!
  self.readonly = true
end

#readonly=(value) ⇒ Object



93
94
95
# File 'lib/cassandra_object/base.rb', line 93

def readonly=(value)
  @readonly = value
end

#readonly?Boolean

Returns true if the record is read only.

Returns:

  • (Boolean)


89
90
91
# File 'lib/cassandra_object/base.rb', line 89

def readonly?
  @readonly
end

#to_paramObject



106
107
108
# File 'lib/cassandra_object/base.rb', line 106

def to_param
  id.to_s if persisted?
end