Module: Diametric::Persistence::Common::InstanceMethods

Defined in:
lib/diametric/persistence/common.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(new_attributes) ⇒ Object


14
15
16
17
18
19
20
21
# File 'lib/diametric/persistence/common.rb', line 14

def assign_attributes(new_attributes)
  valid_keys = attribute_names + [:id]
  new_attributes.each do |key, value|
    if valid_keys.include? key.to_sym
      self.send("#{key}=", value)
    end
  end
end

#save!true, false

Save the entity. If a validation error occurs an error will get raised.

Examples:

Save the entitiy.

entity.save!

Returns:

  • (true, false)

    True if validation passed.


29
30
31
32
33
34
# File 'lib/diametric/persistence/common.rb', line 29

def save!
  unless save
    self.class.fail_validate!(self) unless errors.empty?
  end
  return true
end

#transaction_functionsObject


36
37
38
39
40
41
42
43
# File 'lib/diametric/persistence/common.rb', line 36

def transaction_functions
  functions = self.instance_variable_get("@transaction_functions")
  unless functions
    functions = ::Set.new
    self.instance_variable_set("@transaction_functions", functions)
  end
  functions
end

#update_attributes(new_attributes) ⇒ Object


9
10
11
12
# File 'lib/diametric/persistence/common.rb', line 9

def update_attributes(new_attributes)
  assign_attributes(new_attributes)
  save
end