Class: AmoebaDeployTools::DataBag
- Inherits:
-
Object
- Object
- AmoebaDeployTools::DataBag
- Defined in:
- lib/amoeba_deploy_tools/data_bag.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, item) ⇒ Object
-
#initialize(bag, kitchen) ⇒ DataBag
constructor
A new instance of DataBag.
- #item_filename(id) ⇒ Object
Constructor Details
#initialize(bag, kitchen) ⇒ DataBag
Returns a new instance of DataBag.
5 6 7 8 |
# 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 |
Instance Method Details
#[](id) ⇒ Object
17 18 19 20 21 |
# 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) ⇒ Object
10 11 12 13 14 15 |
# 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) ⇒ Object
23 24 25 |
# File 'lib/amoeba_deploy_tools/data_bag.rb', line 23 def item_filename(id) File.join(@bag_dir, "#{id}.json") end |