ruby - Conditional attribute with data_bag_item in Chef? -


i need set default attribute (from cookbook dependency) value included in databag. want attribute set value of data_bag_item or nil if doesn't exists. in attribute.rb:

if defined?(data_bag_item('databag', 'item'))     default["something"]["item"] = data_bag_item('databag', 'item') else     default["something"]["item"] = nil end 

later in own recipe, i'm checking if variable set nil seems fail error (it's condition isn't executed hence default["something"]["item"] not created) : no resource, method, or local variable named 'default' 'chef::recipe "something"'.

what doing wrong here?

(edit i'm learning chef as learning ruby here. totally mistaken in use of defined in case of conditionals. i'm open every critics here!)

i'm not sure full context of recipe, looks should change default node. why? default used set values can changed each node deployed, when running script, can value using node. change default["something"]["item"] node["something"]["item"] checking variable.