enumb 0.0.4 → 0.0.5

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,15 +1,15 @@
1
1
  ---
2
2
  SHA1:
3
3
  metadata.gz: !binary |-
4
- OGExMGNjZWRjMTkzZGViY2MzY2JmZTg0MDA4YTBjZTg2ZTQwNWQ5NQ==
4
+ NzIxMGQ4MTVmOWFiOWJhZGE0ZGY3MjZjMWMxODFhMmY3OGE4MzU1Yg==
5
5
  data.tar.gz: !binary |-
6
- OTU2NWM0ZTEyZTdkYzAwNWY4MTcyZDM1N2ZkYmM1MWQ5NjVlOGMyNw==
6
+ ZTQzOWIzOTU1ZDZjOWQ2OTY2MTcyMDdkNDE2MWQyNzcwOTUxNDEyZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTU5MmJjNTcyZTI1NWVlYzU4NTcwNmRkMjVjNzY5ZjNmMDkwY2Y4NWYxNGRj
10
- ODBmMWRkMGQ3ZTVjMDU4MjhmOWM5OTgyYmMwN2ZlOWY2MWE0ZTMxM2E0ZGI5
11
- Mzg1MTY0NGY5OTBmYTE2NTdmODIwNDdlMTg5ZWEzYTYwOWZlZWI=
9
+ ZDExOWViNjRkYjJhZGEyZmYwMmM2NDNlNDJhNzQ3OTQ4ZWU3Mzk4N2Q3NGE0
10
+ MDNjYzg0ZGQ2OThkODVhODZlMjY3ZGNmMDU1OTJmYjYwNTYwZjI2NTJiY2Rl
11
+ YjQ3YjMxYzA5OTNjNWYxMTdkOTkzY2FkZDNjMGM0MjUzMjdiMjE=
12
12
  data.tar.gz: !binary |-
13
- NWNkOGQ0MGJjMGEyZDdhZDhjNTM0ZTFiZGY0MmJjNjUyMDk5MWMwOGY3ZDQ4
14
- YWFlZjdiYzBmYmFmM2M3NDQwZWRiMjhjZjMwYjMxMDQ5MjczZTRjMjNiMDUx
15
- OGE0NmNlYmY5NWQxMzZhYTRmODQzYzkwNWYwZTAzZmM1Y2I2OGM=
13
+ Yjg1M2U0ZmE4YjRjZTgxNmIzYTE3M2M5MThkNDk2NjRmMzM4MmViM2I4YmNh
14
+ ZjdiY2NiMjk4NDBjMTYwNzE3ZTFmMzgzNDIwNzQ0ZDdhY2U2ZWY4Zjg4M2Fi
15
+ NzRmNjVhZDg0MjU1ODY1OTU2ODc2NmIwODFlOGUxM2EyYThmZmU=
data/enumb.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Enumb::VERSION
9
9
  spec.authors = ["Manther"]
10
10
  spec.email = ["jason.manther.young@gmail.com"]
11
- spec.description = %q{enumb helps developers create an enum like object in Ruby that closely resembles commonly found enum behavior of popular statically typed languages.}
11
+ spec.description = %q{enumb helps developers create an enum like object in Ruby that closely resembles commonly found enum behavior of other popular languages.}
12
12
  spec.summary = %q{Enum module}
13
13
  spec.homepage = "http://jasonwyoung.blogspot.com/"
14
14
  spec.license = "MIT"
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rake", "~> 0"
23
23
  end
data/lib/enumb.rb CHANGED
@@ -36,19 +36,41 @@ module Enumb
36
36
  end
37
37
  end
38
38
 
39
- def each
40
- self.class_variables.each do |e|
41
- if (e.to_s.include? '__enum__')
42
- yield(self.class_variable_get(e))
39
+ # Iterates using a block if provided, otherwise returns an array of enums
40
+ def enums(&block)
41
+ values = get_enums
42
+ if block
43
+ values.each do |v|
44
+ yield v
43
45
  end
46
+ else
47
+ values
44
48
  end
45
49
  end
46
50
 
51
+ # Returns true/false if provided enum is a part of this class
52
+ def include?(enum_)
53
+ enums.include?(enum_)
54
+ end
55
+
56
+ alias_method :each, :enums
57
+ alias_method :map, :enums
58
+
47
59
  private
60
+
48
61
  def create_class_method(name, &block)
49
62
  self.class.send(:define_method, name, &block)
50
63
  end
51
64
 
65
+ # Return enum class vars
66
+ def get_enums
67
+ # Find matching refs
68
+ v = self.class_variables.find_all { |e| e.to_s.include? '__enum__' }
69
+ # Lookup class variable from refs and return
70
+ v.map { |x| class_variable_get(x) }
71
+ end
72
+
73
+
52
74
  #decided not to limit in these ways, but;
53
75
  #if you want your enum sealed implement something similar
54
76
  #def inherited subclass
data/lib/enumb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Enumb
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -135,11 +135,72 @@ describe 'enumb' do
135
135
  end
136
136
 
137
137
  TestEnumToIterate.each do |x|
138
- expect((((TestEnumToIterate.Nones |
138
+ expect(((TestEnumToIterate.Nones |
139
139
  TestEnumToIterate.Somes |
140
140
  TestEnumToIterate.Anys |
141
- TestEnumToIterate.Each) & x) == x)).to eq(true)
141
+ TestEnumToIterate.Each) & x) == x).to eq(true)
142
142
  end
143
143
  end
144
+
145
+ describe '.include?' do
146
+
147
+ it 'returns true for an Enum that is defined' do
148
+ class TestEnumToInclude
149
+ extend Enumb
150
+ enumerator :Alpha => 1
151
+ enumerator :Beta => 2
152
+ enumerator :Charlie => 3
153
+ enumerator :Echo => 4
154
+ end
155
+ x = TestEnumToInclude.Beta
156
+
157
+ class TestEnumToNotInclude
158
+ extend Enumb
159
+ enumerator :Alpha => 5
160
+ enumerator :Beta => 6
161
+ enumerator :Charlie => 7
162
+ enumerator :Echo => 8
163
+ end
164
+ y = TestEnumToNotInclude.Beta
165
+
166
+ expect(TestEnumToInclude.include?(x)).to be_true
167
+ expect(TestEnumToInclude.include?(y)).to be_false
168
+ # Inverse check
169
+ expect(TestEnumToNotInclude.include?(x)).to be_false
170
+ expect(TestEnumToNotInclude.include?(y)).to be_true
171
+ end
172
+
173
+ end
174
+
175
+ describe '.map' do
176
+
177
+ it 'returns Array of enums' do
178
+ class TestEnumToInclude
179
+ extend Enumb
180
+ enumerator :Alpha => 1
181
+ enumerator :Beta => 2
182
+ enumerator :Charlie => 3
183
+ enumerator :Echo => 4
184
+ end
185
+ expect(TestEnumToInclude.map).to match_array [TestEnumToInclude.Alpha, TestEnumToInclude.Beta, TestEnumToInclude.Charlie, TestEnumToInclude.Echo]
186
+ end
187
+
188
+ end
189
+
190
+ describe '.enums' do
191
+
192
+ it 'returns Array of enums' do
193
+ class TestEnumToInclude
194
+ extend Enumb
195
+ enumerator :Alpha => 1
196
+ enumerator :Beta => 2
197
+ enumerator :Charlie => 3
198
+ enumerator :Echo => 4
199
+ end
200
+ expect(TestEnumToInclude.map).to match_array [TestEnumToInclude.Alpha, TestEnumToInclude.Beta, TestEnumToInclude.Charlie, TestEnumToInclude.Echo]
201
+ end
202
+
203
+ end
204
+
144
205
  end
145
206
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manther
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-19 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,17 +28,19 @@ dependencies:
28
28
  name: rake
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: !binary |-
34
+ MA==
34
35
  requirement: !ruby/object:Gem::Requirement
35
36
  requirements:
36
- - - ">="
37
+ - - "~>"
37
38
  - !ruby/object:Gem::Version
38
- version: '0'
39
+ version: !binary |-
40
+ MA==
39
41
  prerelease: false
40
42
  type: :development
41
- description: enumb helps developers create an enum like object in Ruby that closely resembles commonly found enum behavior of popular statically typed languages.
43
+ description: enumb helps developers create an enum like object in Ruby that closely resembles commonly found enum behavior of other popular languages.
42
44
  email:
43
45
  - jason.manther.young@gmail.com
44
46
  executables: []