From 743efbf647a6e287d6da90588351935d6f877043 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 24 Oct 2017 01:10:51 +0100 Subject: [PATCH] Update examples --- examples/application-example/Gemfile | 2 ++ examples/application-example/bin/foobar | 10 ---------- examples/application-example/lib/foobar.rb | 7 +++++-- .../application-example/lib/foobar/application.rb | 14 ++++++++++++++ .../application-example/lib/foobar/consumers.rb | 2 -- .../lib/foobar/ping_consumer.rb | 4 +++- .../lib/foobar/pong_consumer.rb | 5 +++++ examples/application-example/lib/foobar/version.rb | 4 +++- examples/basic-consumers-example/ping_consumer.rb | 2 ++ examples/basic-consumers-example/pong_consumer.rb | 2 ++ 10 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 examples/application-example/lib/foobar/application.rb delete mode 100644 examples/application-example/lib/foobar/consumers.rb diff --git a/examples/application-example/Gemfile b/examples/application-example/Gemfile index 112d7fd..4bab47c 100644 --- a/examples/application-example/Gemfile +++ b/examples/application-example/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gem 'bunnyrun', path: '../..' diff --git a/examples/application-example/bin/foobar b/examples/application-example/bin/foobar index 96616dd..7d7dea4 100755 --- a/examples/application-example/bin/foobar +++ b/examples/application-example/bin/foobar @@ -5,14 +5,4 @@ $LOAD_PATH.unshift(File.expand_path('../../lib', File.realpath(__FILE__))) require 'bunnyrun' require 'foobar' -module Foobar - class Application < BunnyRun::Application - name File.basename(__FILE__) - usage ' []' - version Foobar::VERSION - - option :log_message, 'Message to log after success', type: :string - end -end - Foobar::Application.run(argv: ARGV) diff --git a/examples/application-example/lib/foobar.rb b/examples/application-example/lib/foobar.rb index 6046187..afb420c 100644 --- a/examples/application-example/lib/foobar.rb +++ b/examples/application-example/lib/foobar.rb @@ -1,5 +1,8 @@ -require 'foobar/consumers' -require 'foobar/version' +# frozen_string_literal: true + +require 'foobar/application' +require 'foobar/ping_consumer' +require 'foobar/pong_consumer' module Foobar end diff --git a/examples/application-example/lib/foobar/application.rb b/examples/application-example/lib/foobar/application.rb new file mode 100644 index 0000000..008c768 --- /dev/null +++ b/examples/application-example/lib/foobar/application.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'foobar/version' + +module Foobar + class Application < BunnyRun::Application + name 'foobar' + usage ' []' + version Foobar::VERSION + + option :success_message, 'Message to log after success', + type: :string, default: ENV['MESSAGE'] + end +end diff --git a/examples/application-example/lib/foobar/consumers.rb b/examples/application-example/lib/foobar/consumers.rb deleted file mode 100644 index 5dc562d..0000000 --- a/examples/application-example/lib/foobar/consumers.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'foobar/ping_consumer' -require 'foobar/pong_consumer' diff --git a/examples/application-example/lib/foobar/ping_consumer.rb b/examples/application-example/lib/foobar/ping_consumer.rb index 04f7e94..e292ae0 100644 --- a/examples/application-example/lib/foobar/ping_consumer.rb +++ b/examples/application-example/lib/foobar/ping_consumer.rb @@ -17,7 +17,9 @@ module Foobar publish('ping-pong', 'PONG', routing_key: 'pong') message.ack - logger.info + + return unless options[:success_message] + logger.info("#{self.class}: #{options[:success_message]}") end end end diff --git a/examples/application-example/lib/foobar/pong_consumer.rb b/examples/application-example/lib/foobar/pong_consumer.rb index 84d802a..ec766bc 100644 --- a/examples/application-example/lib/foobar/pong_consumer.rb +++ b/examples/application-example/lib/foobar/pong_consumer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bunnyrun' module Foobar @@ -15,6 +17,9 @@ module Foobar publish('ping-pong', 'PING', routing_key: 'ping') message.ack + + return unless options[:success_message] + logger.info("#{self.class}: #{options[:success_message]}") end end end diff --git a/examples/application-example/lib/foobar/version.rb b/examples/application-example/lib/foobar/version.rb index 4d43786..059d56a 100644 --- a/examples/application-example/lib/foobar/version.rb +++ b/examples/application-example/lib/foobar/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Foobar - VERSION = '0.1.0'.freeze + VERSION = '0.1.0' end diff --git a/examples/basic-consumers-example/ping_consumer.rb b/examples/basic-consumers-example/ping_consumer.rb index 0308312..e5b24ca 100644 --- a/examples/basic-consumers-example/ping_consumer.rb +++ b/examples/basic-consumers-example/ping_consumer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bunnyrun' class PingConsumer < BunnyRun::Consumer diff --git a/examples/basic-consumers-example/pong_consumer.rb b/examples/basic-consumers-example/pong_consumer.rb index d90084a..805bc9e 100644 --- a/examples/basic-consumers-example/pong_consumer.rb +++ b/examples/basic-consumers-example/pong_consumer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bunnyrun' class PongConsumer < BunnyRun::Consumer