sessionm-cassandra_object 2.2.54 → 2.2.55

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,11 +55,26 @@ module CassandraObject
55
55
  @key = attributes.delete(:key)
56
56
  @new_record = true
57
57
  @destroyed = false
58
+ @readonly = false
58
59
  @attributes = {}.with_indifferent_access
59
60
  self.attributes = attributes
60
61
  @schema_version = self.class.current_schema_version
61
62
  end
62
63
 
64
+ # Returns +true+ if the record is read only.
65
+ def readonly?
66
+ @readonly
67
+ end
68
+
69
+ def readonly=(value)
70
+ @readonly = value
71
+ end
72
+
73
+ # Marks this record as read only.
74
+ def readonly!
75
+ self.readonly = true
76
+ end
77
+
63
78
  def attributes
64
79
  @attributes.merge(:id => id)
65
80
  end
@@ -10,4 +10,8 @@ module CassandraObject
10
10
 
11
11
  class InvalidKey < CassandraObjectError
12
12
  end
13
+
14
+ # Raised on attempt to update record that is instantiated as read only.
15
+ class ReadOnlyRecord < CassandraObjectError
16
+ end
13
17
  end
@@ -151,6 +151,7 @@ module CassandraObject
151
151
 
152
152
  private
153
153
  def create_or_update
154
+ raise ReadOnlyRecord if readonly?
154
155
  result = new_record? ? create : update
155
156
  result != false
156
157
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '2.2.54'
5
+ s.version = '2.2.55'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -25,4 +25,19 @@ class CassandraObject::BaseTest < CassandraObject::TestCase
25
25
  issue = Issue.create
26
26
  assert_equal issue.id.hash, issue.hash
27
27
  end
28
- end
28
+
29
+ test 'readonly' do
30
+ issue = Issue.new
31
+ issue.readonly!
32
+ assert_raise CassandraObject::ReadOnlyRecord do
33
+ issue.save
34
+ end
35
+
36
+ issue = Issue.create
37
+ issue.readonly!
38
+ assert_raise CassandraObject::ReadOnlyRecord do
39
+ issue.save
40
+ end
41
+ end
42
+
43
+ end
@@ -9,7 +9,7 @@ class CassandraObject::FinderMethodsTest < CassandraObject::TestCase
9
9
  end
10
10
 
11
11
  test 'find missing record' do
12
- assert_raise CassandraObject::RecordNotFound do
12
+ assert_raise CassandraObject::InvalidKey do
13
13
  Issue.find('what')
14
14
  end
15
15
  end
@@ -46,4 +46,4 @@ class CassandraObject::FinderMethodsTest < CassandraObject::TestCase
46
46
  #
47
47
  # assert_equal created_issue, found_issue
48
48
  # end
49
- end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.54
4
+ version: 2.2.55
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-05-31 00:00:00.000000000 Z
14
+ date: 2012-08-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: 1.3.5
178
178
  requirements: []
179
179
  rubyforge_project:
180
- rubygems_version: 1.8.22
180
+ rubygems_version: 1.8.24
181
181
  signing_key:
182
182
  specification_version: 3
183
183
  summary: Cassandra ActiveModel