Module: Believer::Columns::ClassMethods

Defined in:
lib/believer/columns.rb

Instance Method Summary collapse

Instance Method Details

#column(name, opts = {}) ⇒ Object

The column name must correspond with the Cassandra column name



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/believer/columns.rb', line 88

def column(name, opts = {})
  defaults = {
      :type => :string
  }
  options = defaults.merge(opts).merge(:name => name)

  columns[name] = Column.new(options)

  self.redefine_method(name) do
    read_attribute(name)
  end

  self.redefine_method("#{name}=") do |val|
    write_attribute(name, val)
  end
end

#columnsObject

Returns all columns on the model

Returns:



82
83
84
# File 'lib/believer/columns.rb', line 82

def columns
  @columns ||= {}
end

#get_primary_keyObject



109
110
111
# File 'lib/believer/columns.rb', line 109

def get_primary_key
  @primary_key.dup
end

#has_compound_key?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/believer/columns.rb', line 127

def has_compound_key?
  @primary_key.size > 1
end

#partition_keyObject



117
118
119
# File 'lib/believer/columns.rb', line 117

def partition_key
  @primary_key.first.dup
end

#partition_keysObject



121
122
123
124
125
# File 'lib/believer/columns.rb', line 121

def partition_keys
  part_key = partition_key
  return part_key.dup if part_key.is_a?(Enumerable)
  [part_key]
end

#primary_key(*cols) ⇒ Object



105
106
107
# File 'lib/believer/columns.rb', line 105

def primary_key(*cols)
  @primary_key = *cols
end

#primary_key_columnsObject



113
114
115
# File 'lib/believer/columns.rb', line 113

def primary_key_columns
  @primary_key.flatten
end