abstractivator 0.0.28 → 0.0.29

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb01795d640d7c7f0d8a422cbe77e0e6f9ce262e
4
- data.tar.gz: 953bf0c7d6d6fd18e800b7fd22780e5b22f6217a
3
+ metadata.gz: 348cdacd93250cedbb2e44760733ff5662432374
4
+ data.tar.gz: eca9b1d0b3d908d82859e4842d2f709b263010f4
5
5
  SHA512:
6
- metadata.gz: 0abda16e780a4dc57ddf5873b5a36e09d379b8e14c55e14ff081ba2d00de717fd03e57afc0bd3f90bf7d56202cb43a9551a6fd095a6e9f7c430f6f28345ba224
7
- data.tar.gz: 022371561b2071ffbe820b25bc3cebddf3c12c169fe391094bb1f8e9c11410fba7fe82ecf225fec010e174054e1ad27a58c4f8fadeea27a2c9c848432544db51
6
+ metadata.gz: 814f84087892a9570caaeeb0158b964d6ff863281ffeb5a4e3ae3fc6dbbc5db0ea1706667fcad7275bea13efec1e1bc917c5fbeac47b143b348c0cf21ba851ab
7
+ data.tar.gz: 31f49dfb24f94e2736227a3c65265a464e0eeac8398e5f1c189559f3a1a605f1e8df978e0337cc5941db5fd0da49c695a20883680e134290c90053ac8ddd9932
@@ -8,6 +8,8 @@ module Enum
8
8
  # base.extend Dsl
9
9
  end
10
10
 
11
+ module Value; end # used to mark enum values
12
+
11
13
  module ClassMethods
12
14
  def values
13
15
  self.constants.map{|sym| self.const_get(sym)}.reject{|x| x.is_a?(Class) || x.is_a?(Module)}
@@ -22,7 +24,11 @@ module Enum
22
24
  end
23
25
 
24
26
  def from(x)
25
- values.find{|v| v.value == x}
27
+ if x.is_a?(Enum::Value)
28
+ x
29
+ else
30
+ values.find{|v| v.value == x}
31
+ end
26
32
  end
27
33
 
28
34
  private
@@ -53,6 +59,7 @@ def make_enum(*fields)
53
59
  value_class =
54
60
  const_set(:Value,
55
61
  Class.new do
62
+ include Enum::Value
56
63
  attr_reader :enum_type, :value
57
64
  define_method(:initialize) do |enum_type, value|
58
65
  @enum_type, @value = enum_type, value
@@ -1,3 +1,3 @@
1
1
  module Abstractivator
2
- VERSION = '0.0.28'
2
+ VERSION = '0.0.29'
3
3
  end
@@ -42,6 +42,9 @@ describe Enum do
42
42
  result = Container::Fruits.from(x)
43
43
  expect(result).to eql Container::Fruits::APPLE
44
44
  end
45
+ it 'works if the value is already typed' do
46
+ expect(Container::Fruits.from(Container::Fruits::APPLE)).to eql Container::Fruits::APPLE
47
+ end
45
48
  end
46
49
  end
47
50
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abstractivator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Winton