protobuf 2.5.4-java → 2.5.5-java

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.
@@ -56,6 +56,22 @@ module Protobuf
56
56
  end
57
57
  end
58
58
 
59
+ # Re-implement `try` in order to fix the problem where
60
+ # the underlying fixnum doesn't respond to all methods (e.g. name or value).
61
+ # If we respond to the first argument, `__send__` the args. Otherwise,
62
+ # delegate the `try` call to the underlying vlaue fixnum.
63
+ #
64
+ def try(*args, &block)
65
+ case
66
+ when args.empty? && block_given?
67
+ yield self
68
+ when respond_to?(args.first)
69
+ __send__(*args, &block)
70
+ else
71
+ @value.try(*args, &block)
72
+ end
73
+ end
74
+
59
75
  def value
60
76
  @value
61
77
  end
@@ -1,4 +1,4 @@
1
1
  module Protobuf
2
- VERSION = '2.5.4'
2
+ VERSION = '2.5.5'
3
3
  PROTOC_VERSION = '2.4.1'
4
4
  end
@@ -39,6 +39,8 @@ describe Protobuf::Enum do
39
39
  context 'when value is not an applicable type' do
40
40
  it 'returns a nil' do
41
41
  Test::EnumTestType.fetch(Test::Resource.new).should be_nil
42
+ Test::EnumTestType.fetch(nil).should be_nil
43
+ Test::EnumTestType.fetch(false).should be_nil
42
44
  end
43
45
  end
44
46
  end
@@ -12,9 +12,18 @@ describe Protobuf::EnumValue do
12
12
  its(:inspect) { should eq('#<Protobuf::EnumValue Test::EnumTestType::ONE=1>') }
13
13
  specify { subject.to_s(:name).should eq("ONE") }
14
14
 
15
- it "can be used as the index to an array" do
15
+ it "can be used as the index to an array" do
16
16
  array = [0, 1, 2, 3]
17
17
  array[::Test::EnumTestType::ONE].should eq(1)
18
18
  end
19
19
 
20
+ describe '#try' do
21
+ specify { subject.try(:class).should eq subject.class }
22
+ specify { subject.try(:name).should eq subject.name }
23
+ specify { subject.try(:value).should eq subject.value }
24
+ specify { subject.try(:to_i).should eq subject.to_i }
25
+ specify { subject.try(:to_int).should eq subject.to_int }
26
+ specify { subject.try { |yielded| yielded.should eq subject } }
27
+ end
28
+
20
29
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: protobuf
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.5.4
5
+ version: 2.5.5
6
6
  platform: java
7
7
  authors:
8
8
  - BJ Neilsen
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-12-17 00:00:00 Z
14
+ date: 2012-12-19 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport