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 +4 -4
- data/lib/activerecord/one/errors_ext.rb +9 -0
- data/lib/activerecord/one/relation_ext.rb +17 -0
- data/lib/activerecord/one.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed446965eed4c76d190fc2842c0ff9a4c798a36
|
4
|
+
data.tar.gz: 7792795980c31ac5e7d6efbc78f2d486d2be5828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c407ed20b10cf36a68ed48d5366ada7ac38998274bc6c451e4857172601fccadca336fc4b952a1a8b0b2aabb4b0ed4ab1a8927694090b0c58f9b20724ac9309
|
7
|
+
data.tar.gz: 8a360fc3f10e92a900d796106306a25eb6a1ef60d40fc0eb6e06d9275e142fc257eda3794d5002718354b8516d8eb7bfded2a4d9eeb2515fa05b789a94f2550a
|
@@ -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
|
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.
|
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
|