protobuf 2.2.6 → 2.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/protobuf/enum.rb +1 -1
- data/lib/protobuf/enum_value.rb +27 -6
- data/lib/protobuf/version.rb +1 -1
- data/spec/lib/protobuf/enum_value_spec.rb +17 -0
- metadata +3 -3
data/lib/protobuf/enum.rb
CHANGED
data/lib/protobuf/enum_value.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
require 'protobuf/enum'
|
2
2
|
|
3
|
+
##
|
4
|
+
# Adding extension to Numeric until
|
5
|
+
# we can get people to stop calling #value
|
6
|
+
# on EnumValue
|
7
|
+
class Numeric
|
8
|
+
unless method_defined?(:value)
|
9
|
+
def value
|
10
|
+
self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
module Protobuf
|
4
16
|
class EnumValue
|
5
17
|
include Comparable
|
6
18
|
|
7
|
-
attr_reader :parent_class, :name
|
19
|
+
attr_reader :parent_class, :name
|
8
20
|
|
9
21
|
##
|
10
22
|
# Constructor
|
@@ -21,7 +33,7 @@ module Protobuf
|
|
21
33
|
def <=>(compared_value)
|
22
34
|
case compared_value
|
23
35
|
when ::Protobuf::EnumValue then
|
24
|
-
value <=> compared_value.
|
36
|
+
value <=> compared_value.to_i
|
25
37
|
when Numeric then
|
26
38
|
value <=> compared_value.to_i
|
27
39
|
end
|
@@ -36,10 +48,6 @@ module Protobuf
|
|
36
48
|
"\#<Protobuf::EnumValue #{@parent_class}::#{@name}=#{@value}>"
|
37
49
|
end
|
38
50
|
|
39
|
-
def to_hash_value
|
40
|
-
self.to_i
|
41
|
-
end
|
42
|
-
|
43
51
|
def to_i
|
44
52
|
@value
|
45
53
|
end
|
@@ -58,6 +66,19 @@ module Protobuf
|
|
58
66
|
self.to_i.to_s
|
59
67
|
end
|
60
68
|
end
|
69
|
+
|
70
|
+
def value
|
71
|
+
if ::Protobuf.print_deprecation_warnings?
|
72
|
+
$stderr.puts("[WARNING] Calling #value on an EnumValue is deprecated and no longer needed.")
|
73
|
+
end
|
74
|
+
|
75
|
+
@value
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Instance Aliases
|
80
|
+
#
|
81
|
+
alias_method :to_hash_value, :to_i
|
61
82
|
end
|
62
83
|
end
|
63
84
|
|
data/lib/protobuf/version.rb
CHANGED
@@ -2,6 +2,15 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Protobuf::EnumValue do
|
4
4
|
|
5
|
+
def capture_stderr(&required_block)
|
6
|
+
real_stderr = $stderr
|
7
|
+
$stderr = StringIO.new
|
8
|
+
yield
|
9
|
+
$stderr.string
|
10
|
+
ensure
|
11
|
+
$stderr = real_stderr
|
12
|
+
end
|
13
|
+
|
5
14
|
subject { Test::EnumTestType::ONE }
|
6
15
|
its(:class) { should eq(Fixnum) }
|
7
16
|
its(:parent_class) { should eq(Test::EnumTestType) }
|
@@ -16,4 +25,12 @@ describe Protobuf::EnumValue do
|
|
16
25
|
array = [0, 1, 2, 3]
|
17
26
|
array[::Test::EnumTestType::ONE].should eq(1)
|
18
27
|
end
|
28
|
+
|
29
|
+
it "prints a Warning to $stderr when #value is called" do
|
30
|
+
local_warning = capture_stderr do
|
31
|
+
::Test::EnumTestType::ONE.value
|
32
|
+
end
|
33
|
+
|
34
|
+
local_warning.should match(/deprecated/i)
|
35
|
+
end
|
19
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -501,7 +501,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
501
501
|
version: '0'
|
502
502
|
segments:
|
503
503
|
- 0
|
504
|
-
hash:
|
504
|
+
hash: 2356396609957916175
|
505
505
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
506
506
|
none: false
|
507
507
|
requirements:
|
@@ -510,7 +510,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
510
510
|
version: '0'
|
511
511
|
segments:
|
512
512
|
- 0
|
513
|
-
hash:
|
513
|
+
hash: 2356396609957916175
|
514
514
|
requirements: []
|
515
515
|
rubyforge_project:
|
516
516
|
rubygems_version: 1.8.24
|