Sha256: d7451cae425a53773603c7e28c23135c220df46772eee6682a65b1e9b474fff9

Contents?: true

Size: 642 Bytes

Versions: 10

Compression:

Stored size: 642 Bytes

Contents

module Neutral
  module Model
    module VoteCached
      extend ActiveSupport::Concern

      included do
        delegate :voting, to: :voteable

        after_create :add_vote_to_voting
        after_update :edit_vote_within_voting
        after_destroy :remove_vote_from_voting
      end

      def add_vote_to_voting
        if voting
          voting.add_to_existing(nature)
        else
          Voting.init(self)
          clear_association_cache
        end
      end

      def edit_vote_within_voting
        voting.edit nature
      end

      def remove_vote_from_voting
        voting.remove nature
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
neutral-0.0.10 lib/neutral/model/vote_cached.rb
neutral-0.0.9 lib/neutral/model/vote_cached.rb
neutral-0.0.8 lib/neutral/model/vote_cached.rb
neutral-0.0.7 lib/neutral/model/vote_cached.rb
neutral-0.0.6 lib/neutral/model/vote_cached.rb
neutral-0.0.5 lib/neutral/model/vote_cached.rb
neutral-0.0.4 lib/neutral/model/vote_cached.rb
neutral-0.0.3 lib/neutral/model/vote_cached.rb
neutral-0.0.2 lib/neutral/model/vote_cached.rb
neutral-0.0.1 lib/neutral/model/vote_cached.rb