gotime-cassandra_object 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '3.0.3'
5
+ s.version = '3.0.4'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
  s.authors = ["Michael Koziarski", "gotime"]
@@ -3,18 +3,16 @@ module CassandraObject
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def find(id)
7
- if id.blank?
8
- raise CassandraObject::RecordNotFound, "Couldn't find #{self.name} with key #{id.inspect}"
9
- elsif attributes = connection.get(column_family, id, {:count => 500}).presence
10
- instantiate(id, attributes)
6
+ def find(ids)
7
+ if ids.is_a?(Array)
8
+ find_some(ids)
11
9
  else
12
- raise CassandraObject::RecordNotFound
10
+ find_one(ids)
13
11
  end
14
12
  end
15
13
 
16
- def find_by_id(id)
17
- find(id)
14
+ def find_by_id(ids)
15
+ find(ids)
18
16
  rescue CassandraObject::RecordNotFound
19
17
  nil
20
18
  end
@@ -34,7 +32,23 @@ module CassandraObject
34
32
  all(options.merge(limit: 1)).first
35
33
  end
36
34
 
37
- def find_with_ids(*ids)
35
+ def count
36
+ connection.count_range(column_family)
37
+ end
38
+
39
+ private
40
+
41
+ def find_one(id)
42
+ if id.blank?
43
+ raise CassandraObject::RecordNotFound, "Couldn't find #{self.name} with key #{id.inspect}"
44
+ elsif attributes = connection.get(column_family, id, {:count => 500}).presence
45
+ instantiate(id, attributes)
46
+ else
47
+ raise CassandraObject::RecordNotFound
48
+ end
49
+ end
50
+
51
+ def find_some(ids)
38
52
  ids = ids.flatten
39
53
  return ids if ids.empty?
40
54
 
@@ -43,10 +57,6 @@ module CassandraObject
43
57
  multi_get(ids).values.compact
44
58
  end
45
59
 
46
- def count
47
- connection.count_range(column_family)
48
- end
49
-
50
60
  def multi_get(keys, options={})
51
61
  attribute_results = ActiveSupport::Notifications.instrument("multi_get.cassandra_object", column_family: column_family, keys: keys) do
52
62
  connection.multi_get(column_family, keys.map(&:to_s), consistency: thrift_read_consistency, count: 500)
@@ -18,6 +18,15 @@ class CassandraObject::FinderMethodsTest < CassandraObject::TestCase
18
18
  end
19
19
  end
20
20
 
21
+ test 'find with ids' do
22
+ first_issue = Issue.create
23
+ second_issue = Issue.create
24
+ third_issue = Issue.create
25
+
26
+ assert_equal [], Issue.find([])
27
+ assert_equal [first_issue, second_issue], Issue.find([first_issue.id, second_issue.id])
28
+ end
29
+
21
30
  test 'find_by_id' do
22
31
  Issue.create.tap do |issue|
23
32
  assert_equal issue, Issue.find_by_id(issue.id)
@@ -39,14 +48,4 @@ class CassandraObject::FinderMethodsTest < CassandraObject::TestCase
39
48
 
40
49
  assert [first_issue, second_issue].include?(Issue.first)
41
50
  end
42
-
43
- test 'find_with_ids' do
44
- first_issue = Issue.create
45
- second_issue = Issue.create
46
- third_issue = Issue.create
47
-
48
- assert_equal [], Issue.find_with_ids([])
49
- assert_equal [first_issue, second_issue].to_set, Issue.find_with_ids(first_issue.id, second_issue.id).to_set
50
- assert_equal [first_issue, second_issue].to_set, Issue.find_with_ids([first_issue.id, second_issue.id]).to_set
51
- end
52
51
  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: 3.0.3
4
+ version: 3.0.4
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-07-09 00:00:00.000000000 Z
13
+ date: 2012-07-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel