Class: Notiffany::Notifier::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/notiffany/notifier/base.rb

Defined Under Namespace

Classes: RequireFailed, UnavailableError, UnsupportedPlatform

Constant Summary collapse

HOSTS =
{
  darwin:  "Mac OS X",
  linux:   "Linux",
  'linux-gnu' =>   "Linux",
  freebsd: "FreeBSD",
  openbsd: "OpenBSD",
  sunos:   "SunOS",
  solaris: "Solaris",
  mswin:   "Windows",
  mingw:   "Windows",
  cygwin:  "Windows"
}
ERROR_ADD_GEM_AND_RUN_BUNDLE =
"Please add \"gem '%s'\" to your Gemfile "\
"and run your app with \"bundle exec\"."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/notiffany/notifier/base.rb', line 47

def initialize(opts = {})
  options = opts.dup
  options.delete(:silent)
  @options =
    { title: "Notiffany" }.
    merge(self.class.const_get(:DEFAULTS)).
    merge(options).freeze

  @images_path = Pathname.new(__FILE__).dirname + "../../../images"

  _check_host_supported
  _require_gem
  _check_available(@options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



45
46
47
# File 'lib/notiffany/notifier/base.rb', line 45

def options
  @options
end

Instance Method Details

#_image_path(image) ⇒ Object



75
76
77
78
# File 'lib/notiffany/notifier/base.rb', line 75

def _image_path(image)
  images = [:failed, :pending, :success, :guard]
  images.include?(image) ? @images_path.join("#{image}.png").to_s : image
end

#nameObject



66
67
68
# File 'lib/notiffany/notifier/base.rb', line 66

def name
  title.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end

#notify(message, opts = {}) ⇒ Object



70
71
72
73
# File 'lib/notiffany/notifier/base.rb', line 70

def notify(message, opts = {})
  new_opts = _notify_options(opts).freeze
  _perform_notify(message, new_opts)
end

#titleObject



62
63
64
# File 'lib/notiffany/notifier/base.rb', line 62

def title
  self.class.to_s[/.+::(\w+)$/, 1]
end