Module: Ballot::ActiveRecord::ClassMethods

Defined in:
lib/ballot/active_record.rb

Overview

Class method extensions to ActiveRecord to support Ballot.

Instance Method Summary collapse

Instance Method Details

#acts_as_ballot(*types) ⇒ Object

The primary macro for marking an ActiveRecord class as votable.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ballot/active_record.rb', line 20

def acts_as_ballot(*types)
  types.each do |type|
    case type.to_s
    when 'votable'
      require 'ballot/active_record/votable'
      next if self < Ballot::ActiveRecord::Votable
      include Ballot::ActiveRecord::Votable
    when 'voter'
      require 'ballot/active_record/voter'
      next if self < Ballot::ActiveRecord::Voter
      include Ballot::ActiveRecord::Voter
    end
  end
end

#acts_as_ballot_votableObject

A shorthand version of acts_as_ballot :votable.



36
37
38
# File 'lib/ballot/active_record.rb', line 36

def acts_as_ballot_votable
  acts_as_ballot :votable
end

#acts_as_ballot_voterObject

A shorthand version of acts_as_ballot :voter.



41
42
43
# File 'lib/ballot/active_record.rb', line 41

def acts_as_ballot_voter
  acts_as_ballot :voter
end

#ballot_votable?Boolean

ActiveRecord classes are not votable by default.

Returns:

  • (Boolean)


10
11
12
# File 'lib/ballot/active_record.rb', line 10

def ballot_votable?
  false
end

#ballot_voter?Boolean

ActiveRecord classes are not voters by default.

Returns:

  • (Boolean)


15
16
17
# File 'lib/ballot/active_record.rb', line 15

def ballot_voter?
  false
end