Skip to content

Commit

Permalink
YARD initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
leklund committed May 30, 2018
1 parent e9b8770 commit 675184c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/pkg/
/vendor/cache/*.gem
spec/examples.txt
.yardoc
/doc
1 change: 1 addition & 0 deletions fastly_nsq.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec-eventually', '0.2'
gem.add_development_dependency 'timecop'
gem.add_development_dependency 'webmock', '~> 3.0'
gem.add_development_dependency 'yard'

gem.add_dependency 'concurrent-ruby', '~> 1.0'
gem.add_dependency 'nsq-ruby', '~> 2.3'
Expand Down
29 changes: 29 additions & 0 deletions lib/fastly_nsq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ module FastlyNsq
LIFECYCLE_EVENTS = %i[startup shutdown heartbeat].freeze

class << self
# @return [String] NSQ Channel
attr_accessor :channel
# @return [Proc] global preprocessor
attr_accessor :preprocessor
# @return [Numeric] number of max attempts for processing an NSQ message
attr_accessor :max_attempts
# @return [Logger]
attr_writer :logger

def events
@events ||= LIFECYCLE_EVENTS.each_with_object({}) { |e, a| a[e] = [] }
end

##
# Create a FastlyNsq::Listener
#
# @param topic [String] NSQ topic on which to listen
# @param procesor [Proc] processor that will be `call`ed per message
# @param options [Hash] additional options
# @return FastlyNsq::Listener
def listen(topic, processor, **options)
FastlyNsq::Listener.new(topic: topic, processor: processor, **options)
end
Expand All @@ -32,19 +43,37 @@ def logger
@logger ||= Logger.new(nil)
end

##
# Configuration for FastlyNsq
# @example
# FastlyNsq.configure do |config|
# config.channel = 'Z'
# config.logger = Logger.new
# end
def configure
yield self
end

##
# Returns a new FastlyNsq::Manager or the memoized
# instance `@manager`.
# @return [FastlyNsq::Manager]
def manager
@manager ||= FastlyNsq::Manager.new
end

##
# Set a new manager
# @param manager [FastlyNsq::Manager]
# @return [FastlyNsq::Manager]
def manager=(manager)
@manager&.transfer(manager)
@manager = manager
end

##
# Return an array of NSQ lookupd http addresses
# @return [Array<String>] list of nsqlookupd http addresses
def lookupd_http_addresses
ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS').split(',').map(&:strip)
end
Expand Down

0 comments on commit 675184c

Please sign in to comment.