class AmoebaDeployTools::DataBag
Public Class Methods
new(bag, kitchen)
click to toggle source
# File lib/amoeba_deploy_tools/data_bag.rb, line 5 def initialize(bag, kitchen) @bag_dir = File.join(kitchen, 'data_bags', bag.to_s) Dir.mkdir @bag_dir unless Dir.exists? @bag_dir end
Public Instance Methods
[](id)
click to toggle source
# File lib/amoeba_deploy_tools/data_bag.rb, line 17 def [](id) DataBagItem.load(item_filename(id), format: :json, create: true).tap do |i| i.id = id end end
[]=(id, item)
click to toggle source
# File lib/amoeba_deploy_tools/data_bag.rb, line 10 def []=(id, item) bag_item = DataBagItem.create(item_filename(id), format: :json) bag_item.clear.deep_merge!(item.to_hash) bag_item.id = id bag_item.save end
item_filename(id)
click to toggle source
# File lib/amoeba_deploy_tools/data_bag.rb, line 23 def item_filename(id) File.join(@bag_dir, "#{id}.json") end