beefcake 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/beefcake.rb +6 -0
  2. data/test/message_test.rb +11 -1
  3. metadata +2 -2
data/lib/beefcake.rb CHANGED
@@ -202,6 +202,12 @@ module Beefcake
202
202
  fields.values.all? {|fld| self[fld.name] == o[fld.name] }
203
203
  end
204
204
 
205
+ def inspect
206
+ set = fields.values.select {|fld| self[fld.name] != nil }
207
+ flds = set.map {|fld| "#{fld.name}: #{self[fld.name].inspect}" }
208
+ "<#{self.class.name} #{flds.join(", ")}>"
209
+ end
210
+
205
211
  end
206
212
 
207
213
  end
data/test/message_test.rb CHANGED
@@ -28,7 +28,8 @@ end
28
28
  class SimpleMessage
29
29
  include Beefcake::Message
30
30
 
31
- optional :a, :int32, 1
31
+ optional :a, :int32, 1
32
+ optional :b, :string, 2
32
33
  end
33
34
 
34
35
 
@@ -291,4 +292,13 @@ class MessageTest < Test::Unit::TestCase
291
292
  assert_not_equal b, c
292
293
  end
293
294
 
295
+ def test_inspect
296
+ msg = SimpleMessage.new :a => 1
297
+ assert_equal "<SimpleMessage a: 1>", msg.inspect
298
+ msg.b = "testing"
299
+ assert_equal "<SimpleMessage a: 1, b: \"testing\">", msg.inspect
300
+ msg.a = nil
301
+ assert_equal "<SimpleMessage b: \"testing\">", msg.inspect
302
+ end
303
+
294
304
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Blake Mizerany