lib/vault-tree/contract/contract.rb in vault-tree-0.1.0 vs lib/vault-tree/contract/contract.rb in vault-tree-0.3.3

- old
+ new

@@ -6,11 +6,12 @@ @json = json @master_passphrase = params[:master_passphrase] @external_data = params[:external_data] end - def close_vault(id) + def close_vault(id, params = {data: nil}) + update_external_data(id: id , data: params[:data]) validate_vault(id) update_vaults vault(id).close self end @@ -46,18 +47,22 @@ def master_passphrase validate_passphrase @master_passphrase end + def external_data_hash + @external_data + end + def external_data(id) @external_data[id] end private def passphrase_present? - !! @master_passphrase + !! @master_passphrase end def valid_id?(id) id.nil? || vaults.include?(id) end @@ -78,8 +83,14 @@ raise Exceptions::VaultDoesNotExist unless valid_id?(id) end def validate_passphrase raise Exceptions::MissingPassphrase unless passphrase_present? + end + + def update_external_data(params) + vault_id = params[:id] + data = params[:data] + @external_data = @external_data.merge({"#{vault_id}" => "#{data}"}) unless data.nil? end end end