lib/approval/mixins/resource.rb in approval-0.2.3 vs lib/approval/mixins/resource.rb in approval-0.3.0
- old
+ new
@@ -1,24 +1,28 @@
module Approval
module Mixins
module Resource
extend ActiveSupport::Concern
- DEFAULT_IGNORE_FIELDS = %w[id created_at updated_at].freeze
-
included do
class_attribute :approval_ignore_fields
+ self.approval_ignore_fields = %w[id created_at updated_at]
+
has_many :approval_items, class_name: :"Approval::Item", as: :resource
end
class_methods do
- def append_ignore_fields(ignore_fields = [])
- self.approval_ignore_fields = DEFAULT_IGNORE_FIELDS.dup.concat(ignore_fields).map(&:to_s).uniq
+ def assign_ignore_fields(ignore_fields = [])
+ self.approval_ignore_fields = approval_ignore_fields.concat(ignore_fields).map(&:to_s).uniq
end
end
- def params_for_approval
+ def create_params_for_approval
attributes.except(*approval_ignore_fields).compact
+ end
+
+ def update_params_for_approval
+ changes.except(*approval_ignore_fields).each_with_object({}) { |(k, v), h| h[k] = v.last }.compact
end
end
end
end