9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/approvable/acts_as_approvable.rb', line 9
def acts_as_approvable **options
include Approvable::ActsAsApprovable::LocalInstanceMethods
has_many :change_requests, as: :approvable, class_name: 'Approvable::ChangeRequest', dependent: :destroy
has_one :current_change_request, -> {where.not(state: 'approved') }, as: :approvable, class_name: 'Approvable::ChangeRequest', autosave: true
before_save :apply_changes, if: :auto_approve?
after_save :force_approve!, if: :auto_approve?
cattr_accessor :filter_attrs, :filter_type
if options[:except]
self.filter_type = :except
self.filter_attrs = options[:except]
elsif options[:only]
self.filter_type = :only
self.filter_attrs = options[:only]
else
self.filter_type = :except
self.filter_attrs = []
end
unless method_defined?(:assign_attributes_without_change_request)
alias_method_chain :assign_attributes, :change_request
alias_method :attributes=, :assign_attributes_with_change_request
end
end
|