Sha256: 37b0345afc6d2ed36efde75b67687e703763e9c39ec5a9c0cba3ecae0ed30fac

Contents?: true

Size: 1.4 KB

Versions: 26

Compression:

Stored size: 1.4 KB

Contents

require "notiffany/notifier/base"

module Notiffany
  class Notifier
    # Writes notifications to a file.
    #
    class File < Base
      DEFAULTS = { format: "%s\n%s\n%s\n" }

      private

      # @param [Hash] opts some options
      # @option opts [Boolean] path the path to a file where notification
      #   message will be written
      #
      def _check_available(opts = {})
        fail UnavailableError, "No :path option given" unless opts[:path]
      end

      # Writes the notification to a file. By default it writes type, title,
      # and message separated by newlines.
      #
      # @param [String] message the notification message body
      # @param [Hash] opts additional notification library options
      # @option opts [String] type the notification type. Either 'success',
      #   'pending', 'failed' or 'notify'
      # @option opts [String] title the notification title
      # @option opts [String] image the path to the notification image
      # @option opts [String] format printf style format for file contents
      # @option opts [String] path the path of where to write the file
      #
      def _perform_notify(message, opts = {})
        fail UnavailableError, "No :path option given" unless opts[:path]

        str = format(opts[:format], opts[:type], opts[:title], message)
        ::File.write(opts[:path], str)
      end

      def _gem_name
        nil
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 8 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.35 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.34 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.33 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.32 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.31 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.30 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.29 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.28 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.27 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.26 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
qiita_org-0.1.25 gems/ruby/2.7.0/gems/notiffany-0.1.3/lib/notiffany/notifier/file.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/notiffany-0.1.1/lib/notiffany/notifier/file.rb
notiffany-0.1.3 lib/notiffany/notifier/file.rb
notiffany-0.1.2 lib/notiffany/notifier/file.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/notiffany-0.1.1/lib/notiffany/notifier/file.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/notiffany-0.1.1/lib/notiffany/notifier/file.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/notiffany-0.1.1/lib/notiffany/notifier/file.rb