lib/lockbox/utils.rb in lockbox-0.4.3 vs lib/lockbox/utils.rb in lockbox-0.4.4

- old
+ new

@@ -2,12 +2,16 @@ class Utils def self.build_box(context, options, table, attribute) options = options.except(:attribute, :encrypted_attribute, :migrating, :attached, :type) options[:encode] = false unless options.key?(:encode) options.each do |k, v| - if v.is_a?(Proc) - options[k] = context.instance_exec(&v) if v.respond_to?(:call) + if v.respond_to?(:call) + # context not present for pluck + # still possible to use if not dependent on context + options[k] = context ? context.instance_exec(&v) : v.call elsif v.is_a?(Symbol) + # context not present for pluck + raise Error, "Not available since :#{k} depends on record" unless context options[k] = context.send(v) end end unless options[:key] || options[:encryption_key] || options[:decryption_key]