gotime-cassandra_object 2.3.4 → 2.3.5

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/README.rdoc CHANGED
@@ -1,2 +1,44 @@
1
1
  == Cassandra Object
2
2
 
3
+ Cassandra Object uses ActiveModel to mimic much of the behavior in ActiveRecord.
4
+
5
+
6
+ == Defining Models
7
+
8
+ class Widget < CassandraObject::Base
9
+ key :uuid
10
+ attribute :name, type: :string
11
+ attribute :description, type: :string
12
+ attribute :price, type: :integer
13
+
14
+ validates :name, presence: :true
15
+
16
+ before_create do
17
+ self.description = "#{name} is the best product ever"
18
+ end
19
+ end
20
+
21
+ == Creating and updating records
22
+
23
+ Cassandra Object has equivalent methods as ActiveRecord:
24
+
25
+ widget = Widget.new
26
+ widget.valid?
27
+ widget = Widget.create(name: 'Acme', price: 100)
28
+ widget.update_attribute(:price, 1200)
29
+ widget.update_attributes(price: 1200, name: 'Acme Corporation')
30
+ widget.attributes = {price: 300}
31
+ widget.price_was
32
+ widget.save
33
+ widget.save!
34
+
35
+ == Finding records
36
+
37
+ widget = Widget.find(uuid)
38
+ widget = Widget.first
39
+ widgets = Widget.all
40
+ Widget.find_each do |widget|
41
+ ...
42
+ end
43
+
44
+ CQL is currently not supported
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '2.3.4'
5
+ s.version = '2.3.5'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -18,9 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_runtime_dependency('rails', "~> 3.0")
21
+ s.add_runtime_dependency('activemodel', "~> 3.0")
22
22
  s.add_runtime_dependency('cassandra', "~> 0.11.3")
23
23
 
24
24
  s.add_development_dependency('bundler', "~> 1.0.0")
25
- end
26
-
25
+ end
@@ -1,4 +1,5 @@
1
- require 'rails/all'
1
+ require 'active_support/all'
2
+ require 'active_model'
2
3
 
3
4
  module CassandraObject
4
5
  extend ActiveSupport::Autoload
@@ -46,4 +47,4 @@ module CassandraObject
46
47
  end
47
48
  end
48
49
 
49
- require 'cassandra_object/railtie'
50
+ require 'cassandra_object/railtie' if defined?(Rails)
@@ -4,7 +4,7 @@ module CassandraObject
4
4
 
5
5
  included do
6
6
  extend ActiveModel::Callbacks
7
- define_model_callbacks :save, :create, :destroy, :update
7
+ define_model_callbacks :save, :create, :update, :destroy
8
8
  end
9
9
 
10
10
  def destroy #:nodoc:
@@ -1,6 +1,7 @@
1
1
  module CassandraObject
2
2
  module FinderMethods
3
3
  extend ActiveSupport::Concern
4
+
4
5
  module ClassMethods
5
6
  def find(key)
6
7
  if !parse_key(key)
@@ -39,9 +40,7 @@ module CassandraObject
39
40
 
40
41
  ids = ids.compact.map(&:to_s).uniq
41
42
 
42
- results = multi_get(ids).values.compact
43
-
44
- results.size <= 1 && !expects_array ? results.first : results
43
+ multi_get(ids).values.compact
45
44
  end
46
45
 
47
46
  private
@@ -20,16 +20,6 @@ module CassandraObject
20
20
  def parse(string)
21
21
  raise NotImplementedError, "#{self.class.name}#parse isn't implemented."
22
22
  end
23
-
24
-
25
- # create should create a new key object from the cassandra format.
26
- #
27
- # @param [String] the result of calling key.to_s
28
- # @return [CassandraObject::Identity::Key] the key
29
- #
30
- def create(string)
31
- raise NotImplementedError, "#{self.class.name}#create isn't implemented."
32
- end
33
23
  end
34
24
  end
35
25
  end
@@ -36,14 +36,6 @@ module CassandraObject
36
36
  def next_key(object)
37
37
  CustomKey.new(object.send(@method))
38
38
  end
39
-
40
- def parse(paramized_key)
41
- CustomKey.new(paramized_key)
42
- end
43
-
44
- def create(paramized_key)
45
- CustomKey.new(paramized_key)
46
- end
47
39
  end
48
40
  end
49
41
  end
@@ -41,10 +41,6 @@ module CassandraObject
41
41
  def parse(paramized_key)
42
42
  NaturalKey.new(paramized_key)
43
43
  end
44
-
45
- def create(paramized_key)
46
- NaturalKey.new(paramized_key)
47
- end
48
44
  end
49
45
  end
50
46
  end
@@ -28,11 +28,6 @@ module CassandraObject
28
28
  rescue
29
29
  nil
30
30
  end
31
-
32
- # create should create a new key object from the cassandra format.
33
- def create(string)
34
- UUID.new(string)
35
- end
36
31
  end
37
32
  end
38
33
  end
@@ -13,7 +13,7 @@ module CassandraObject
13
13
 
14
14
  included do
15
15
  define_model_callbacks :validation
16
- define_callbacks :validate, :scope => :name
16
+ define_callbacks :validate, scope: :name
17
17
  end
18
18
 
19
19
  module ClassMethods
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class CassandraObject::CallbacksTest < CassandraObject::TestCase
4
+ class TestIssue < CassandraObject::Base
5
+ self.column_family = 'Issues'
6
+ key :uuid
7
+ attribute :description, type: :string
8
+
9
+ %w(after_save after_create after_update after_destroy).each do |method|
10
+ send(method) do
11
+ callback_history << method
12
+ end
13
+ end
14
+
15
+ def reset_callback_history
16
+ @callback_history = []
17
+ end
18
+
19
+ def callback_history
20
+ @callback_history ||= []
21
+ end
22
+ end
23
+
24
+ test 'create' do
25
+ issue = TestIssue.create
26
+
27
+ assert_equal ['after_create', 'after_save'], issue.callback_history
28
+ end
29
+
30
+ test 'update' do
31
+ issue = TestIssue.create
32
+ issue.reset_callback_history
33
+
34
+ issue.update_attribute :description, 'foo'
35
+
36
+ assert_equal ['after_update', 'after_save'], issue.callback_history
37
+ end
38
+
39
+ test 'destroy' do
40
+ issue = TestIssue.create
41
+ issue.reset_callback_history
42
+
43
+ issue.destroy
44
+
45
+ assert_equal ['after_destroy'], issue.callback_history
46
+ end
47
+ end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,8 @@
1
- # lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
2
- # $:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
3
- # require File.expand_path('../../lib/cassandra_object', __FILE__)
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'test/unit'
4
4
  require 'cassandra/0.8'
5
5
  require 'cassandra_object'
6
- require 'rails/test_help'
7
6
 
8
7
  class Issue < CassandraObject::Base
9
8
  key :uuid
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.3.4
4
+ version: 2.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-08-10 00:00:00.000000000Z
13
+ date: 2011-08-11 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rails
17
- requirement: &2165457380 !ruby/object:Gem::Requirement
16
+ name: activemodel
17
+ requirement: &2168989460 !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: *2165457380
25
+ version_requirements: *2168989460
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cassandra
28
- requirement: &2165456920 !ruby/object:Gem::Requirement
28
+ requirement: &2168985520 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.11.3
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2165456920
36
+ version_requirements: *2168985520
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &2165456060 !ruby/object:Gem::Requirement
39
+ requirement: &2168984360 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2165456060
47
+ version_requirements: *2168984360
48
48
  description: Cassandra ActiveModel
49
49
  email: gems@gotime.com
50
50
  executables: []
@@ -117,6 +117,7 @@ files:
117
117
  - test/attributes_test.rb
118
118
  - test/base_test.rb
119
119
  - test/batches_test.rb
120
+ - test/callbacks_test.rb
120
121
  - test/connection_test.rb
121
122
  - test/consistency_test.rb
122
123
  - test/finder_methods_test.rb
@@ -165,6 +166,7 @@ test_files:
165
166
  - test/attributes_test.rb
166
167
  - test/base_test.rb
167
168
  - test/batches_test.rb
169
+ - test/callbacks_test.rb
168
170
  - test/connection_test.rb
169
171
  - test/consistency_test.rb
170
172
  - test/finder_methods_test.rb