Class: Bagboy::Chef::DataBags::Item
- Inherits:
-
Object
- Object
- Bagboy::Chef::DataBags::Item
- Defined in:
- lib/bagboy/chef/data_bags/item.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(opts = {}) ⇒ Item
constructor
A new instance of Item.
- #sync ⇒ Object
- #update(values, fields) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Item
Returns a new instance of Item.
11 12 13 14 15 16 17 18 19 |
# File 'lib/bagboy/chef/data_bags/item.rb', line 11 def initialize(opts = {}) @path = opts[:path] || '' @file = opts[:file] || Core::FileHelper.instance @name = opts[:name] || '' @bag = opts[:bag] || '' @scm = opts[:scm] || Core::SCMHelper.instance @knife = opts[:knife] || Bagboy::Chef::Knife.instance @data = {} end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/bagboy/chef/data_bags/item.rb', line 9 def name @name end |
Instance Method Details
#data ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bagboy/chef/data_bags/item.rb', line 21 def data if File.exists?(@path.to_s) and @data.empty? @data = JSON.parse @file.read(@path) else @data end end |
#sync ⇒ Object
38 39 40 |
# File 'lib/bagboy/chef/data_bags/item.rb', line 38 def sync @knife.update_item(@bag, @name) end |
#update(values, fields) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/bagboy/chef/data_bags/item.rb', line 29 def update (values, fields) pull text = parse_data(values, fields) @file.write @path, text sync commit @data end |