module Marples
  module ModelActionBroadcast
    CALLBACKS = [ :save, :create, :update, :destroy, :commit ]

    def self.included base
      base.class_eval do
        # Something that response to #subscribe and #publish - although we
        # only use #publish in this mixin.
        class_attribute :marples_transport
        # You *will* need to set this yourself in each application.
        class_attribute :marples_client_name
        self.marples_client_name = File.basename(Rails.root)
        # If you'd like the actions performed by Marples to be logged, set a
        # logger. By default this uses the NullLogger.
        class_attribute :marples_logger
        self.marples_logger = Rails.logger

        CALLBACKS.each do |callback|
          callback_action = callback.to_s =~ /e$/ ? "#{callback}d" : "#{callback}ed"
          after_callback = "after_#{callback}"
          next unless respond_to? after_callback
          send after_callback do |record|
            record.class.marples_client.send callback_action, record
          end
        end

        def self.marples_client
          @marples_client ||= build_marples_client
        end

        def self.build_marples_client
          Marples::Client.new(marples_transport, marples_client_name, marples_logger)
        end
      end
    end
  end
end

module Marples
  module ModelActionBroadcast
    CALLBACKS = [ :save, :create, :update, :destroy, :commit ]

    def self.included base
      base.class_eval do
        # Something that response to #subscribe and #publish - although we
        # only use #publish in this mixin.
        class_attribute :marples_transport
        # You *will* need to set this yourself in each application.
        class_attribute :marples_client_name
        # If you'd like the actions performed by Marples to be logged, set a
        # logger. By default this uses the NullLogger.
        class_attribute :marples_logger
        self.marples_logger = Rails.logger

        CALLBACKS.each do |callback|
          callback_action = callback.to_s =~ /e$/ ? "#{callback}d" : "#{callback}ed"
          after_callback = "after_#{callback}"
          next unless respond_to? after_callback
          send after_callback do |record|
            record.class.marples_client.send callback_action, record
          end
        end

        def self.marples_client
          @marples_client ||= build_marples_client
        end

        def self.build_marples_client
          Marples::Client.new(marples_transport, marples_client_name, marples_logger)
        end
      end
    end
  end
end

Remove automagic implicit default for marples_client_name
Remove automagic implicit default for marples_client_name

The application should set this explicitly. The implicit behaviour is
brittle since it depends on the application's directory name, which
can change between environments (e.g. it's different in Jenkins), and
is therefore a potential source of bugs.
