couchbase-model 0.3.1 → 0.4.0
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/HISTORY.markdown +5 -0
- data/lib/couchbase-model.rb +1 -0
- data/lib/couchbase/model.rb +14 -1
- data/lib/couchbase/model/version.rb +1 -1
- metadata +2 -2
data/HISTORY.markdown
CHANGED
data/lib/couchbase-model.rb
CHANGED
data/lib/couchbase/model.rb
CHANGED
@@ -37,6 +37,15 @@ module Couchbase
|
|
37
37
|
# @since 0.0.1
|
38
38
|
class Error::MissingId < Error::Base; end
|
39
39
|
|
40
|
+
# @since 0.4.0
|
41
|
+
class Error::RecordInvalid < Error::Base
|
42
|
+
attr_reader :record
|
43
|
+
def initialize(record)
|
44
|
+
@record = record
|
45
|
+
super(@record.errors.full_messages.join(", "))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
40
49
|
# Declarative layer for Couchbase gem
|
41
50
|
#
|
42
51
|
# @since 0.0.1
|
@@ -414,6 +423,7 @@ module Couchbase
|
|
414
423
|
#
|
415
424
|
# @param [Hash] attrs attribute-value pairs
|
416
425
|
def initialize(attrs = {})
|
426
|
+
@errors = ::ActiveModel::Errors.new(self) if defined?(::ActiveModel)
|
417
427
|
case attrs
|
418
428
|
when Hash, HashWithIndifferentAccess
|
419
429
|
if attrs.respond_to?(:with_indifferent_access)
|
@@ -469,7 +479,10 @@ module Couchbase
|
|
469
479
|
# p.draft = false
|
470
480
|
# p.save
|
471
481
|
def save(cas = nil)
|
472
|
-
|
482
|
+
if respond_to?(:valid?) && !valid?
|
483
|
+
raise Couchbase::Error::RecordInvalid.new(self)
|
484
|
+
end
|
485
|
+
return create unless meta
|
473
486
|
value = @_raw ? @_raw : attributes_with_values
|
474
487
|
model.bucket.replace(@id, value, model.default.merge(:cas => cas))
|
475
488
|
self
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchbase-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: couchbase
|