Class: SpotifyWeb::Handler Private
- Inherits:
-
Object
- Object
- SpotifyWeb::Handler
- Includes:
- Assertions, Loggable
- Defined in:
- lib/spotify_web/handler.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents a callback that’s been bound to a particular event
Instance Attribute Summary collapse
-
#conditions ⇒ Hash<String, Object>
readonly
private
The data that must be matched in order for the handler to run.
-
#event ⇒ String
readonly
private
The event this handler is bound to.
-
#once ⇒ Boolean
readonly
private
Whether to only call the handler once and then never again.
Instance Method Summary collapse
-
#initialize(event, options = {}, &block) ⇒ Handler
constructor
private
Builds a new handler bound to the given event.
-
#run(event) ⇒ Boolean
private
Runs this handler for each result from the given event.
Methods included from Assertions
#assert_valid_keys, #assert_valid_values
Constructor Details
#initialize(event, options = {}, &block) ⇒ Handler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a new handler bound to the given event.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/spotify_web/handler.rb', line 31 def initialize(event, = {}, &block) assert_valid_values(event, *Event.commands.values) assert_valid_keys(, :once, :if) = {:once => false, :if => nil}.merge() @event = event @once = [:once] @conditions = [:if] @block = block end |
Instance Attribute Details
#conditions ⇒ Hash<String, Object> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The data that must be matched in order for the handler to run
22 23 24 |
# File 'lib/spotify_web/handler.rb', line 22 def conditions @conditions end |
#event ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The event this handler is bound to
14 15 16 |
# File 'lib/spotify_web/handler.rb', line 14 def event @event end |
#once ⇒ Boolean (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether to only call the handler once and then never again
18 19 20 |
# File 'lib/spotify_web/handler.rb', line 18 def once @once end |
Instance Method Details
#run(event) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs this handler for each result from the given event.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/spotify_web/handler.rb', line 46 def run(event) if conditions_match?(event.data) # Run the block for each individual result event.results.each do |args| begin @block.call(*args) rescue StandardError => ex logger.error(([ex.] + ex.backtrace) * "\n") end end true else false end end |