Sha256: 1ed50ea5cd2638729e8a8ca9c19c4bf6071a9576b5fc7f113ff792f9636d8253

Contents?: true

Size: 730 Bytes

Versions: 2

Compression:

Stored size: 730 Bytes

Contents

module Approval
  module ActsAsResource
    extend ActiveSupport::Concern

    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 assign_ignore_fields(ignore_fields = [])
        self.approval_ignore_fields = approval_ignore_fields.concat(ignore_fields).map(&:to_s).uniq
      end
    end

    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 }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
approval-0.7.1 app/models/concerns/approval/acts_as_resource.rb
approval-0.7.0 app/models/concerns/approval/acts_as_resource.rb