gotime-cassandra_object 4.4.0 → 4.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -4
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/inspect.rb +5 -5
- data/lib/cassandra_object/persistence.rb +11 -3
- data/lib/cassandra_object/scope/finder_methods.rb +1 -2
- data/lib/cassandra_object/scope/query_methods.rb +2 -2
- data/test/unit/inspect_test.rb +5 -4
- data/test/unit/persistence_test.rb +14 -0
- metadata +2 -2
data/.travis.yml
CHANGED
@@ -3,16 +3,16 @@ module CassandraObject
|
|
3
3
|
def inspect
|
4
4
|
inspection = ["#{self.class.primary_key}: #{id.inspect}"]
|
5
5
|
|
6
|
-
@attributes.
|
7
|
-
|
6
|
+
@attributes.each do |attribute, value|
|
7
|
+
if value.present?
|
8
|
+
inspection << "#{attribute}: #{attribute_for_inspect(value)}"
|
9
|
+
end
|
8
10
|
end
|
9
11
|
|
10
12
|
"#<#{self.class} #{inspection * ', '}>"
|
11
13
|
end
|
12
14
|
|
13
|
-
def attribute_for_inspect(
|
14
|
-
value = read_attribute(attr_name)
|
15
|
-
|
15
|
+
def attribute_for_inspect(value)
|
16
16
|
if value.is_a?(String) && value.length > 50
|
17
17
|
"#{value[0..50]}...".inspect
|
18
18
|
elsif value.is_a?(Date) || value.is_a?(Time)
|
@@ -4,7 +4,7 @@ module CassandraObject
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
def remove(id)
|
7
|
-
execute_cql "DELETE FROM #{column_family} WHERE KEY = ?", id
|
7
|
+
execute_cql "DELETE FROM #{column_family} #{write_option_string} WHERE KEY = ?", id
|
8
8
|
end
|
9
9
|
|
10
10
|
def delete_all
|
@@ -20,12 +20,12 @@ module CassandraObject
|
|
20
20
|
def write(id, attributes)
|
21
21
|
if (encoded = encode_attributes(attributes)).any?
|
22
22
|
insert_attributes = {'KEY' => id}.update encode_attributes(attributes)
|
23
|
-
statement = "INSERT INTO #{column_family} (#{insert_attributes.keys * ','}) VALUES (#{Array.new(insert_attributes.size, '?') * ','})"
|
23
|
+
statement = "INSERT INTO #{column_family} (#{insert_attributes.keys * ','}) VALUES (#{Array.new(insert_attributes.size, '?') * ','}) #{write_option_string}"
|
24
24
|
execute_cql statement, *insert_attributes.values
|
25
25
|
end
|
26
26
|
|
27
27
|
if (nil_attributes = attributes.select { |key, value| value.nil? }).any?
|
28
|
-
execute_cql "DELETE #{nil_attributes.keys * ','} FROM #{column_family} WHERE KEY = ?", id
|
28
|
+
execute_cql "DELETE #{nil_attributes.keys * ','} FROM #{column_family} #{write_option_string} WHERE KEY = ?", id
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -53,6 +53,14 @@ module CassandraObject
|
|
53
53
|
attributes = attributes.symbolize_keys
|
54
54
|
Hash[attribute_definitions.map { |k, attribute_definition| [k.to_s, attribute_definition.instantiate(object, attributes[k])] }]
|
55
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def write_option_string
|
59
|
+
consistency = base_class.default_consistency
|
60
|
+
if consistency
|
61
|
+
"USING CONSISTENCY #{consistency}"
|
62
|
+
end
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
def new_record?
|
@@ -35,9 +35,9 @@ module CassandraObject
|
|
35
35
|
def to_a
|
36
36
|
statement = [
|
37
37
|
"SELECT #{select_string} FROM #{klass.column_family}",
|
38
|
+
consistency_string,
|
38
39
|
where_string,
|
39
|
-
limit_string
|
40
|
-
consistency_string
|
40
|
+
limit_string
|
41
41
|
].delete_if(&:blank?) * ' '
|
42
42
|
|
43
43
|
instantiate_from_cql(statement)
|
data/test/unit/inspect_test.rb
CHANGED
@@ -8,18 +8,19 @@ class CassandraObject::InspectTest < CassandraObject::TestCase
|
|
8
8
|
integer :other
|
9
9
|
end
|
10
10
|
|
11
|
-
assert_equal "#{'x' * 51}...".inspect, object.new(
|
12
|
-
assert_equal "2012-02-14 12:01:02".inspect, object.new(
|
13
|
-
assert_equal "
|
11
|
+
assert_equal "#{'x' * 51}...".inspect, object.new.attribute_for_inspect('x' * 100)
|
12
|
+
assert_equal "2012-02-14 12:01:02".inspect, object.new.attribute_for_inspect(Time.new(2012, 02, 14, 12, 01, 02))
|
13
|
+
assert_equal "\"foo\"", object.new.attribute_for_inspect('foo')
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'inspect' do
|
17
17
|
object = temp_object do
|
18
18
|
string :description
|
19
19
|
integer :price
|
20
|
-
end.new(description: "yeah buddy", price:
|
20
|
+
end.new(description: "yeah buddy", price: nil)
|
21
21
|
|
22
22
|
assert_match /id/, object.inspect
|
23
23
|
assert_match /description/, object.inspect
|
24
|
+
assert_no_match /price/, object.inspect
|
24
25
|
end
|
25
26
|
end
|
@@ -111,4 +111,18 @@ class CassandraObject::PersistenceTest < CassandraObject::TestCase
|
|
111
111
|
persisted_issue.reload
|
112
112
|
assert_equal 'say what', persisted_issue.description
|
113
113
|
end
|
114
|
+
|
115
|
+
test 'delete with consistency' do
|
116
|
+
issue = Issue.create
|
117
|
+
Issue.with_consistency 'QUORUM' do
|
118
|
+
issue.destroy
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
test 'insert with consistency' do
|
123
|
+
Issue.with_consistency 'QUORUM' do
|
124
|
+
Issue.create
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
114
128
|
end
|
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: 4.4.
|
4
|
+
version: 4.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|