collection_of 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/collection_of/collection.rb +10 -0
- data/lib/collection_of/version.rb +1 -1
- data/spec/collection_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjM0ZDM1ZDIyZWFhZmNiNjJkOTNmYjAwMjlhOGQwNGYzOTdkZmY5Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWIwZmU4YjQ5NjMyYWY1YWExMTQ3ZTExMzAxYmU0YzEzYzg2OWQ2OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWE5NDc3MTlmZjcwZTA4NDFmYzlkNjUwN2YyNzU0MDgxYWU1MjhmZmYyODFj
|
10
|
+
ZTU0N2RlZjc2Y2RlYTg3NDJmNWVlYzkxZTRlMWNjODdmYmUzZmJjYmVmODA2
|
11
|
+
N2I0MjA0MmVlNzZlMmI1YWE3OGUwYTYyM2MyNDA2NzlkY2RlYTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmE3NDg4N2U2NmU2Y2E4ZDU1YzA1YzhmNDExMjU4Mzk5YTQ0OTE3YTgzMGE0
|
14
|
+
MTdmOGE0MDQ3YTEwNjhjMjlhZDVlY2Q1OWE2NTNlNDUxNmJiZTdlYjhiYzAx
|
15
|
+
N2U1MTE3OWEyM2EzMDRmMWY0NjdlY2RiYmE1M2U0YjJjOTk5NDM=
|
@@ -51,6 +51,16 @@ class Collection
|
|
51
51
|
@collection << obj
|
52
52
|
end
|
53
53
|
|
54
|
+
def keys
|
55
|
+
@collection.map{ |i| i.name.to_sym }
|
56
|
+
end
|
57
|
+
|
58
|
+
def include?(item)
|
59
|
+
return true if @collection.include?(item)
|
60
|
+
return keys.include?(item.to_sym) if item.respond_to?(:to_sym)
|
61
|
+
return false
|
62
|
+
end
|
63
|
+
|
54
64
|
def except(*items)
|
55
65
|
items.map!(&:to_sym)
|
56
66
|
self.class.new(klass, reject{ |i| items.include?(i.name.to_sym) })
|
data/spec/collection_spec.rb
CHANGED
@@ -143,6 +143,28 @@ describe Collection do
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
+
describe "#keys" do
|
147
|
+
let(:w1) { Widget.new(:one) }
|
148
|
+
let(:w2) { Widget.new(:two) }
|
149
|
+
subject { described_class[Widget] }
|
150
|
+
|
151
|
+
before { subject << w1 << w2 }
|
152
|
+
|
153
|
+
its(:keys) { should == [:one, :two] }
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "#include?" do
|
157
|
+
let(:w1) { Widget.new(:one) }
|
158
|
+
let(:w2) { Widget.new(:one) }
|
159
|
+
subject { described_class[Widget] }
|
160
|
+
before { subject << w1 }
|
161
|
+
|
162
|
+
it { should include w1 }
|
163
|
+
it { should include :one }
|
164
|
+
it { should_not include w2 }
|
165
|
+
it { should_not include :two }
|
166
|
+
end
|
167
|
+
|
146
168
|
describe "#except" do
|
147
169
|
let(:c) { described_class[Widget] }
|
148
170
|
let(:w1) { Widget.new(:one) }
|