lib/ridley/resources/data_bag.rb in ridley-0.4.1 vs lib/ridley/resources/data_bag.rb in ridley-0.5.0

- old
+ new

@@ -2,23 +2,27 @@ # @author Jamie Winsor <jamie@vialstudios.com> # @api private class DBIChainLink attr_reader :data_bag attr_reader :connection + attr_reader :klass # @param [Ridley::DataBag] data_bag - def initialize(data_bag, connection) + def initialize(data_bag, connection, options = {}) + options[:encrypted] ||= false + @data_bag = data_bag @connection = connection + @klass = options[:encrypted] ? Ridley::EncryptedDataBagItem : Ridley::DataBagItem end def new(*args) - Ridley::DataBagItem.send(:new, connection, data_bag, *args) + klass.send(:new, connection, data_bag, *args) end def method_missing(fun, *args, &block) - Ridley::DataBagItem.send(fun, connection, data_bag, *args, &block) + klass.send(fun, connection, data_bag, *args, &block) end end # @author Jamie Winsor <jamie@vialstudios.com> class DataBag @@ -54,10 +58,14 @@ attribute :name validates_presence_of :name def item - @dbi_link ||= DBIChainLink.new(self, connection) + DBIChainLink.new(self, connection) + end + + def encrypted_item + DBIChainLink.new(self, connection, encrypted: true) end end module DSL # Coerces instance functions into class functions on Ridley::DataBag. This coercion