Sha256: 3455c0178e9fedd314bf3e8676a3029a3b2822de2afa6b750b6ccd7200a89bef

Contents?: true

Size: 1.78 KB

Versions: 10

Compression:

Stored size: 1.78 KB

Contents

module Bullet
  module Notification
    class Base
      attr_accessor :notifier, :url
      attr_reader :base_class, :associations, :path

      def initialize(base_class, association_or_associations, path = nil)
        @base_class = base_class
        @associations = association_or_associations.is_a?(Array) ?  association_or_associations : [association_or_associations]
        @path = path
      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

      def eql?(other)
        klazz_associations_str == other.klazz_associations_str
      end

      def hash
        klazz_associations_str.hash
      end

      protected
        def klazz_associations_str
          "  #{@base_class} => [#{@associations.map(&:inspect).join(', ')}]"
        end

        def associations_str
          ":includes => #{@associations.map{ |a| a.to_s.to_sym unless a.is_a? Hash }.inspect}"
        end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
bullet-5.0.0 lib/bullet/notification/base.rb
bullet-4.14.10 lib/bullet/notification/base.rb
bullet-4.14.9 lib/bullet/notification/base.rb
bullet-4.14.8 lib/bullet/notification/base.rb
bullet-4.14.7 lib/bullet/notification/base.rb
bullet-4.14.6 lib/bullet/notification/base.rb
bullet-4.14.5 lib/bullet/notification/base.rb
bullet-4.14.4 lib/bullet/notification/base.rb
bullet-4.14.3 lib/bullet/notification/base.rb
bullet-4.14.2 lib/bullet/notification/base.rb