Module: Ballot::Sequel::ClassMethods

Defined in:
lib/ballot/sequel.rb

Overview

Class method extensions to Sequel::Model to support Ballot.

Instance Method Summary collapse

Instance Method Details

#acts_as_ballot(*types) ⇒ Object

This macro makes migrating from ActiveRecord to Sequel (mostly) painless. The preferred way is to simply enable the Sequel plug-in directly:

class Voter
  plugin :ballot_voter
end

class Votable
  plugin :ballot_votable
end


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ballot/sequel.rb', line 30

def acts_as_ballot(*types)
  types.each do |type|
    case type.to_s
    when 'votable'
      warn 'Prefer using the Sequel::Model plugin :ballot_votable directly.'
      plugin :ballot_votable
    when 'voter'
      warn 'Prefer using the Sequel::Model plugin :ballot_voter directly.'
      plugin :ballot_voter
    end
  end
end

#acts_as_ballot_votableObject

A shorthand version of acts_as_ballot :votable.



44
45
46
# File 'lib/ballot/sequel.rb', line 44

def acts_as_ballot_votable
  acts_as_ballot :votable
end

#acts_as_ballot_voterObject

A shorthand version of acts_as_ballot :voter.



49
50
51
# File 'lib/ballot/sequel.rb', line 49

def acts_as_ballot_voter
  acts_as_ballot :voter
end

#ballot_votable?Boolean

Sequel::Model classes are not votable by default.

Returns:

  • (Boolean)


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

def ballot_votable?
  false
end

#ballot_voter?Boolean

Sequel::Model classes are not voters by default.

Returns:

  • (Boolean)


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

def ballot_voter?
  false
end