Sha256: 005f0832c374458d88f301210353010414461cb42597bc7233116cbac4b30c5a

Contents?: true

Size: 1018 Bytes

Versions: 2

Compression:

Stored size: 1018 Bytes

Contents

module ESA
  module Traits
    module Accountable
      extend ActiveSupport::Concern

      included do
        has_many :esa_events,       :as => :accountable, :class_name => ESA::Event.extension_name(self),       :extend => ESA::Associations::EventsExtension
        has_many :esa_flags,        :as => :accountable, :class_name => ESA::Flag.extension_name(self),        :extend => ESA::Associations::FlagsExtension
        has_many :esa_transactions, :as => :accountable, :class_name => ESA::Transaction.extension_name(self), :extend => ESA::Associations::TransactionsExtension

        before_destroy :destroy_accountable

        def esa_ruleset
          ESA::Ruleset.extension_instance(self)
        end

        def esa_chart
          self.esa_ruleset.chart
        end

        def destroy_accountable
          if self.esa_transactions.blank?
            self.esa_flags.delete_all
            self.esa_events.delete_all
          else
            false
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
event_sourced_accounting-0.2.2 app/models/esa/traits/accountable.rb
event_sourced_accounting-0.1.6 app/models/esa/traits/accountable.rb