yinum 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +6 -1
- data/lib/enum/enum_value.rb +11 -9
- data/lib/enum/version.rb +1 -1
- data/spec/lib/enum/enum_value_spec.rb +8 -0
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f981118e63240ce752016306f552b599ed1c75
|
4
|
+
data.tar.gz: 5d3452a2d2417ab36550d5bc624410c690da840c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 836af7a5e9d795160e14bb0b312e6335f241d2568f35cf64165abc566b6635467f289b3578b720684cb704fce8bd9c17a46f60f2914017d2632369ba88e01ef5
|
7
|
+
data.tar.gz: 6b52268a70a4c68a3a8cb4d1c14ddf194aee6d0bbcb1b0c56caa1d368f17bfa0b62ff3882df4add8ee53bc2e1ddf64b7f2617586d52529dde7d505b9438cf46c
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -274,7 +274,12 @@ Car.where(:color => Car::COLORS.red) # good
|
|
274
274
|
```
|
275
275
|
|
276
276
|
You may use the EnumValue object for anything, but don't get smart using the key.
|
277
|
-
|
277
|
+
|
278
|
+
If the EnumValue proxy doesn't work in a specific situation (when the gem is not following the [duck typing](http://en.wikipedia.org/wiki/Duck_typing) rules), you can use `#value` (in `update_all` or `validates_uniqueness_of`):
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
Car.update_all(:color => Car::COLORS.red.value)
|
282
|
+
```
|
278
283
|
|
279
284
|
## Also
|
280
285
|
|
data/lib/enum/enum_value.rb
CHANGED
@@ -9,6 +9,8 @@ class Enum::EnumValue < BasicObject
|
|
9
9
|
|
10
10
|
def initialize(enum, name = nil, value)
|
11
11
|
@enum, @name, @value = enum, name, value
|
12
|
+
@name_s = @name.to_s if @name
|
13
|
+
@value_s = @value.to_s
|
12
14
|
end
|
13
15
|
|
14
16
|
def enum_value?
|
@@ -18,26 +20,26 @@ class Enum::EnumValue < BasicObject
|
|
18
20
|
def inspect
|
19
21
|
return @value.inspect if @name.nil?
|
20
22
|
|
21
|
-
"#{@enum.to_s}.#{@
|
23
|
+
"#{@enum.to_s}.#{@name_s}"
|
22
24
|
end
|
23
25
|
|
24
26
|
def ==(other)
|
25
|
-
return @value == other
|
27
|
+
return true if @value == other or @value_s == other
|
26
28
|
|
27
|
-
@name == other or @
|
29
|
+
not @name.nil? and (@name == other or @name_s == other)
|
28
30
|
end
|
29
31
|
|
30
32
|
def ===(other)
|
31
|
-
return @value === other
|
33
|
+
return true if @value === other or @value_s === other
|
32
34
|
|
33
|
-
@name === other or @
|
35
|
+
not @name.nil? and (@name === other or @name_s === other)
|
34
36
|
end
|
35
37
|
|
36
38
|
def t(options = {})
|
37
39
|
return @value.t(options) if @name.nil?
|
38
40
|
if not defined?(::I18n)
|
39
|
-
if @
|
40
|
-
return @
|
41
|
+
if @name_s.respond_to?(:titleize)
|
42
|
+
return @name_s.titleize
|
41
43
|
else
|
42
44
|
raise NotImplementedError, "I18n and String#titleize are not available"
|
43
45
|
end
|
@@ -57,7 +59,7 @@ class Enum::EnumValue < BasicObject
|
|
57
59
|
# but if not, use without
|
58
60
|
{ scope: scope_without_klass,
|
59
61
|
# but! if not, return titleize or scope with klass error
|
60
|
-
default: @
|
62
|
+
default: @name_s.respond_to?(:titleize) ? @name_s.titleize : ::I18n.t(
|
61
63
|
@name,
|
62
64
|
{ scope: scope_with_klass
|
63
65
|
}.merge(options)
|
@@ -70,7 +72,7 @@ class Enum::EnumValue < BasicObject
|
|
70
72
|
::I18n.t(
|
71
73
|
@name,
|
72
74
|
{ scope: scope_without_klass,
|
73
|
-
default: (@
|
75
|
+
default: (@name_s.titleize if @name_s.respond_to?(:titleize))
|
74
76
|
}.merge(options)
|
75
77
|
)
|
76
78
|
end
|
data/lib/enum/version.rb
CHANGED
@@ -25,13 +25,21 @@ describe Enum::EnumValue do
|
|
25
25
|
subject(:enum) { Enum.new(:MY_COLORS, :red => 1, :blue => 2) }
|
26
26
|
|
27
27
|
its(:red) { should == 1 }
|
28
|
+
its(:red) { should == '1' }
|
28
29
|
its(:blue) { should_not == 1 }
|
30
|
+
its(:blue) { should_not == '1' }
|
29
31
|
its(:red) { should == :red }
|
32
|
+
its(:red) { should == 'red' }
|
30
33
|
its(:blue) { should_not == :red }
|
34
|
+
its(:blue) { should_not == 'red' }
|
31
35
|
its(:red) { should === 1 }
|
36
|
+
its(:red) { should === '1' }
|
32
37
|
its(:blue) { should_not === 1 }
|
38
|
+
its(:blue) { should_not === '1' }
|
33
39
|
its(:red) { should === :red }
|
40
|
+
its(:red) { should === 'red' }
|
34
41
|
its(:blue) { should_not === :red }
|
42
|
+
its(:blue) { should_not === 'red' }
|
35
43
|
its(:red) { should be_red }
|
36
44
|
its(:blue) { should_not be_red }
|
37
45
|
specify { enum.red.object_id.should == enum[:red].object_id }
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yinum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oded Niv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: generate_method
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: nil_or
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.0'
|
55
55
|
description: Yummy implementation of enum that gives integer values with a special
|
@@ -60,8 +60,8 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .gitignore
|
64
|
-
- .rspec
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
65
|
- CHANGELOG.md
|
66
66
|
- Gemfile
|
67
67
|
- Gemfile.lock
|
@@ -94,12 +94,12 @@ require_paths:
|
|
94
94
|
- lib
|
95
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|