enumb 0.0.2 → 0.0.3
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 +8 -8
- data/lib/Enumb/version.rb +1 -1
- data/lib/Enumb.rb +2 -2
- data/spec/unit/Enumb_spec.rb +13 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2Q4OWNmYzJiMmU4NWQ4OWYxNmY5MzI4NGVhMmFhNWIxNTcyMWZhOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWUyYTgzZDY1MjA0MTAyOTlmMjcxYmRhNGQxMTJiNjEyZmUwMDlhMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWI5YTIzODcwMGRhMDZmNDQxMjFkYjYyMTAwMWUyMDVlM2IwY2I5NmZiOTY4
|
10
|
+
NGRkMjUyMjUzMmY0NWI0ZTg3YzY1M2IyODdmNjhmNTY0NzczYzcyOTE5NTQ4
|
11
|
+
M2MxNDVjZjYxZGJiNzA1NDk2N2Q4YTNiZWFiMjViOGQzYTQ4M2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmU5Y2E1MWM5MzFiN2JmMDMwMDEwMzE2OGZhNWY2ODNkYzMzNzg3MjYxNjg0
|
14
|
+
N2UzOGY5OGZiM2FiNjQyZTVkZGIyNGM0MWE2MDgyZDBiMWJlMmQ3MzQ3YzZi
|
15
|
+
ODc1NmM0YjQ2YWU0NGVlOTRmNjY2MDc2YTZhNzAxNjlmNzFkZWI=
|
data/lib/Enumb/version.rb
CHANGED
data/lib/Enumb.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
require "enumb/version"
|
8
8
|
|
9
9
|
module Enumb
|
10
|
-
|
10
|
+
|
11
11
|
def enumerator(hash)
|
12
12
|
raise 'Parameter must be hash' unless hash.is_a?(Hash)
|
13
13
|
raise 'Multiple key/value pairs passed. Only single pair accepted.' unless hash.length == 1
|
@@ -28,7 +28,7 @@ module Enumb
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def parse(descriptor)
|
31
|
-
raise
|
31
|
+
raise 'Descriptor needs to be convertible to string' unless descriptor.respond_to?(:to_s)
|
32
32
|
self.class_variables.each do |x|
|
33
33
|
if x.to_s.downcase == '@@__enum__' + descriptor.to_s.downcase
|
34
34
|
return self.class_variable_get(x)
|
data/spec/unit/Enumb_spec.rb
CHANGED
@@ -105,7 +105,19 @@ describe 'enumb' do
|
|
105
105
|
end
|
106
106
|
expect(TestEnumDescriptor.to_descriptor('123')).to eq('Nones')
|
107
107
|
end
|
108
|
-
it 'if
|
108
|
+
it 'if parse called incorrectly, expect exception' do
|
109
|
+
class TestEnumToValue
|
110
|
+
extend Enumb
|
111
|
+
enumerator :Nones => '123'
|
112
|
+
enumerator :Somes => '456'
|
113
|
+
end
|
114
|
+
|
115
|
+
class No_to_s
|
116
|
+
undef_method :to_s
|
117
|
+
end
|
118
|
+
expect{TestEnumToValue.parse(No_to_s.new)}.to raise_error(Exception)
|
119
|
+
end
|
120
|
+
it 'if parse called correctly, should evaluate correctly' do
|
109
121
|
class TestEnumToValue
|
110
122
|
extend Enumb
|
111
123
|
enumerator :Nones => '123'
|