Sha256: b5fdb81b13a0d682f02a19195a85262687e9031c4a5a40765cef14c1fac69fcc

Contents?: true

Size: 793 Bytes

Versions: 6

Compression:

Stored size: 793 Bytes

Contents

module Approval
  module Mixins
    module Resource
      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 }.compact
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
approval-0.3.5 lib/approval/mixins/resource.rb
approval-0.3.4 lib/approval/mixins/resource.rb
approval-0.3.3 lib/approval/mixins/resource.rb
approval-0.3.2 lib/approval/mixins/resource.rb
approval-0.3.1 lib/approval/mixins/resource.rb
approval-0.3.0 lib/approval/mixins/resource.rb