typesafe_enum 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +4 -4
- data/lib/typesafe_enum/base.rb +2 -1
- data/lib/typesafe_enum/module_info.rb +1 -1
- data/spec/unit/typesafe_enum/base_spec.rb +5 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d4eb09d4f1aa7e839ff17914b2b41273e5f82ef
|
4
|
+
data.tar.gz: 863e13f1b183a106aa9ad565485f2cb07ef6bac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 952de3b215c8a70054d644b82003069a12f85880d91645456b6a681f94f0d952820cf73db32e1563359d53846117c8cc12ce6864a6573d3094390a2bd98ca2ce
|
7
|
+
data.tar.gz: 0e9f424f975ad48bcbab6aaf6719082319e3a593f5372ada6eb9694b330b9679ecf9556c72c0c602e135911956857c150efcb340bfba4f34dc00ec6ec087fe2e
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.1.6 (15 Mar 2016)
|
2
|
+
|
3
|
+
- [#3](https://github.com/dmolesUC3/typesafe_enum/pull/3) - No need for `instance_eval` when creating new enum instance methods - [@dblock](https://github.com/dblock).
|
4
|
+
|
1
5
|
## 0.1.5 (27 Jan 2016)
|
2
6
|
|
3
7
|
- Include the original call site in the warning message for duplicate instances to help
|
data/README.md
CHANGED
@@ -264,16 +264,16 @@ Suit.map(&:pip)
|
|
264
264
|
|
265
265
|
## Enum instances with methods
|
266
266
|
|
267
|
-
Enum instances can declare their own methods
|
267
|
+
Enum instances can declare their own methods:
|
268
268
|
|
269
269
|
```ruby
|
270
270
|
class Operation < TypesafeEnum::Base
|
271
|
-
new(:PLUS, '+')
|
271
|
+
new(:PLUS, '+') do
|
272
272
|
def eval(x, y)
|
273
273
|
x + y
|
274
274
|
end
|
275
275
|
end
|
276
|
-
new(:MINUS, '-')
|
276
|
+
new(:MINUS, '-') do
|
277
277
|
def eval(x, y)
|
278
278
|
x - y
|
279
279
|
end
|
@@ -370,7 +370,7 @@ enum Suit {
|
|
370
370
|
}
|
371
371
|
```
|
372
372
|
|
373
|
-
With `TypesafeEnum`, instance-specific methods require extra parentheses
|
373
|
+
With `TypesafeEnum`, instance-specific methods require extra parentheses,
|
374
374
|
as shown above, and about the best you can do even for simple enums is something like:
|
375
375
|
|
376
376
|
```ruby
|
data/lib/typesafe_enum/base.rb
CHANGED
@@ -119,13 +119,14 @@ module TypesafeEnum
|
|
119
119
|
|
120
120
|
private
|
121
121
|
|
122
|
-
def initialize(key, value = nil)
|
122
|
+
def initialize(key, value = nil, &block)
|
123
123
|
fail TypeError, "#{key} is not a symbol" unless key.is_a?(Symbol)
|
124
124
|
@key = key
|
125
125
|
@value = value || key.to_s.downcase
|
126
126
|
@ord = self.class.size
|
127
127
|
self.class.class_exec(self) do |instance|
|
128
128
|
register(instance)
|
129
|
+
instance.instance_eval(&block) if block_given?
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# coding:
|
1
|
+
# coding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
class Suit < TypesafeEnum::Base
|
@@ -361,7 +361,6 @@ module TypesafeEnum
|
|
361
361
|
end
|
362
362
|
|
363
363
|
describe '::find_by_ord' do
|
364
|
-
|
365
364
|
it 'maps ordinal indices to enum instances' do
|
366
365
|
Suit.each do |s|
|
367
366
|
expect(Suit.find_by_ord(s.ord)).to be(s)
|
@@ -400,14 +399,14 @@ module TypesafeEnum
|
|
400
399
|
expect(Suit.map { |s| pip(s) }).to eq(%w(♣ ♦ ♥ ♠))
|
401
400
|
end
|
402
401
|
|
403
|
-
it 'supports "inner class" methods
|
404
|
-
class
|
405
|
-
new(:PLUS, '+')
|
402
|
+
it 'supports "inner class" methods' do
|
403
|
+
class Operation < Base
|
404
|
+
new(:PLUS, '+') do
|
406
405
|
def eval(x, y)
|
407
406
|
x + y
|
408
407
|
end
|
409
408
|
end
|
410
|
-
new(:MINUS, '-')
|
409
|
+
new(:MINUS, '-') do
|
411
410
|
def eval(x, y)
|
412
411
|
x - y
|
413
412
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typesafe_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|