Module: APN::Base
- Included in:
- Connection, Feedback
- Defined in:
- lib/apn/base.rb
Overview
APN::Base takes care of all the boring certificate loading, socket creating, and logging responsibilities so APN::Sender and APN::Feedback and focus on their respective specialties.
Constant Summary collapse
- FIFO_SIZE =
5
Instance Attribute Summary collapse
-
#fifos ⇒ Object
Returns the value of attribute fifos.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #initialize(opts = {}) ⇒ Object
-
#log(level, message = nil) ⇒ Object
Log message to any logger provided by the user (e.g. the Rails logger).
-
#log_and_die(msg) ⇒ Object
Log the message first, to ensure it reports what went wrong if in daemon mode.
-
#socket ⇒ Object
Lazy-connect the socket once we try to access it in some way.
Instance Attribute Details
#fifos ⇒ Object
Returns the value of attribute fifos.
8 9 10 |
# File 'lib/apn/base.rb', line 8 def fifos @fifos end |
#logger ⇒ Object
Returns the value of attribute logger.
8 9 10 |
# File 'lib/apn/base.rb', line 8 def logger @logger end |
#opts ⇒ Object
Returns the value of attribute opts.
8 9 10 |
# File 'lib/apn/base.rb', line 8 def opts @opts end |
Instance Method Details
#initialize(opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/apn/base.rb', line 12 def initialize(opts = {}) @opts = opts @fifos = Hash.new { [] } setup_logger setup_paths log(:info, "APN::Sender with opts #{@opts}") end |
#log(level, message = nil) ⇒ Object
Log message to any logger provided by the user (e.g. the Rails logger). Accepts log_level
, message
, since that seems to make the most sense, and just message
, to be compatible with Resque’s log method and to enable sending verbose and very_verbose worker messages to e.g. the rails logger.
Perhaps a method definition of +message, level
would make more sense, but that’s also the complete opposite of what anyone comming from rails would expect.
34 35 36 37 38 39 |
# File 'lib/apn/base.rb', line 34 def log(level, = nil) level, = 'info', level if .nil? # Handle only one argument if called from Resque, which expects only message return false unless self.logger && self.logger.respond_to?(level) self.logger.send(level, "[APNConnection:#{object_id} #{apn_environment}] #{}") end |
#log_and_die(msg) ⇒ Object
Log the message first, to ensure it reports what went wrong if in daemon mode. Then die, because something went horribly wrong.
43 44 45 46 |
# File 'lib/apn/base.rb', line 43 def log_and_die(msg) log(:fatal, msg) raise msg end |
#socket ⇒ Object
Lazy-connect the socket once we try to access it in some way
22 23 24 25 |
# File 'lib/apn/base.rb', line 22 def socket setup_connection unless @socket return @socket end |