Skip to content

Commit

Permalink
clear pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
madding committed May 29, 2019
1 parent 8ab3849 commit 81fb775
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 0 additions & 2 deletions gemfiles/.bundle/config

This file was deleted.

14 changes: 9 additions & 5 deletions lib/vault/encrypted_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def vault_attribute(vault_attr, options = {})

# Getter
define_method(vault_attr.to_s) do
__vault_load_attributes! unless @__vault_loaded
self.__vault_load_attributes! unless @__vault_loaded
instance_variable_get("@#{vault_attr}")
end

# Setter
define_method("#{vault_attr}=") do |value|
__vault_load_attributes! unless @__vault_loaded
self.__vault_load_attributes! unless @__vault_loaded

# We always set it as changed without comparing with the current value
# because we allow our held values to be mutated, so we need to assume
Expand Down Expand Up @@ -266,9 +266,11 @@ def __vault_persist_attributes!
# If there are any changes to the model, update them all at once,
# skipping any callbacks and validation. This is okay, because we are
# already in a transaction due to the callback.
self.update_columns(changes) unless changes.empty?
if !changes.empty?
self.update_columns(changes)
end

true
return true
end

# Encrypt a single attribute using Vault and persist back onto the
Expand All @@ -284,7 +286,9 @@ def __vault_persist_attribute!(attribute, options)
plaintext = instance_variable_get("@#{attribute}")

# Apply the serialize to the plaintext value, if one exists
plaintext = serializer.encode(plaintext) if serializer
if serializer
plaintext = serializer.encode(plaintext)
end

# Generate context if needed
generated_context = __vault_generate_context(context)
Expand Down
7 changes: 4 additions & 3 deletions spec/dummy/app/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'binary_serializer'
require "binary_serializer"

class Person < ActiveRecord::Base
include Vault::EncryptedModel
Expand All @@ -7,8 +7,8 @@ class Person < ActiveRecord::Base

vault_attribute :credit_card,
encrypted_column: :cc_encrypted,
path: 'credit-secrets',
key: 'people_credit_cards'
path: "credit-secrets",
key: "people_credit_cards"

vault_attribute :details,
serialize: :json
Expand All @@ -35,3 +35,4 @@ def encryption_context
"user_#{id}"
end
end

8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'vault/rails'
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "vault/rails"

require 'rspec'
require "rspec"

RSpec.configure do |config|
# Prohibit using the should syntax
Expand All @@ -21,4 +21,4 @@
config.order = 'random'
end

require File.expand_path('../dummy/config/environment.rb', __FILE__)
require File.expand_path("../dummy/config/environment.rb", __FILE__)

0 comments on commit 81fb775

Please sign in to comment.