gotime-cassandra_object 2.10.3 → 2.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/base.rb +0 -1
- data/lib/gotime-cassandra_object.rb +0 -1
- metadata +7 -10
- data/lib/cassandra_object/associations.rb +0 -46
- data/lib/cassandra_object/associations/one_to_many.rb +0 -146
- data/lib/cassandra_object/associations/one_to_one.rb +0 -85
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotime-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.10.
|
4
|
+
version: 2.10.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-01-10 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &70334275426700 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '3.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70334275426700
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: cassandra
|
28
|
-
requirement: &
|
28
|
+
requirement: &70334275424680 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.12.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70334275424680
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &70334275423800 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70334275423800
|
48
48
|
description: Cassandra ActiveModel
|
49
49
|
email: gems@gotime.com
|
50
50
|
executables: []
|
@@ -60,9 +60,6 @@ files:
|
|
60
60
|
- README.rdoc
|
61
61
|
- Rakefile
|
62
62
|
- gotime-cassandra_object.gemspec
|
63
|
-
- lib/cassandra_object/associations.rb
|
64
|
-
- lib/cassandra_object/associations/one_to_many.rb
|
65
|
-
- lib/cassandra_object/associations/one_to_one.rb
|
66
63
|
- lib/cassandra_object/attribute_methods.rb
|
67
64
|
- lib/cassandra_object/attribute_methods/definition.rb
|
68
65
|
- lib/cassandra_object/attribute_methods/dirty.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module CassandraObject
|
2
|
-
module Associations
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
extend ActiveSupport::Autoload
|
5
|
-
|
6
|
-
autoload :OneToMany
|
7
|
-
autoload :OneToOne
|
8
|
-
|
9
|
-
included do
|
10
|
-
class_inheritable_hash :associations
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def relationships_column_family=(column_family)
|
15
|
-
@relationships_column_family = column_family
|
16
|
-
end
|
17
|
-
|
18
|
-
def relationships_column_family
|
19
|
-
@relationships_column_family || "#{name}Relationships"
|
20
|
-
end
|
21
|
-
|
22
|
-
def column_family_configuration
|
23
|
-
super << {:Name=>relationships_column_family, :CompareWith=>"UTF8Type", :CompareSubcolumnsWith=>"TimeUUIDType", :ColumnType=>"Super"}
|
24
|
-
end
|
25
|
-
|
26
|
-
def association(association_name, options= {})
|
27
|
-
if options[:unique]
|
28
|
-
write_inheritable_hash(:associations, {association_name => OneToOne.new(association_name, self, options)})
|
29
|
-
else
|
30
|
-
write_inheritable_hash(:associations, {association_name => OneToMany.new(association_name, self, options)})
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def remove(key)
|
35
|
-
begin
|
36
|
-
ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: relationships_column_family, key: key) do
|
37
|
-
connection.remove(relationships_column_family, key.to_s, consistency: thrift_write_consistency)
|
38
|
-
end
|
39
|
-
rescue Cassandra::AccessError => e
|
40
|
-
raise e unless e.message =~ /Invalid column family/
|
41
|
-
end
|
42
|
-
super
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
module CassandraObject
|
2
|
-
module Associations
|
3
|
-
class OneToMany
|
4
|
-
def initialize(association_name, owner_class, options)
|
5
|
-
@association_name = association_name.to_s
|
6
|
-
@owner_class = owner_class
|
7
|
-
@target_class_name = options[:class_name] || association_name.to_s.singularize.camelize
|
8
|
-
@options = options
|
9
|
-
|
10
|
-
define_methods!
|
11
|
-
end
|
12
|
-
|
13
|
-
def find(owner, options = {})
|
14
|
-
reversed = options.has_key?(:reversed) ? options[:reversed] : reversed?
|
15
|
-
cursor = CassandraObject::Cursor.new(target_class, column_family, owner.key.to_s, @association_name, :start_after => options[:start_after], :reversed => reversed)
|
16
|
-
cursor.find(options[:limit] || 100)
|
17
|
-
end
|
18
|
-
|
19
|
-
def add(owner, record, set_inverse = true)
|
20
|
-
key = owner.key
|
21
|
-
attributes = {@association_name=>{new_key=>record.key.to_s}}
|
22
|
-
ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
|
23
|
-
connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
|
24
|
-
end
|
25
|
-
if has_inverse? && set_inverse
|
26
|
-
inverse.set_inverse(record, owner)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def new_key
|
31
|
-
SimpleUUID::UUID.new
|
32
|
-
end
|
33
|
-
|
34
|
-
def column_family
|
35
|
-
@owner_class.relationships_column_family
|
36
|
-
end
|
37
|
-
|
38
|
-
def connection
|
39
|
-
@owner_class.connection
|
40
|
-
end
|
41
|
-
|
42
|
-
def target_class
|
43
|
-
@target_class ||= @target_class_name.constantize
|
44
|
-
end
|
45
|
-
|
46
|
-
def new_proxy(owner)
|
47
|
-
OneToManyAssociationProxy.new(self, owner)
|
48
|
-
end
|
49
|
-
|
50
|
-
def has_inverse?
|
51
|
-
@options[:inverse_of]
|
52
|
-
end
|
53
|
-
|
54
|
-
def inverse
|
55
|
-
has_inverse? && target_class.associations[@options[:inverse_of]]
|
56
|
-
end
|
57
|
-
|
58
|
-
def set_inverse(owner, record)
|
59
|
-
add(owner, record, false)
|
60
|
-
end
|
61
|
-
|
62
|
-
def reversed?
|
63
|
-
@options[:reversed] == true
|
64
|
-
end
|
65
|
-
|
66
|
-
def define_methods!
|
67
|
-
@owner_class.class_eval <<-eos
|
68
|
-
def #{@association_name}
|
69
|
-
@_#{@association_name} ||= self.class.associations[:#{@association_name}].new_proxy(self)
|
70
|
-
end
|
71
|
-
eos
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class OneToManyAssociationProxy
|
76
|
-
def initialize(association, owner)
|
77
|
-
@association = association
|
78
|
-
@owner = owner
|
79
|
-
end
|
80
|
-
|
81
|
-
include Enumerable
|
82
|
-
def each
|
83
|
-
target.each do |i|
|
84
|
-
yield i
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def [](index)
|
89
|
-
to_a[index]
|
90
|
-
end
|
91
|
-
|
92
|
-
def <<(record)
|
93
|
-
@association.add(@owner, record)
|
94
|
-
if loaded?
|
95
|
-
@target << record
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Get the targets of this association proxy
|
100
|
-
#
|
101
|
-
# @param [Hash] options the options with which to modify this query
|
102
|
-
# @option options [String] :start_after the key after which to start returning results
|
103
|
-
# @option options [Boolean] :reversed (false or association default) return the results in reverse order
|
104
|
-
# @option options [Integer] :limit the max number of results to return
|
105
|
-
# @return [Array<CassandraObject::Base>] an array of objects of type self#target_class
|
106
|
-
#
|
107
|
-
def all(options = {})
|
108
|
-
@association.find(@owner, options)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Create a record of the associated type with
|
112
|
-
# the supplied attributes and add it to this
|
113
|
-
# association
|
114
|
-
#
|
115
|
-
# @param [Hash] attributes the attributes with which to create the object
|
116
|
-
# @return [CassandraObject::Base] the newly created object
|
117
|
-
#
|
118
|
-
def create(attributes)
|
119
|
-
@association.target_class.create(attributes).tap do |record|
|
120
|
-
if record.valid?
|
121
|
-
self << record
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def create!(attributes)
|
127
|
-
@association.target_class.create!(attributes).tap do |record|
|
128
|
-
self << record
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def target
|
133
|
-
@target ||= begin
|
134
|
-
@loaded = true
|
135
|
-
@association.find(@owner)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
alias to_a target
|
140
|
-
|
141
|
-
def loaded?
|
142
|
-
defined?(@loaded) && @loaded
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
module CassandraObject
|
2
|
-
module Associations
|
3
|
-
class OneToOne
|
4
|
-
def initialize(association_name, owner_class, options)
|
5
|
-
@association_name = association_name.to_s
|
6
|
-
@owner_class = owner_class
|
7
|
-
@target_class_name = options[:class_name] || association_name.to_s.camelize
|
8
|
-
@options = options
|
9
|
-
|
10
|
-
define_methods!
|
11
|
-
end
|
12
|
-
|
13
|
-
def define_methods!
|
14
|
-
@owner_class.class_eval <<-eos
|
15
|
-
def #{@association_name}
|
16
|
-
@_#{@association_name} ||= self.class.associations[:#{@association_name}].find(self)
|
17
|
-
end
|
18
|
-
|
19
|
-
def #{@association_name}=(record)
|
20
|
-
@_#{@association_name} = record
|
21
|
-
self.class.associations[:#{@association_name}].set(self, record)
|
22
|
-
end
|
23
|
-
eos
|
24
|
-
end
|
25
|
-
|
26
|
-
def clear(owner)
|
27
|
-
ActiveSupport::Notifications.instrument("remove.cassandra_object", :column_family => column_family, :key => owner.key, :columns => @association_name) do
|
28
|
-
connection.remove(column_family, owner.key.to_s, @association_name)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def find(owner)
|
33
|
-
if key = connection.get(column_family, owner.key.to_s, @association_name.to_s, :count=>1).values.first
|
34
|
-
target_class.get(key)
|
35
|
-
else
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def set(owner, record, set_inverse = true)
|
41
|
-
clear(owner)
|
42
|
-
key = owner.key
|
43
|
-
attributes = {@association_name=>{new_key=>record.key.to_s}}
|
44
|
-
ActiveSupport::Notifications.instrument("insert.cassandra_object", :column_family => column_family, :key => key, :attributes => attributes) do
|
45
|
-
connection.insert(column_family, key.to_s, attributes, :consistency => @owner_class.thrift_write_consistency)
|
46
|
-
end
|
47
|
-
if has_inverse? && set_inverse
|
48
|
-
inverse.set_inverse(record, owner)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def new_key
|
53
|
-
SimpleUUID::UUID.new
|
54
|
-
end
|
55
|
-
|
56
|
-
def set_inverse(owner, record)
|
57
|
-
set(owner, record, false)
|
58
|
-
end
|
59
|
-
|
60
|
-
def has_inverse?
|
61
|
-
@options[:inverse_of]
|
62
|
-
end
|
63
|
-
|
64
|
-
def inverse
|
65
|
-
has_inverse? && target_class.associations[@options[:inverse_of]]
|
66
|
-
end
|
67
|
-
|
68
|
-
def column_family
|
69
|
-
@owner_class.relationships_column_family
|
70
|
-
end
|
71
|
-
|
72
|
-
def connection
|
73
|
-
@owner_class.connection
|
74
|
-
end
|
75
|
-
|
76
|
-
def target_class
|
77
|
-
@target_class ||= @target_class_name.constantize
|
78
|
-
end
|
79
|
-
|
80
|
-
def new_proxy(owner)
|
81
|
-
# OneToManyAssociationProxy.new(self, owner)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|