yinum 1.7.0 → 1.7.1
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +1 -1
- data/lib/enum/enum_value.rb +8 -12
- data/lib/enum/helpers/enum_attribute.rb +9 -1
- data/lib/enum/version.rb +1 -1
- data/spec/lib/enum/enum_value_spec.rb +8 -2
- data/spec/lib/enum/helpers/enum_attribute_spec.rb +5 -2
- data/spec/lib/enum/helpers/enum_column_spec.rb +4 -2
- 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: 46b4c4c4f5f5cce627f88c4c19607cc77bd23095
|
4
|
+
data.tar.gz: db4d64a617533347040e9b0176fc968b95486f64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46d4bd89347488975200454f7000cdd61459acf21ede9f1c1ee07858fb4437fdd9cfd032db08f9bc8680f0edb858f97b225b926b48acafccb0ee63289c5bcd25
|
7
|
+
data.tar.gz: e8c496f34c5b983a5cea385eb1ad162e2b0ebf719540de12ffd481d24a10030c493c06aca5ee00e15176e0fd13992ed8c9bc15676c2aba526fbbfb68d8f99848
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
**1.7.0**
|
1
2
|
* `attr_enum` reader always returns an EnumValue.
|
2
3
|
* `EnumValue#t` uses `String#titlelize` if it's available and I18n or the
|
3
|
-
specific translation are not available.
|
4
|
+
specific translation are not available.
|
5
|
+
|
6
|
+
**1.7.1**
|
7
|
+
* Remove usage of `reverse_merge`, apparently doesn't exist in Ruby core.
|
8
|
+
* `attr_enum`'s writer does not pass an EnumValue to the super.
|
9
|
+
* Fix `EnumValue#t` specs (mocking `I18n`).
|
data/Gemfile.lock
CHANGED
data/lib/enum/enum_value.rb
CHANGED
@@ -44,32 +44,28 @@ class Enum::EnumValue < BasicObject
|
|
44
44
|
::I18n.t(
|
45
45
|
@name,
|
46
46
|
# prefer scope with klass
|
47
|
-
|
48
|
-
|
49
|
-
).merge( # our :default is a priority here
|
47
|
+
{ scope: scope_with_klass
|
48
|
+
}.merge(options).merge( # our :default is a priority here
|
50
49
|
default: ::I18n.t(
|
51
50
|
@name,
|
52
51
|
# but if not, use without
|
53
|
-
|
54
|
-
scope: scope_without_klass,
|
52
|
+
{ scope: scope_without_klass,
|
55
53
|
# but! if not, return titleize or scope with klass error
|
56
54
|
default: @name.to_s.respond_to?(:titleize) ? @name.to_s.titleize : ::I18n.t(
|
57
55
|
@name,
|
58
|
-
|
59
|
-
|
60
|
-
)
|
56
|
+
{ scope: scope_with_klass
|
57
|
+
}.merge(options)
|
61
58
|
)
|
62
|
-
)
|
59
|
+
}.merge(options)
|
63
60
|
)
|
64
61
|
)
|
65
62
|
)
|
66
63
|
else
|
67
64
|
::I18n.t(
|
68
65
|
@name,
|
69
|
-
|
70
|
-
scope: scope_without_klass,
|
66
|
+
{ scope: scope_without_klass,
|
71
67
|
default: (@name.to_s.titleize if @name.to_s.respond_to?(:titleize))
|
72
|
-
)
|
68
|
+
}.merge(options)
|
73
69
|
)
|
74
70
|
end
|
75
71
|
end
|
@@ -21,7 +21,15 @@ module Enum::Helpers::EnumAttribute
|
|
21
21
|
# attribute reader
|
22
22
|
define_method(attr) { v = super(); (v.nil? or not e.values.include?(v)) ? Enum::EnumValue.new(e, v) : e[v] }
|
23
23
|
# attribute writer
|
24
|
-
define_method("#{attr}=")
|
24
|
+
define_method("#{attr}=") do |v|
|
25
|
+
if v.respond_to?(:enum_value?) and v.enum_value?
|
26
|
+
super(v.value)
|
27
|
+
elsif v.nil?
|
28
|
+
super(v)
|
29
|
+
else
|
30
|
+
super(e[v].value)
|
31
|
+
end
|
32
|
+
end
|
25
33
|
|
26
34
|
if options[:qualifier]
|
27
35
|
# generating scopes and questioning methods
|
data/lib/enum/version.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class I18n
|
4
|
+
def self.t(path, scope: nil, default: nil)
|
5
|
+
"#{scope}.#{path}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
describe Enum::EnumValue do
|
4
10
|
subject { @enum }
|
5
11
|
|
@@ -8,7 +14,7 @@ describe Enum::EnumValue do
|
|
8
14
|
# can't use subject @enum.red as it turns into a Fixnum
|
9
15
|
|
10
16
|
specify { @enum.red.inspect.should == "MY_COLORS.red" }
|
11
|
-
specify { @enum.red.t.should == "
|
17
|
+
specify { @enum.red.t.should == "enums.my_colors.red" }
|
12
18
|
end # context "no parent"
|
13
19
|
|
14
20
|
context "with parent" do
|
@@ -16,7 +22,7 @@ describe Enum::EnumValue do
|
|
16
22
|
# can't use subject @enum.red as it turns into a Fixnum
|
17
23
|
|
18
24
|
specify { @enum.red.inspect.should == "Object::MY_COLORS.red" }
|
19
|
-
specify { @enum.red.t.should == "
|
25
|
+
specify { @enum.red.t.should == "enums.object.my_colors.red" }
|
20
26
|
end # context "with parent"
|
21
27
|
|
22
28
|
context "comparison" do
|
@@ -51,16 +51,19 @@ def enum_attribute_specs
|
|
51
51
|
specify "nil" do
|
52
52
|
@record.color = nil
|
53
53
|
@record[:color].should be_nil
|
54
|
+
@record[:color].should_not respond_to(:enum_value?)
|
54
55
|
end
|
55
56
|
|
56
57
|
specify "name" do
|
57
58
|
@record.color = :red
|
58
|
-
@record[:color]
|
59
|
+
@record[:color] == 1
|
60
|
+
@record[:color].should_not respond_to(:enum_value?)
|
59
61
|
end
|
60
62
|
|
61
63
|
specify "value" do
|
62
64
|
@record.color = 2
|
63
|
-
@record[:color]
|
65
|
+
@record[:color] == 2
|
66
|
+
@record[:color].should_not respond_to(:enum_value?)
|
64
67
|
end
|
65
68
|
|
66
69
|
specify "invalid" do
|
@@ -75,12 +75,14 @@ def enum_columns_attribute_specs
|
|
75
75
|
|
76
76
|
specify "name" do
|
77
77
|
@record.color = :red
|
78
|
-
@record[:color].should
|
78
|
+
@record[:color].should == 1
|
79
|
+
@record[:color].should_not respond_to(:enum_value?)
|
79
80
|
end
|
80
81
|
|
81
82
|
specify "value" do
|
82
83
|
@record.color = 2
|
83
|
-
@record[:color].should
|
84
|
+
@record[:color].should == 2
|
85
|
+
@record[:color].should_not respond_to(:enum_value?)
|
84
86
|
end
|
85
87
|
|
86
88
|
specify "invalid" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yinum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oded Niv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|