basho/riak-ruby-client — pull request #127 by bkerley (2014-12-02 21:45:32+00:00)
Title: Index names need to be stringified

Hi,
Apologies if I'm missing something obvious, but getting an error while trying to store items with secondary indexes. This is happening in Ruby 2.0 and 1.9.3, backend set to leveldb and using riak-client 1.4.2.

I'm trying to follow the example steps (from README). Error happens during store, TypeError: can't dup NilClass, at line 97 in /lib/riak/client/ beefcake/object_methods.rb:
```ruby
def maybe_encode(string)
ENCODING ? string.dup.force_encoding('BINARY') : string
end
```

Stacktrace:
```
2.0.0-p247 :007 > bucket = @client.bucket("ll") [0/1308]
=> #
2.0.0-p247 :008 > object = bucket.get_or_new 'cobb.salad'
=> #]>
2.0.0-p247 :009 > object.indexes[:ingredients_bin] = %w{lettuce tomato bacon egg chives}
=> ["lettuce", "tomato", "bacon", "egg", "chives"]
2.0.0-p247 :010 > object.indexes[:calories_int] = [220]
=> [220]
2.0.0-p247 :011 > object.store
TypeError: can't dup NilClass
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client/beefcake/object_methods.rb:97:in `dup'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client/beefcake/object_methods.rb:97:in `maybe_encode'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client/beefcake/object_methods.rb:16:in `dump_object'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client/beefcake_protobuffs_backend.rb:64:in `store_object'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client.rb:551:in `block in store_object'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client.rb:470:in `block in recover_from'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/innertube-1.0.2/lib/innertube.rb:127:in `take'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client.rb:468:in `recover_from'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client.rb:414:in `protobuffs'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client.rb:140:in `backend'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/client.rb:550:in `store_object'
from /Users/ron/.rvm/gems/ruby-2.0.0-p247/gems/riak-client-1.4.2/lib/riak/robject.rb:130:in `store'
from (irb):11
from /Users/ron/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `

'
```