Sha256: ea494840ae80cb4b6deba0c727457054074c857a4727d68f1266a4aacfc7c4e5

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module Brakefast
  module Notification
    class Base
      attr_accessor :notifier, :url
      attr_reader :klass, :message, :path, :line

      def initialize(klass, message, path = nil, line = nil)
        @klass = klass
        @message = message
        @path = path
        @line = line
      end

      def title
        raise NoMethodError.new("no method title defined")
      end

      def body
        raise NoMethodError.new("no method body defined")
      end

      def call_stack_messages
        ""
      end

      def whoami
        @user ||= ENV['USER'].presence || (`whoami`.chomp rescue "")
        if @user.present?
          "user: #{@user}"
        else
          ""
        end
      end

      def body_with_caller
        "#{body}\n#{call_stack_messages}\n"
      end

      def notify_inline
        self.notifier.inline_notify(notification_data)
      end

      def notify_out_of_channel
        self.notifier.out_of_channel_notify(notification_data)
      end

      def short_notice
        [whoami.presence, url, title, body].compact.join("  ")
      end

      def notification_data
        {
          :user => whoami,
          :url => url,
          :title => title,
          :body => body_with_caller,
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brakefast-0.0.2 lib/brakefast/notification/base.rb
brakefast-0.0.1 lib/brakefast/notification/base.rb