Module: Turntabler
- Defined in:
- lib/turntabler.rb,
lib/turntabler/resource.rb,
lib/turntabler/boot.rb,
lib/turntabler/room.rb,
lib/turntabler/snag.rb,
lib/turntabler/song.rb,
lib/turntabler/user.rb,
lib/turntabler/vote.rb,
lib/turntabler/error.rb,
lib/turntabler/event.rb,
lib/turntabler/avatar.rb,
lib/turntabler/client.rb,
lib/turntabler/handler.rb,
lib/turntabler/message.rb,
lib/turntabler/sticker.rb,
lib/turntabler/version.rb,
lib/turntabler/loggable.rb,
lib/turntabler/playlist.rb,
lib/turntabler/assertions.rb,
lib/turntabler/connection.rb,
lib/turntabler/preferences.rb,
lib/turntabler/digest_helpers.rb,
lib/turntabler/room_directory.rb,
lib/turntabler/authorized_user.rb,
lib/turntabler/sticker_placement.rb,
lib/turntabler/playlist_directory.rb
Overview
Turntable.FM API for Ruby
Defined Under Namespace
Modules: Assertions, DigestHelpers, Loggable, Version Classes: APIError, AuthorizedUser, Avatar, Boot, Client, Connection, ConnectionError, Error, Event, Handler, Message, Playlist, PlaylistDirectory, Preferences, Resource, Room, RoomDirectory, Snag, Song, Sticker, StickerPlacement, User, Vote
Class Attribute Summary collapse
-
.logger ⇒ Logger
The logger to use for all Turntable messages.
Class Method Summary collapse
-
.events(*names) ⇒ Object
Defines one or more custom events for which handlers can be registered and triggered via Turntabler::Client#on and Turntabler::Client#trigger, respectively.
-
.interactive ⇒ Object
Whether this is going to be used in an interactive console such as IRB.
-
.run(*args, &block) ⇒ Object
Sets up the proper EventMachine reactor / Fiber to run commands against a client.
Class Attribute Details
.logger ⇒ Logger
The logger to use for all Turntable messages. By default, everything is logged to STDOUT.
13 14 15 |
# File 'lib/turntabler.rb', line 13 def logger @logger end |
Class Method Details
.events(*names) ⇒ Object
Events must be defined before handlers can be registered for them
Defines one or more custom events for which handlers can be registered and triggered via Turntabler::Client#on and Turntabler::Client#trigger, respectively.
111 112 113 114 115 116 117 118 119 |
# File 'lib/turntabler.rb', line 111 def events(*names) names.each do |name| if Event.command?(name) raise ArgumentError, "Event :#{name} is already defined" else Event.handle(name) end end end |
.interactive ⇒ Object
You must continue to run all commands on a client through Turntabler#run.
Whether this is going to be used in an interactive console such as IRB. If this is enabled then EventMachine will run in a separate thread. This will allow IRB to continue to actually be interactive.
34 35 36 |
# File 'lib/turntabler.rb', line 34 def interactive Thread.new { EM.run }.abort_on_exception = true end |
.run(*args, &block) ⇒ Object
If you’re already running within an EventMachine reactor and a
Sets up the proper EventMachine reactor / Fiber to run commands against a client. If this is not in interactive mode, then the block won’t return until the EventMachine reactor is stopped.
Fiber, then there’s no need to call this method prior to interacting with a Turntabler::Client instance.
Exception handling
Any exceptions that occur within the block will be automatically caught and logged. This prevents the EventMachine reactor from dying.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/turntabler.rb', line 80 def run(*args, &block) if EM.reactor_running? EM.next_tick do EM.synchrony do begin if args.any? # Run the block within a client Client.new(*args, &block) else # Just run the block within a fiber block.call end rescue StandardError => ex logger.error(([ex.] + ex.backtrace) * "\n") end end end else EM.synchrony { run(*args, &block) } end end |