Module: Eaglenube::Synchronizer::AWS::CommonMethods

Defined in:
lib/eaglenube/synchronizer/aws.rb

Instance Method Summary collapse

Instance Method Details

#create_or_update(provider_vpc, object_identifying_attributes, **optional_params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/eaglenube/synchronizer/aws.rb', line 7

def create_or_update(provider_vpc, object_identifying_attributes, **optional_params)
  unless optional_params.is_a?(Hash)
    raise Eaglenube::Synchronizer::Error, "Expecting common_params to be hash type"
  end

  db_object = find_by(object_identifying_attributes) || new(object_identifying_attributes)
  attributes = parse_provider_data(provider_vpc)
  attributes.merge(optional_params || {}).each { |k, v| db_object.send("#{k}=", v) }
  puts "Error in saving db_object: #{db_object.errors.to_a}" unless db_object.save
end