Sha256: f04ef891f7072f29116e5763cbac6cd0589ba4d98d0496823efbe4b39cef28d9

Contents?: true

Size: 1.4 KB

Versions: 12

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]

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

      def _gem_name
        nil
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/notiffany-0.0.8/lib/notiffany/notifier/file.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/notiffany-0.0.8/lib/notiffany/notifier/file.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/notiffany-0.0.8/lib/notiffany/notifier/file.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/notiffany-0.0.8/lib/notiffany/notifier/file.rb
notiffany-0.0.8 lib/notiffany/notifier/file.rb
geminfo-0.1.0 path/gems/notiffany-0.0.7/lib/notiffany/notifier/file.rb
notiffany-0.0.7 lib/notiffany/notifier/file.rb
notiffany-0.0.6 lib/notiffany/notifier/file.rb
notiffany-0.0.5 lib/notiffany/notifier/file.rb
notiffany-0.0.4 lib/notiffany/notifier/file.rb
notiffany-0.0.3 lib/notiffany/notifier/file.rb
notiffany-0.0.2 lib/notiffany/notifier/file.rb