Class: Ridley::DataBagItemObject
- Inherits:
-
ChefObject
- Object
- ChefObject
- Ridley::DataBagItemObject
- Defined in:
- lib/ridley/chef_objects/data_bag_item_obect.rb
Instance Attribute Summary collapse
- #data_bag ⇒ Ridley::DataBagObject readonly
Instance Method Summary collapse
-
#decrypt ⇒ Hash
Decrypts this data bag item.
-
#decrypt_value(value) ⇒ Hash
Decrypts an individual value stored inside the data bag item.
- #from_hash(hash) ⇒ Object
-
#initialize(resource, data_bag, new_attrs = {}) ⇒ DataBagItemObject
constructor
A new instance of DataBagItemObject.
-
#reload ⇒ Object
Reload the attributes of the instantiated resource.
-
#save ⇒ Boolean
Creates a resource on the target remote or updates one if the resource already exists.
-
#update ⇒ Boolean
Updates the instantiated resource on the target remote with any changes made to self.
Methods inherited from ChefObject
#<=>, #==, chef_id, #chef_id, chef_json_class, chef_type, #eql?, #hash, #inspect, set_chef_id, set_chef_json_class, set_chef_type
Constructor Details
#initialize(resource, data_bag, new_attrs = {}) ⇒ DataBagItemObject
Returns a new instance of DataBagItemObject.
21 22 23 24 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 21 def initialize(resource, data_bag, new_attrs = {}) super(resource, new_attrs) @data_bag = data_bag end |
Instance Attribute Details
#data_bag ⇒ Ridley::DataBagObject (readonly)
9 10 11 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 9 def data_bag @data_bag end |
Instance Method Details
#decrypt ⇒ Hash
Decrypts this data bag item.
47 48 49 50 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 47 def decrypt decrypted_hash = Hash[_attributes_.map { |key, value| [key, key == "id" ? value : decrypt_value(value)] }] mass_assign(decrypted_hash) end |
#decrypt_value(value) ⇒ Hash
Decrypts an individual value stored inside the data bag item.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 61 def decrypt_value(value) case format_version_of(value) when 0 decrypt_v0_value(value) when 1 decrypt_v1_value(value) else raise NotImplementedError, "Currently decrypting only version 0 & 1 databags are supported" end end |
#from_hash(hash) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 97 def from_hash(hash) hash = Hashie::Mash.new(hash.to_hash) mass_assign(hash.has_key?(:raw_data) ? hash[:raw_data] : hash) self end |
#reload ⇒ Object
Reload the attributes of the instantiated resource
75 76 77 78 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 75 def reload mass_assign(resource.find(data_bag, self)._attributes_) self end |
#save ⇒ Boolean
Creates a resource on the target remote or updates one if the resource already exists.
34 35 36 37 38 39 40 41 42 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 34 def save raise Errors::InvalidResource.new(self.errors) unless valid? mass_assign(resource.create(data_bag, self)._attributes_) true rescue Errors::HTTPConflict self.update true end |
#update ⇒ Boolean
Updates the instantiated resource on the target remote with any changes made to self
87 88 89 90 91 92 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 87 def update raise Errors::InvalidResource.new(self.errors) unless valid? mass_assign(resource.update(data_bag, self)._attributes_) true end |