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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7887df2a7d513fd1089691ef8f669cfa26c335
4
- data.tar.gz: 18a3664afcdac4bd096b2d93e69ca42fcf7b52f5
3
+ metadata.gz: e4921c51fca978e6910b1c8a0e9390b01f0d8408
4
+ data.tar.gz: 77d9a49aecd1011ca0225536bcc420cc24ac9d03
5
5
  SHA512:
6
- metadata.gz: a9bb37f630dd759ed2b392f3193355623ef4990da1a575be15011cb0fe3b3d0ecc7ba52e1167cabf57f319786f00ea8de473a76cbf218cb099e2c795b2df2c70
7
- data.tar.gz: 3f09e0a8051a1181967d5e688580132cabec39280210e3031cded9044a49142c28e536c318f6c630a9d4060434bd04b656cd3f2ad4cc2cab5a7760eb79d8a484
6
+ metadata.gz: a8e66fdc4569a943dd53f0ba8d0d49fb9c776ea3e062b5ba1657340925f707a4689ee8c3ed0e3aead7d1c00ca9e8d16e46955a238c1b1f5a23de2d6088b752a2
7
+ data.tar.gz: 3d2bb86b4dbdc92a30596a3cafc1cb85483ad317bab5375f7e4746957173354ba542e1996af724a8f6c9ef9a74fd5bc4ba1e7ca9d4af3c0978f6be71a72a25fc
@@ -14,6 +14,7 @@ en:
14
14
  duck_record:
15
15
  errors:
16
16
  messages:
17
+ record_invalid: "Validation failed: %{errors}"
17
18
  # Append your own errors here or at the model/attributes scope.
18
19
 
19
20
  # You can define own errors for models or model attributes.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DuckRecord
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.22"
3
3
  end
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.21
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-01-12 00:00:00.000000000 Z
11
+ date: 2018-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport