yinum 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6c73933a509d17c611e833780d494509c743d76
4
- data.tar.gz: 08cbfb277952c6542c39b1dc5ebe9e9e331f2682
3
+ metadata.gz: 46b4c4c4f5f5cce627f88c4c19607cc77bd23095
4
+ data.tar.gz: db4d64a617533347040e9b0176fc968b95486f64
5
5
  SHA512:
6
- metadata.gz: 6e2e98a5b4b03df21652b9539da8e29e7a7661fde7df110d155172ef4c05bad87a3e8de61ae042490487139bee7b6a2e46252ddd1739d3cf51ec6a54a568dff1
7
- data.tar.gz: 467a1640a733bdef9a958c1c8b452cfbe50af55cd913395af3bccceade2b6111ab3eab2224d56cd141eebb6ca389ead9d05b3be52d601082c6e28e1e1ed21766
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yinum (1.6.0)
4
+ yinum (1.7.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -44,32 +44,28 @@ class Enum::EnumValue < BasicObject
44
44
  ::I18n.t(
45
45
  @name,
46
46
  # prefer scope with klass
47
- options.reverse_merge(
48
- scope: scope_with_klass
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
- options.reverse_merge(
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
- options.reverse_merge(
59
- scope: scope_with_klass
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
- options.reverse_merge(
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}=") { |v| v.nil? ? super(v) : super(e[v]) }
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,3 +1,3 @@
1
1
  class Enum
2
- VERSION = '1.7.0'
2
+ VERSION = '1.7.1'
3
3
  end
@@ -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 == "I18n not available: enums.my_colors.red" }
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 == "I18n not available: enums.object.my_colors.red" }
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].should be_enum_value and @record[:color].should be_red
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].should be_enum_value and @record[:color].should be_blue
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 be_enum_value and @record[:color].should be_red
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 be_enum_value and @record[:color].should be_blue
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.0
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-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec