Class: Pravangi::PendingApproval

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/pravangi/models/pending_approval.rb

Instance Method Summary collapse

Instance Method Details

#approve_changesObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pravangi/models/pending_approval.rb', line 20

def approve_changes
  PendingApproval.transaction do
    resource.skip_approval = true
    object_changes.each do |k,v|
      resource[k] = v[1]
    end
    self.update_attribute(:is_approved, true)
    resource.save
    resource.reload
  end
end

#as_objectObject



12
13
14
# File 'lib/pravangi/models/pending_approval.rb', line 12

def as_object
  @object ||= YAML.load(raw_object)
end

#changed_object_attributesObject



16
17
18
# File 'lib/pravangi/models/pending_approval.rb', line 16

def changed_object_attributes
  self.object_changes.keys
end

#reject_changesObject



32
33
34
# File 'lib/pravangi/models/pending_approval.rb', line 32

def reject_changes
  self.update_attribute(:is_rejected, true)
end

#skip_attributesObject



36
37
38
39
40
# File 'lib/pravangi/models/pending_approval.rb', line 36

def skip_attributes
  if self.resource.class.pravangi_options[:skip_attributes]
    object_changes.except(*self.resource.class.pravangi_options[:skip_attributes])
  end
end