Skip to content

Some additions #11

Open
wants to merge 4 commits into from
View
4 active_column.gemspec
@@ -17,10 +17,10 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = ["lib"]
+ s.require_paths = ["lib", "lib/active_column/types"]
s.add_dependency 'cassandra', '>= 0.12'
- s.add_dependency 'simple_uuid', '~> 0.1.0'
+ s.add_dependency 'simple_uuid', '~> 0.2.0'
s.add_dependency 'rake'
s.add_development_dependency 'rails', '>= 3.0'
View
5 lib/active_column.rb
@@ -6,6 +6,7 @@ module ActiveColumn
autoload :Base, 'active_column/base'
autoload :Configuration, 'active_column/configuration'
+ autoload :Constants, 'active_column/constants'
autoload :KeyConfig, 'active_column/key_config'
autoload :Version, 'active_column/version'
autoload :Helpers, 'active_column/helpers'
@@ -19,6 +20,10 @@ module Tasks
autoload :ColumnFamily, 'active_column/tasks/column_family'
end
+ module Types
+ autoload :ColumnFamily, 'active_column/types/column_family'
+ end
+
load 'active_column/tasks/ks.rake'
View
18 lib/active_column/constants.rb
@@ -0,0 +1,18 @@
+module ActiveColumn
+ module Constants
+ COMPARATOR_TYPES = {
+ :time => 'TimeUUIDType',
+ :timestamp => 'TimeUUIDType',
+ :long => 'LongType',
+ :string => 'BytesType',
+ :utf8 => 'UTF8Type',
+ :lexical_uuid => 'LexicalUUIDType',
+ :double => 'DoubleType'
+ }
+
+ COLUMN_TYPES = {
+ :super => 'Super',
+ :standard => 'Standard'
+ }
+ end
+end
View
4 lib/active_column/generators/templates/migration.rb.erb
@@ -1,4 +1,4 @@
-class <%= name %> < ActiveColumn::Migration
+class <%= name.camelcase %> < ActiveColumn::Migration
def self.up
@@ -8,4 +8,4 @@ class <%= name %> < ActiveColumn::Migration
end
-end
+end
View
28 lib/active_column/tasks/column_family.rb
@@ -4,16 +4,8 @@ module Tasks
class ColumnFamily
- COMPARATOR_TYPES = { :time => 'TimeUUIDType',
- :timestamp => 'TimeUUIDType',
- :long => 'LongType',
- :string => 'BytesType',
- :utf8 => 'UTF8Type',
- :lexical_uuid => 'LexicalUUIDType'}
-
- COLUMN_TYPES = { :super => 'Super',
- :standard => 'Standard' }
-
+ include ActiveColumn::Constants
+
def initialize(keyspace)
raise 'Cannot operate on system keyspace' if keyspace == 'system'
@keyspace = keyspace
@@ -24,10 +16,11 @@ def exists?(name)
end
def create(name, &block)
- cf = Cassandra::ColumnFamily.new
+ cf = ActiveColumn::Types::ColumnFamily.new
cf.name = name.to_s
cf.keyspace = @keyspace.to_s
cf.comparator_type = 'TimeUUIDType'
+ cf.column_metadata = []
block.call cf if block
@@ -84,7 +77,18 @@ def post_process_column_family(cf)
else
raise ArgumentError, "Unrecognized column_type #{column_type}"
end
-
+
+ replace = ["comparator_type", "default_validation_class", "key_validation_class"]
+ replace.each do |rep|
+ attr = cf.send(rep)
+ next unless attr.is_a? Symbol
+ if COMPARATOR_TYPES.has_key?(attr)
+ cf.send("#{rep}=", COMPARATOR_TYPES[attr])
+ else
+ raise ArgumentError, "Unrecognized #{rep}: #{attr}"
+ end
+ end
+
cf
end
View
25 lib/active_column/types/column_family.rb
@@ -0,0 +1,25 @@
+module ActiveColumn
+ module Types
+ class ColumnFamily < Cassandra::ColumnFamily
+
+ include ActiveColumn::Constants
+
+ def column(name, &block)
+ cd = CassandraThrift::ColumnDef.new
+ cd.name = name.to_s
+ block.call cd if block
+ post_process_column_metadata(cd)
+ self.column_metadata << cd
+ end
+
+ private
+
+ def post_process_column_metadata(cd)
+ validation_class = cd.validation_class
+ if validation_class && COMPARATOR_TYPES.has_key?(validation_class)
+ cd.validation_class = COMPARATOR_TYPES[validation_class]
+ end
+ end
+ end
+ end
+end
View
2 lib/active_column/version.rb
@@ -1,3 +1,3 @@
module ActiveColumn
- VERSION = "0.2"
+ VERSION = "0.2.1"
end
Something went wrong with that request. Please try again.