activerecord-one 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5b422bf591b3a7d4230632c406310826f001f5a
4
- data.tar.gz: 32a7349b53635c9bd15feb37c9b69a4c22647964
3
+ metadata.gz: 4ed446965eed4c76d190fc2842c0ff9a4c798a36
4
+ data.tar.gz: 7792795980c31ac5e7d6efbc78f2d486d2be5828
5
5
  SHA512:
6
- metadata.gz: 8e7346cac09e58ca8baa36d331b512a26750d7ba7448cf80627835955515b1bffb86e787db76f742d296abc5f6259fbbb41f3dd35be197f62ac69a792cccaaa4
7
- data.tar.gz: 1245392f70059c418967388413ffdd7cea3a2a389c800f90d0eaa63768ae1d11bf7663a32a12c060623f030f56e0d9842a23bfa66332e93da41d60c4f5eb7037
6
+ metadata.gz: 0c407ed20b10cf36a68ed48d5366ada7ac38998274bc6c451e4857172601fccadca336fc4b952a1a8b0b2aabb4b0ed4ab1a8927694090b0c58f9b20724ac9309
7
+ data.tar.gz: 8a360fc3f10e92a900d796106306a25eb6a1ef60d40fc0eb6e06d9275e142fc257eda3794d5002718354b8516d8eb7bfded2a4d9eeb2515fa05b789a94f2550a
@@ -0,0 +1,9 @@
1
+ module ActiveRecord
2
+ # Raised when one record is expected but none are found
3
+ class NoRecordFound < ActiveRecordError
4
+ end
5
+
6
+ # Raised when one record is expected but more than one is found
7
+ class MultipleRecordsFound < ActiveRecordError
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ class ActiveRecord::Relation
2
+ # Asserts that the collection contains exactly one record, and returns it.
3
+ #
4
+ # If the collection is empty, it raises <tt>ActiveRecord::NoRecordFound</tt>.
5
+ # If the collection contains more than one record, it raises
6
+ # <tt>ActiveRecord::MultipleRecordsFound</tt>.
7
+ def one!
8
+ case size
9
+ when 0
10
+ raise ActiveRecord::NoRecordFound
11
+ when 1
12
+ first
13
+ else
14
+ raise ActiveRecord::MultipleRecordsFound
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ require "activerecord/one/errors_ext"
2
+ require "activerecord/one/relation_ext"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-one
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddie Lebow
@@ -47,7 +47,10 @@ email:
47
47
  executables: []
48
48
  extensions: []
49
49
  extra_rdoc_files: []
50
- files: []
50
+ files:
51
+ - lib/activerecord/one.rb
52
+ - lib/activerecord/one/errors_ext.rb
53
+ - lib/activerecord/one/relation_ext.rb
51
54
  homepage: https://github.com/elebow/activerecord-one
52
55
  licenses:
53
56
  - public domain