active_cabinet 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_cabinet/metaclass.rb +31 -1
- data/lib/active_cabinet/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b61d0603a2ee6d70ca64a73cdf0081d869190d37b7bc3ba4795f79eb69389021
|
4
|
+
data.tar.gz: fefcaba2831cdc000efbed76754714af54b71b06221bcd2818e81acf78d12c2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ff91224eabf6843fd471864fbcf235cae80970f689392ca4ee07936d5a4708489c2e3e3eec7c11407d6dee615faf341ee38196781e7989cbc731bc8c3240b85
|
7
|
+
data.tar.gz: a6ba9e9921e5b11701489d75f786a09759ad39a76dba75fcd135745305a853ff46d487016e6c640640700259b99b138a528122e2197d39a37f25c15b7f490994
|
@@ -112,9 +112,39 @@ class ActiveCabinet
|
|
112
112
|
end
|
113
113
|
alias [] find
|
114
114
|
|
115
|
+
# Yields each record to the given block.
|
116
|
+
#
|
117
|
+
# @yieldparam [Object] record all record instances.
|
118
|
+
def each
|
119
|
+
cabinet.each_value do |attributes|
|
120
|
+
yield new(attributes)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Returns the first record.
|
125
|
+
#
|
126
|
+
# @return [Object] the record.
|
127
|
+
def first
|
128
|
+
find keys.first
|
129
|
+
end
|
130
|
+
|
131
|
+
# Returns the last record.
|
132
|
+
#
|
133
|
+
# @return [Object] the record.
|
134
|
+
def last
|
135
|
+
find keys.last
|
136
|
+
end
|
137
|
+
|
138
|
+
# Returns a random racord.
|
139
|
+
#
|
140
|
+
# @return [Object] the record.
|
141
|
+
def random
|
142
|
+
find keys.sample
|
143
|
+
end
|
144
|
+
|
115
145
|
# @!group Deleting Records
|
116
146
|
|
117
|
-
# Deletes a record matching the +id
|
147
|
+
# Deletes a record matching the +id+.
|
118
148
|
#
|
119
149
|
# @param [String] id the record ID.
|
120
150
|
# @return [Boolean] +true+ on success, +false+ otherwise.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_cabinet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hash_cabinet
|