couchbase-orm 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/couchbase-orm/base.rb +11 -7
- data/lib/couchbase-orm/persistence.rb +4 -4
- data/lib/couchbase-orm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6180a380880e394f4d1708aa67048db9adcfb18a
|
4
|
+
data.tar.gz: 028684cab7ef06b41a5aecbfc56b29826fa85230
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1302271d05d4302ec5c5a27c4d408d2c746fc3074b999e38533e0d9f3bc6fdd423ae30be0f84b4c36012b593a41a504960b2000a95929c5d18591f6a7a60d131
|
7
|
+
data.tar.gz: 19f91c2fa122d7a212f2364c0b614af39b11ecba3ba5bcea1b361609fe88c265927a0c619bdd9ef13d24403fb78dfc803f3ea5bc37f52fe074d576ff98de4b16
|
data/lib/couchbase-orm/base.rb
CHANGED
@@ -20,7 +20,7 @@ module CouchbaseOrm
|
|
20
20
|
include ::ActiveModel::Dirty
|
21
21
|
include ::ActiveModel::Serializers::JSON
|
22
22
|
|
23
|
-
|
23
|
+
include ::ActiveModel::Validations
|
24
24
|
include ::ActiveModel::Validations::Callbacks
|
25
25
|
define_model_callbacks :initialize, :only => :after
|
26
26
|
define_model_callbacks :create, :destroy, :save, :update
|
@@ -71,15 +71,19 @@ module CouchbaseOrm
|
|
71
71
|
name = name.to_sym
|
72
72
|
|
73
73
|
@attributes[name] = options
|
74
|
-
next if self.instance_methods.include?(name)
|
75
74
|
|
76
|
-
|
77
|
-
|
75
|
+
unless self.instance_methods.include?(name)
|
76
|
+
define_method(name) do
|
77
|
+
read_attribute(name)
|
78
|
+
end
|
78
79
|
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
eq_meth = :"#{name}="
|
82
|
+
unless self.instance_methods.include?(eq_meth)
|
83
|
+
define_method(eq_meth) do |value|
|
84
|
+
value = yield(value) if block_given?
|
85
|
+
write_attribute(name, value)
|
86
|
+
end
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
@@ -187,7 +187,7 @@ module CouchbaseOrm
|
|
187
187
|
|
188
188
|
|
189
189
|
def _update_record(with_cas: false, **options)
|
190
|
-
return false unless perform_validations(options)
|
190
|
+
return false unless perform_validations(:update, options)
|
191
191
|
return true unless changed?
|
192
192
|
|
193
193
|
run_callbacks :update do
|
@@ -211,7 +211,7 @@ module CouchbaseOrm
|
|
211
211
|
end
|
212
212
|
|
213
213
|
def _create_record(**options)
|
214
|
-
return false unless perform_validations(options)
|
214
|
+
return false unless perform_validations(:create, options)
|
215
215
|
|
216
216
|
run_callbacks :create do
|
217
217
|
run_callbacks :save do
|
@@ -232,8 +232,8 @@ module CouchbaseOrm
|
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
|
-
def perform_validations(options = {})
|
236
|
-
return valid? if options[:validate] != false
|
235
|
+
def perform_validations(context, options = {})
|
236
|
+
return valid?(context) if options[:validate] != false
|
237
237
|
true
|
238
238
|
end
|
239
239
|
end
|