duck_record 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/duck_record/locale/en.yml +1 -0
- data/lib/duck_record/reflection.rb +4 -0
- data/lib/duck_record/validations.rb +24 -0
- data/lib/duck_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4921c51fca978e6910b1c8a0e9390b01f0d8408
|
4
|
+
data.tar.gz: 77d9a49aecd1011ca0225536bcc420cc24ac9d03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e66fdc4569a943dd53f0ba8d0d49fb9c776ea3e062b5ba1657340925f707a4689ee8c3ed0e3aead7d1c00ca9e8d16e46955a238c1b1f5a23de2d6088b752a2
|
7
|
+
data.tar.gz: 3d2bb86b4dbdc92a30596a3cafc1cb85483ad317bab5375f7e4746957173354ba542e1996af724a8f6c9ef9a74fd5bc4ba1e7ca9d4af3c0978f6be71a72a25fc
|
@@ -37,6 +37,10 @@ module DuckRecord
|
|
37
37
|
ar._reflections = ar._reflections.merge(name.to_s => reflection)
|
38
38
|
end
|
39
39
|
|
40
|
+
def has_reflection?(reflection_name)
|
41
|
+
_reflections.keys.include?(reflection_name.to_s)
|
42
|
+
end
|
43
|
+
|
40
44
|
# \Reflection enables the ability to examine the associations and aggregations of
|
41
45
|
# Active Record classes and objects. This information, for example,
|
42
46
|
# can be used in a form builder that takes an Active Record object
|
@@ -1,6 +1,22 @@
|
|
1
1
|
require "duck_record/validations/uniqueness_on_real_record"
|
2
2
|
|
3
3
|
module DuckRecord
|
4
|
+
class RecordInvalid < DuckRecordError
|
5
|
+
attr_reader :record
|
6
|
+
|
7
|
+
def initialize(record = nil)
|
8
|
+
if record
|
9
|
+
@record = record
|
10
|
+
errors = @record.errors.full_messages.join(", ")
|
11
|
+
message = I18n.t(:"#{@record.class.i18n_scope}.errors.messages.record_invalid", errors: errors, default: :"errors.messages.record_invalid")
|
12
|
+
else
|
13
|
+
message = "Record invalid"
|
14
|
+
end
|
15
|
+
|
16
|
+
super(message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
4
20
|
# = Active Record \Validations
|
5
21
|
#
|
6
22
|
# Active Record includes the majority of its validations from ActiveModel::Validations
|
@@ -27,6 +43,14 @@ module DuckRecord
|
|
27
43
|
errors.empty? && output
|
28
44
|
end
|
29
45
|
|
46
|
+
def valid!(context = nil)
|
47
|
+
if valid?(context)
|
48
|
+
true
|
49
|
+
else
|
50
|
+
raise RecordInvalid.new(self)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
30
54
|
alias_method :validate, :valid?
|
31
55
|
|
32
56
|
private
|
data/lib/duck_record/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duck_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|