gotime-cassandra_object 0.9.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +70 -25
- data/Rakefile +11 -39
- data/gotime-cassandra_object.gemspec +6 -6
- data/lib/cassandra_object.rb +6 -12
- data/lib/cassandra_object/associations.rb +1 -1
- data/lib/cassandra_object/attributes.rb +53 -43
- data/lib/cassandra_object/base.rb +4 -17
- data/lib/cassandra_object/batches.rb +13 -0
- data/lib/cassandra_object/connection.rb +15 -0
- data/lib/cassandra_object/dirty.rb +19 -14
- data/lib/cassandra_object/finder_methods.rb +64 -0
- data/lib/cassandra_object/identity.rb +0 -1
- data/lib/cassandra_object/migrations.rb +3 -1
- data/lib/cassandra_object/persistence.rb +51 -94
- data/lib/cassandra_object/railtie.rb +11 -0
- data/lib/cassandra_object/tasks/{ks.rb → ks.rake} +0 -2
- data/lib/cassandra_object/validation.rb +11 -15
- data/{test → test-old}/active_model_test.rb +0 -0
- data/test-old/base_test.rb +4 -0
- data/{test → test-old}/basic_scenarios_test.rb +0 -0
- data/{test → test-old}/callbacks_test.rb +0 -0
- data/{test → test-old}/config/cassandra.in.sh +0 -0
- data/{test → test-old}/config/log4j.properties +0 -0
- data/{test → test-old}/config/storage-conf.xml +0 -0
- data/{test → test-old}/connection.rb +0 -0
- data/{test → test-old}/cursor_test.rb +0 -0
- data/{test → test-old}/dirty_test.rb +0 -0
- data/{test → test-old}/fixture_models.rb +0 -0
- data/{test → test-old}/identity/natural_key_factory_test.rb +0 -0
- data/{test → test-old}/index_test.rb +0 -0
- data/{test → test-old}/legacy/test_helper.rb +0 -0
- data/{test → test-old}/migration_test.rb +0 -0
- data/{test → test-old}/one_to_many_associations_test.rb +0 -0
- data/{test → test-old}/test_case.rb +0 -0
- data/test-old/test_helper.rb +16 -0
- data/{test → test-old}/time_test.rb +0 -0
- data/{test → test-old}/types_test.rb +0 -0
- data/{test → test-old}/validation_test.rb +0 -0
- data/{test → test-old}/z_mock_test.rb +0 -0
- data/test/batches_test.rb +15 -0
- data/test/connection_test.rb +17 -0
- data/test/finder_methods_test.rb +28 -0
- data/test/identity_test.rb +15 -0
- data/test/persistence_test.rb +17 -0
- data/test/test_helper.rb +21 -12
- metadata +75 -165
- data/lib/cassandra_object/find_each.rb +0 -28
- data/lib/cassandra_object/find_with_ids.rb +0 -24
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "http://rubygems.org"
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,39 +1,87 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gotime-cassandra_object (0.
|
5
|
-
|
6
|
-
|
7
|
-
cassandra
|
4
|
+
gotime-cassandra_object (0.9.1)
|
5
|
+
cassandra (~> 0.11.3)
|
6
|
+
rails (~> 3.0)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: http://rubygems.org/
|
11
10
|
specs:
|
12
|
-
|
13
|
-
|
11
|
+
abstract (1.0.0)
|
12
|
+
actionmailer (3.0.9)
|
13
|
+
actionpack (= 3.0.9)
|
14
|
+
mail (~> 2.2.19)
|
15
|
+
actionpack (3.0.9)
|
16
|
+
activemodel (= 3.0.9)
|
17
|
+
activesupport (= 3.0.9)
|
14
18
|
builder (~> 2.1.2)
|
15
|
-
|
16
|
-
|
19
|
+
erubis (~> 2.6.6)
|
20
|
+
i18n (~> 0.5.0)
|
21
|
+
rack (~> 1.2.1)
|
22
|
+
rack-mount (~> 0.6.14)
|
23
|
+
rack-test (~> 0.5.7)
|
24
|
+
tzinfo (~> 0.3.23)
|
25
|
+
activemodel (3.0.9)
|
26
|
+
activesupport (= 3.0.9)
|
27
|
+
builder (~> 2.1.2)
|
28
|
+
i18n (~> 0.5.0)
|
29
|
+
activerecord (3.0.9)
|
30
|
+
activemodel (= 3.0.9)
|
31
|
+
activesupport (= 3.0.9)
|
32
|
+
arel (~> 2.0.10)
|
33
|
+
tzinfo (~> 0.3.23)
|
34
|
+
activeresource (3.0.9)
|
35
|
+
activemodel (= 3.0.9)
|
36
|
+
activesupport (= 3.0.9)
|
37
|
+
activesupport (3.0.9)
|
38
|
+
arel (2.0.10)
|
17
39
|
builder (2.1.2)
|
18
|
-
cassandra (0.
|
40
|
+
cassandra (0.11.3)
|
19
41
|
json
|
20
42
|
rake
|
21
43
|
simple_uuid (>= 0.1.0)
|
22
|
-
thrift_client (>= 0.6.
|
23
|
-
|
44
|
+
thrift_client (>= 0.6.3)
|
45
|
+
erubis (2.6.6)
|
46
|
+
abstract (>= 1.0.0)
|
24
47
|
i18n (0.5.0)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
48
|
+
json (1.5.3)
|
49
|
+
mail (2.2.19)
|
50
|
+
activesupport (>= 2.3.6)
|
51
|
+
i18n (>= 0.4.0)
|
52
|
+
mime-types (~> 1.16)
|
53
|
+
treetop (~> 1.4.8)
|
54
|
+
mime-types (1.16)
|
55
|
+
polyglot (0.3.1)
|
56
|
+
rack (1.2.3)
|
57
|
+
rack-mount (0.6.14)
|
58
|
+
rack (>= 1.0.0)
|
59
|
+
rack-test (0.5.7)
|
60
|
+
rack (>= 1.0)
|
61
|
+
rails (3.0.9)
|
62
|
+
actionmailer (= 3.0.9)
|
63
|
+
actionpack (= 3.0.9)
|
64
|
+
activerecord (= 3.0.9)
|
65
|
+
activeresource (= 3.0.9)
|
66
|
+
activesupport (= 3.0.9)
|
67
|
+
bundler (~> 1.0)
|
68
|
+
railties (= 3.0.9)
|
69
|
+
railties (3.0.9)
|
70
|
+
actionpack (= 3.0.9)
|
71
|
+
activesupport (= 3.0.9)
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
rdoc (~> 3.4)
|
74
|
+
thor (~> 0.14.4)
|
75
|
+
rake (0.9.2)
|
76
|
+
rdoc (3.8)
|
33
77
|
simple_uuid (0.1.1)
|
34
|
-
|
35
|
-
|
36
|
-
|
78
|
+
thor (0.14.6)
|
79
|
+
thrift (0.6.0)
|
80
|
+
thrift_client (0.6.3)
|
81
|
+
thrift (~> 0.6.0)
|
82
|
+
treetop (1.4.9)
|
83
|
+
polyglot (>= 0.3.1)
|
84
|
+
tzinfo (0.3.29)
|
37
85
|
|
38
86
|
PLATFORMS
|
39
87
|
ruby
|
@@ -41,6 +89,3 @@ PLATFORMS
|
|
41
89
|
DEPENDENCIES
|
42
90
|
bundler (~> 1.0.0)
|
43
91
|
gotime-cassandra_object!
|
44
|
-
jeweler (~> 1.5.1)
|
45
|
-
rcov
|
46
|
-
shoulda
|
data/Rakefile
CHANGED
@@ -1,43 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rake'
|
4
4
|
require 'rake/testtask'
|
5
|
-
Rake::TestTask.new(:test) do |test|
|
6
|
-
test.libs << 'lib' << 'test'
|
7
|
-
test.pattern = 'test/**/test_*.rb'
|
8
|
-
test.verbose = true
|
9
|
-
end
|
10
|
-
|
11
|
-
require 'rcov/rcovtask'
|
12
|
-
Rcov::RcovTask.new do |test|
|
13
|
-
test.libs << 'test'
|
14
|
-
test.pattern = 'test/**/test_*.rb'
|
15
|
-
test.verbose = true
|
16
|
-
end
|
17
|
-
|
18
|
-
task :default => :test
|
19
|
-
|
20
|
-
require 'rake/rdoctask'
|
21
|
-
Rake::RDocTask.new do |rdoc|
|
22
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
23
|
-
|
24
|
-
rdoc.rdoc_dir = 'rdoc'
|
25
|
-
rdoc.title = "cassandra_object #{version}"
|
26
|
-
rdoc.rdoc_files.include('README*')
|
27
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
28
|
-
end
|
29
5
|
|
30
|
-
|
31
|
-
unless defined?(CassandraObject)
|
32
|
-
$: << 'test'
|
33
|
-
$: << 'lib'
|
34
|
-
require 'test_helper'
|
35
|
-
end
|
36
|
-
puts "Clearing keyspace! ..."
|
37
|
-
CassandraObject::Base.connection.clear_keyspace!
|
38
|
-
puts "Cleared"
|
39
|
-
end
|
6
|
+
# require File.expand_path('../lib/cassandra_object', __FILE__)
|
40
7
|
|
41
|
-
task
|
42
|
-
end
|
8
|
+
task default: :test
|
43
9
|
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.libs << 'test'
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
@@ -2,25 +2,25 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'gotime-cassandra_object'
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '2.0.0'
|
6
6
|
s.description = 'Cassandra ActiveModel'
|
7
7
|
s.summary = 'Cassandra ActiveModel'
|
8
|
+
|
9
|
+
s.required_ruby_version = '>= 1.9.2'
|
8
10
|
s.required_rubygems_version = '>= 1.3.5'
|
11
|
+
|
9
12
|
s.authors = ["Michael Koziarski", "gotime"]
|
10
13
|
s.email = 'gems@gotime.com'
|
11
14
|
s.homepage = 'http://github.com/gotime/cassandra_object'
|
15
|
+
|
12
16
|
s.extra_rdoc_files = ["README.markdown"]
|
13
17
|
s.files = `git ls-files`.split("\n")
|
14
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
19
|
s.require_paths = ['lib']
|
16
20
|
|
17
|
-
s.add_runtime_dependency('
|
18
|
-
s.add_runtime_dependency('activemodel', "~> 3.0")
|
21
|
+
s.add_runtime_dependency('rails', "~> 3.0")
|
19
22
|
s.add_runtime_dependency('cassandra', "~> 0.11.3")
|
20
23
|
|
21
|
-
s.add_development_dependency('shoulda')
|
22
24
|
s.add_development_dependency('bundler', "~> 1.0.0")
|
23
|
-
s.add_development_dependency('jeweler', "~> 1.5.1")
|
24
|
-
s.add_development_dependency('rcov')
|
25
25
|
end
|
26
26
|
|
data/lib/cassandra_object.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
require 'i18n'
|
3
|
-
require 'active_support'
|
4
|
-
require 'active_model'
|
1
|
+
require 'rails/all'
|
5
2
|
|
6
3
|
module CassandraObject
|
7
4
|
extend ActiveSupport::Autoload
|
8
5
|
|
9
6
|
autoload :Base
|
7
|
+
autoload :Connection
|
10
8
|
autoload :Attributes
|
11
9
|
autoload :Dirty
|
12
10
|
autoload :Consistency
|
@@ -22,8 +20,8 @@ module CassandraObject
|
|
22
20
|
autoload :Collection
|
23
21
|
autoload :Types
|
24
22
|
autoload :Mocking
|
25
|
-
autoload :
|
26
|
-
autoload :
|
23
|
+
autoload :Batches
|
24
|
+
autoload :FinderMethods
|
27
25
|
autoload :Timestamps
|
28
26
|
|
29
27
|
autoload :Schema
|
@@ -32,11 +30,7 @@ module CassandraObject
|
|
32
30
|
extend ActiveSupport::Autoload
|
33
31
|
autoload :Keyspace
|
34
32
|
autoload :ColumnFamily
|
35
|
-
|
36
|
-
require 'cassandra_object/tasks/ks'
|
37
|
-
end
|
38
|
-
|
39
|
-
module Generators
|
40
|
-
require 'cassandra_object/generators/migration_generator'
|
41
33
|
end
|
42
34
|
end
|
35
|
+
|
36
|
+
require 'cassandra_object/railtie'
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module CassandraObject
|
2
2
|
class Attribute
|
3
|
-
|
4
3
|
attr_reader :name, :converter, :expected_type
|
5
4
|
def initialize(name, owner_class, converter, expected_type, options)
|
6
5
|
@name = name.to_s
|
@@ -14,10 +13,6 @@ module CassandraObject
|
|
14
13
|
return value if value.nil?
|
15
14
|
value.kind_of?(expected_type) ? value : converter.decode(value)
|
16
15
|
end
|
17
|
-
|
18
|
-
def define_methods!
|
19
|
-
@owner_class.define_attribute_methods(true)
|
20
|
-
end
|
21
16
|
end
|
22
17
|
|
23
18
|
module Attributes
|
@@ -26,68 +21,83 @@ module CassandraObject
|
|
26
21
|
|
27
22
|
module ClassMethods
|
28
23
|
def attribute(name, options)
|
29
|
-
|
24
|
+
if model_attributes.empty?
|
25
|
+
self.model_attributes = {}.with_indifferent_access
|
26
|
+
end
|
27
|
+
|
30
28
|
unless type_mapping = attribute_types[options[:type]]
|
31
|
-
type_mapping =
|
32
|
-
|
29
|
+
type_mapping = {
|
30
|
+
expected_type: options[:type],
|
31
|
+
converter: options[:converter]
|
32
|
+
}.with_indifferent_access
|
33
33
|
end
|
34
|
-
|
35
|
-
|
36
|
-
write_inheritable_hash(:model_attributes, {name => new_attr}.with_indifferent_access)
|
37
|
-
new_attr.define_methods!
|
34
|
+
|
35
|
+
model_attributes[name] = Attribute.new(name, self, type_mapping[:converter], type_mapping[:expected_type], options)
|
38
36
|
end
|
39
37
|
|
40
|
-
def define_attribute_methods
|
41
|
-
return unless model_attributes
|
42
|
-
undefine_attribute_methods if force
|
38
|
+
def define_attribute_methods
|
43
39
|
super(model_attributes.keys)
|
44
40
|
end
|
45
|
-
|
41
|
+
|
46
42
|
def register_attribute_type(name, expected_type, converter)
|
47
|
-
attribute_types[name] = { :
|
43
|
+
attribute_types[name] = { expected_type: expected_type, converter: converter }.with_indifferent_access
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
51
47
|
included do
|
52
|
-
|
48
|
+
class_attribute :model_attributes
|
49
|
+
self.model_attributes = {}.with_indifferent_access
|
50
|
+
|
53
51
|
attribute_method_suffix("", "=")
|
54
52
|
|
55
53
|
cattr_accessor :attribute_types
|
56
54
|
self.attribute_types = {}.with_indifferent_access
|
57
55
|
end
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
raise NoMethodError, "Unknown attribute #{name.inspect}"
|
65
|
-
end
|
57
|
+
def write_attribute(name, value)
|
58
|
+
if ma = self.class.model_attributes[name]
|
59
|
+
@attributes[name.to_s] = ma.check_value!(value)
|
60
|
+
else
|
61
|
+
raise NoMethodError, "Unknown attribute #{name.inspect}"
|
66
62
|
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def read_attribute(name)
|
66
|
+
@attributes[name.to_s]
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
69
|
+
def attributes=(attributes)
|
70
|
+
attributes.each do |(name, value)|
|
71
|
+
send("#{name}=", value)
|
70
72
|
end
|
73
|
+
end
|
71
74
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
def method_missing(method_id, *args, &block)
|
76
|
+
if !self.class.attribute_methods_generated?
|
77
|
+
self.class.define_attribute_methods
|
78
|
+
send(method_id, *args, &block)
|
79
|
+
else
|
80
|
+
super
|
76
81
|
end
|
82
|
+
end
|
77
83
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
84
|
+
def respond_to?(*args)
|
85
|
+
self.class.define_attribute_methods unless self.class.attribute_methods_generated?
|
86
|
+
super
|
87
|
+
end
|
82
88
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
89
|
+
protected
|
90
|
+
def attribute_method?(name)
|
91
|
+
!!model_attributes[name.to_sym]
|
92
|
+
end
|
87
93
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
94
|
+
private
|
95
|
+
def attribute(name)
|
96
|
+
read_attribute(name.to_sym)
|
97
|
+
end
|
98
|
+
|
99
|
+
def attribute=(name, value)
|
100
|
+
write_attribute(name.to_sym, value)
|
101
|
+
end
|
92
102
|
end
|
93
103
|
end
|
@@ -1,24 +1,10 @@
|
|
1
|
-
require 'cassandra/0.
|
1
|
+
require 'cassandra/0.8'
|
2
2
|
require 'set'
|
3
3
|
|
4
4
|
require 'cassandra_object/log_subscriber'
|
5
5
|
|
6
6
|
module CassandraObject
|
7
7
|
class Base
|
8
|
-
class_inheritable_accessor :connection
|
9
|
-
class_inheritable_writer :connection_class
|
10
|
-
|
11
|
-
def self.connection_class
|
12
|
-
read_inheritable_attribute(:connection_class) || Cassandra
|
13
|
-
end
|
14
|
-
|
15
|
-
module ConnectionManagement
|
16
|
-
def establish_connection(*args)
|
17
|
-
self.connection = connection_class.new(*args)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
extend ConnectionManagement
|
21
|
-
|
22
8
|
module Naming
|
23
9
|
def column_family=(column_family)
|
24
10
|
@column_family = column_family
|
@@ -43,6 +29,7 @@ module CassandraObject
|
|
43
29
|
extend ActiveModel::Naming
|
44
30
|
extend ActiveSupport::DescendantsTracker
|
45
31
|
|
32
|
+
include Connection
|
46
33
|
include Callbacks
|
47
34
|
include Identity
|
48
35
|
include Attributes
|
@@ -51,8 +38,8 @@ module CassandraObject
|
|
51
38
|
include Dirty
|
52
39
|
include Validation
|
53
40
|
include Associations
|
54
|
-
include
|
55
|
-
include
|
41
|
+
include Batches
|
42
|
+
include FinderMethods
|
56
43
|
|
57
44
|
attr_reader :attributes
|
58
45
|
attr_accessor :key
|