Commit f3e8563c
Changed files (7)
app
controllers
admin
services
application
infrastructure
config
initializers
script
app/controllers/admin/photos_controller.rb
@@ -1,8 +1,8 @@
module Admin
class PhotosController < AdminController
- def initialize(photo_repository = Photo, message_bus = Spank::IOC.resolve(:message_bus), storage = Spank::IOC.resolve(:blob_storage))
+ def initialize(photo_repository = Photo, command_bus = Spank::IOC.resolve(:command_bus), storage = Spank::IOC.resolve(:blob_storage))
@photo_repository = photo_repository
- @bus = message_bus
+ @bus = command_bus
@storage = storage
super()
end
app/services/application/create_cake_command.rb
@@ -1,8 +1,8 @@
class CreateCakeCommand
- def initialize(context, current_user = context.current_user, message_bus = Spank::IOC.resolve(:message_bus))
+ def initialize(context, current_user = context.current_user, command_bus = Spank::IOC.resolve(:command_bus))
@context = context
@current_user = current_user
- @message_bus = message_bus
+ @command_bus = command_bus
end
def run(attributes, tags)
@@ -10,7 +10,7 @@ class CreateCakeCommand
@current_user.tag(cake, with: tags, on: :tags)
if cake.save
- @message_bus.publish(:cake_published, cake_id: cake.id)
+ @command_bus.publish(:cake_published, cake_id: cake.id)
@context.create_cake_succeeded(cake)
else
@context.create_cake_failed(cake)
app/services/application/upload_avatar.rb
@@ -1,10 +1,10 @@
class UploadAvatar
- def initialize(message_bus = Spank::IOC.resolve(:message_bus))
- @message_bus = message_bus
+ def initialize(command_bus = Spank::IOC.resolve(:command_bus))
+ @command_bus = command_bus
end
def run(user, image)
- @message_bus.publish(:upload_avatar, create_message_from(user, image))
+ @command_bus.publish(:upload_avatar, create_message_from(user, image))
end
private
app/services/application/upload_photo.rb
@@ -1,12 +1,12 @@
class UploadPhoto
- def initialize(message_bus = Spank::IOC.resolve(:message_bus), cakes = Creation)
- @message_bus = message_bus
+ def initialize(command_bus = Spank::IOC.resolve(:command_bus), cakes = Creation)
+ @command_bus = command_bus
@cakes = cakes
end
def run(cake_id, params)
photo = @cakes.find(cake_id).photos.create!(image_processing: true, watermark: params[:watermark])
- @message_bus.publish(:upload_photo, create_message_from(cake_id, params, photo))
+ @command_bus.publish(:upload_photo, create_message_from(cake_id, params, photo))
photo
end
app/services/infrastructure/message_bus.rb → app/services/infrastructure/command_bus.rb
@@ -1,4 +1,4 @@
-class MessageBus
+class CommandBus
def initialize(queue = Delayed::Job)
@queue = queue
end
config/initializers/container.rb
@@ -5,7 +5,7 @@ class ConfigureContainerCommand
container.register(:message_handler) { |builder| builder.build(ProcessPhoto) }
container.register(:message_handler) { |builder| builder.build(ProcessAvatar) }
container.register(:queue) { |c| Delayed::Job }
- container.register(:message_bus) { |c| c.build(MessageBus) }.as_singleton
+ container.register(:command_bus) { |c| c.build(CommandBus) }.as_singleton
container.register(:exif_parser) { |builder| ExifParser.new }
container.register(:twitter_publisher) { |c| c.build(TwitterPublisher) }.as_singleton
container.register(:product_api) { |c| AmazonAPI.new }.as_singleton
script/migrate-photos.rb
@@ -4,8 +4,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'envi
class Command
attr_reader :bus, :storage
- def initialize(message_bus = Spank::IOC.resolve(:message_bus), storage = BlobStorage.new)
- @bus = message_bus
+ def initialize(command_bus = Spank::IOC.resolve(:command_bus), storage = BlobStorage.new)
+ @bus = command_bus
@storage = storage
end