Module: BallotBox::Callbacks
- Included in:
- Manager
- Defined in:
- lib/ballot_box/callbacks.rb
Instance Method Summary collapse
-
#_after_vote ⇒ Object
Provides access to the callback array for before_vote :api: private.
-
#_before_vote ⇒ Object
Provides access to the callback array for before_vote :api: private.
-
#_run_callbacks(kind, *args) ⇒ Object
Hook to _run_callbacks asserting for conditions.
-
#after_vote(options = {}, method = :push, &block) ⇒ Object
A callback that runs after vote created Example: BallotBox::Manager.after_vote do |env, opts| end.
-
#before_vote(options = {}, method = :push, &block) ⇒ Object
A callback that runs before create vote Example: BallotBox::Manager.before_vote do |env, opts| end.
Instance Method Details
#_after_vote ⇒ Object
Provides access to the callback array for before_vote :api: private
45 46 47 |
# File 'lib/ballot_box/callbacks.rb', line 45 def _after_vote @_after_vote ||= [] end |
#_before_vote ⇒ Object
Provides access to the callback array for before_vote :api: private
29 30 31 |
# File 'lib/ballot_box/callbacks.rb', line 29 def _before_vote @_before_vote ||= [] end |
#_run_callbacks(kind, *args) ⇒ Object
Hook to _run_callbacks asserting for conditions.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ballot_box/callbacks.rb', line 5 def _run_callbacks(kind, *args) #:nodoc: = args.last # Last callback arg MUST be a Hash send("_#{kind}").each do |callback, conditions| invalid = conditions.find do |key, value| value.is_a?(Array) ? !value.include?([key]) : (value != [key]) end callback.call(*args) unless invalid end end |
#after_vote(options = {}, method = :push, &block) ⇒ Object
38 39 40 41 |
# File 'lib/ballot_box/callbacks.rb', line 38 def after_vote( = {}, method = :push, &block) raise BlockNotGiven unless block_given? _after_vote.send(method, [block, ]) end |
#before_vote(options = {}, method = :push, &block) ⇒ Object
22 23 24 25 |
# File 'lib/ballot_box/callbacks.rb', line 22 def before_vote( = {}, method = :push, &block) raise BlockNotGiven unless block_given? _before_vote.send(method, [block, ]) end |