notifaction 0.0.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 514d8e96cf96f632d010335afd0347b2de5025e5
4
- data.tar.gz: 478edc696fc6ec139e9040d2f83c404ee5e10a34
3
+ metadata.gz: 28a65b85fb1a825f7af8225c38e01d8d614aa2a3
4
+ data.tar.gz: 664caaee8dd66d0a045d381d5bddaca4823e44b1
5
5
  SHA512:
6
- metadata.gz: ee30e73c53dd80cdacdeffae606899e29e8c55bd606d5847b541515c37ef48c495d61aab121e6daf90f1d4decaefff58e95758b133d7066d7eec5eeb8ab78d29
7
- data.tar.gz: e4a13582cd36cae2de6cb2ba18a9a35d5bee0d87b802c2b87b7971f85bebd93b7dad3587636fa122b99f3f90505551c96d885cdcd0cc982f07431bf5885643bf
6
+ metadata.gz: 5db2dd9639e975b4b6a22ba4562f654f01ba9fd27c88bbe1437378178d63d1aa3ff0f50b52aea40f0af657c5a2b8780c558c381fdf3dbd0f81c3fab1c7a4d56e
7
+ data.tar.gz: 12f6946a537c61dec18da6f78b9a070cb9252231e8d2915e90ea665496fac8634bcefedfc7c7cb06c0485132f871dca982943444808e0ec9c4463d468767722b
@@ -1,75 +1,67 @@
1
1
  class Notify
2
2
  # Display a notification bubble
3
3
  def self.bubble(message, title)
4
- begin
5
- if Utils.os == :macosx
6
- if !osx_notification(message, title)
7
- raise "No handler found, cannot show bubble notification"
8
- end
9
- else
10
- if !notifysend(message, title)
11
- raise "No handler found, cannot show bubble notification"
12
- #elsif zenity(message, title)
13
- # raise "No handler found, cannot show bubble notification"
14
- end
15
- end
16
- rescue Exception => e
17
- warning("[self.bubble] #{e.message}")
4
+ if Utils.os == :macosx
5
+ handler = Notifaction::Type::OSX.new
6
+ else
7
+ handler = Notifaction::Type::Linux.new
18
8
  end
9
+
10
+ handler.bubble(message, title)
11
+ handler.quit
19
12
  end
20
13
 
21
14
  def self.modal(message, title)
22
- begin
23
- if Utils.os == :macosx
24
- if !osx_modal(message, title)
25
- raise "No handler found, cannot show system popup"
26
- end
27
- end
28
- rescue Exception => e
29
- warning("[self.bubble] #{e.message}")
15
+ if Utils.os == :macosx
16
+ handler = Notifaction::Type::OSX.new
17
+ else
18
+ handler = Notifaction::Type::Linux.new
30
19
  end
20
+
21
+ handler.modal(message, title)
22
+ handler.quit
31
23
  end
32
24
 
33
25
  # Prints a pre-formatted error message to the console
34
- def self.error(message, config = [])
35
- # message = message.split("\n").join("\n\u2716 ")
36
- # inline("\u2716 #{message} - #{Utils.formatted_time}", :red)
37
- # inline("\u2716 Exiting...", :red)
38
-
39
- # exit(1)
26
+ def self.error(message, config = {})
40
27
  handler = Notifaction::Type::Terminal.new
41
28
  handler.error(message, config)
42
- handler.quit
29
+ handler.quit unless config[:auto_quit] == false
43
30
  end
44
31
 
45
32
  # Prints a pre-formatted warning message to the console
46
- def self.warning(message)
47
- message = message.split("\n").join("\n\u2011 ")
48
- inline("\u2011 #{message} - #{Utils.formatted_time}", :yellow)
33
+ def self.warning(message, config = {})
34
+ handler = Notifaction::Type::Terminal.new
35
+ handler.warning(message, config)
49
36
  end
50
37
 
51
38
  # Prints a pre-formatted informational message to the console
52
39
  def self.info(message, config = {})
53
40
  handler = Notifaction::Type::Terminal.new
54
41
  handler.info(message, config)
55
- #inline("#{message} - #{Utils.formatted_time}", :blue)
56
42
  end
57
43
 
58
44
  # Prints a pre-formatted secondary informational message to the console
59
- def self.sinfo(message)
60
- message = message.split("\n").join("\n\u2011 ")
61
- inline("\u2011 #{message} - #{Utils.formatted_time}", :cyan)
45
+ def self.sinfo(message, config = {})
46
+ handler = Notifaction::Type::Terminal.new
47
+ handler.note(message, config)
48
+ end
49
+
50
+ def self.note(message, config = {})
51
+ handler = Notifaction::Type::Terminal.new
52
+ handler.note(message, config)
62
53
  end
63
54
 
64
55
  # Prints a pre-formatted success message to the console
65
- def self.success(message)
66
- message = message.split("\n").join("\n\u2713 ")
67
- inline("\u2713 #{message} - #{Utils.formatted_time}", :green)
56
+ def self.success(message, config = {})
57
+ handler = Notifaction::Type::Terminal.new
58
+ handler.success(message, config)
68
59
  end
69
60
 
70
61
  # Prints a pre-formatted unstyled message to the console
71
- def self.spit(message)
72
- inline(message, :null)
62
+ def self.spit(message, config = {})
63
+ handler = Notifaction::Type::Terminal.new
64
+ handler.spit(message, config)
73
65
  end
74
66
 
75
67
  # Send status updates to WorkingOn
@@ -87,8 +79,9 @@ class Notify
87
79
  end
88
80
 
89
81
  # pretty-print a spacer
90
- def self.spacer
91
- inline("\u2011 =============", :magenta)
82
+ def self.spacer(config = {})
83
+ handler = Notifaction::Type::Terminal.new
84
+ handler.spacer(config)
92
85
  end
93
86
 
94
87
  def self.configure
@@ -115,53 +108,4 @@ class Notify
115
108
  end
116
109
  end
117
110
 
118
- private
119
-
120
- # Collate colour and style, build message string in format of
121
- # "\e[#{style};#{colour}m#{text}\e[0m"
122
- def self.inline(message, colour = nil, style = nil)
123
- puts Style.format(message, colour, style)
124
- end
125
-
126
- def self.osx_notification(message, title)
127
- begin
128
- @response = `osascript -e 'display notification "#{message}" with title "#{title}"'`
129
-
130
- $?.exitstatus == 0
131
- rescue SystemExit, Interrupt
132
- error("Interrupt caught, exiting")
133
- end
134
- end
135
-
136
- # OSX system modal popup
137
- def self.osx_modal(message, title, icon = :caution)
138
- begin
139
- @response = `osascript -e 'tell app "System Events" to display dialog "#{message}" buttons {"OK"} default button 1 with title "#{title}" with icon #{icon}'`
140
-
141
- $?.exitstatus == 0
142
- rescue SystemExit, Interrupt
143
- error("Interrupt caught, exiting")
144
- end
145
- end
146
-
147
- # Linux system notification
148
- def self.notifysend(message, title)
149
- begin
150
- @response = `notify-send "#{title}" "#{message}"`
151
-
152
- $?.exitstatus == 0
153
- rescue SystemExit, Interrupt
154
- error("Interrupt caught, exiting")
155
- end
156
- end
157
-
158
- def self.zenity(message, title)
159
- begin
160
- @response = `echo "message:#{message}" | zenity --notification --listen`
161
-
162
- $?.exitstatus == 0
163
- rescue SystemExit, Interrupt
164
- error("Interrupt caught, exiting")
165
- end
166
- end
167
111
  end
@@ -3,11 +3,12 @@ module Notifaction
3
3
  class Linux < Type::Base
4
4
 
5
5
  def bubble(message, title)
6
-
6
+ @response = `notify-send "#{title}" "#{message}"`
7
+ $?.exitstatus == 0
7
8
  end
8
9
 
9
10
  def modal(message, title)
10
-
11
+ nil
11
12
  end
12
13
 
13
14
  end
@@ -3,11 +3,13 @@ module Notifaction
3
3
  class OSX < Type::Base
4
4
 
5
5
  def bubble(message, title)
6
-
6
+ @response = `osascript -e 'display notification "#{message}" with title "#{title}"'`
7
+ $?.exitstatus == 0
7
8
  end
8
9
 
9
- def modal(message, title)
10
-
10
+ def modal(message, title, icon = :caution)
11
+ @response = `osascript -e 'tell app "System Events" to display dialog "#{message}" buttons {"OK"} default button 1 with title "#{title}" with icon #{icon}'`
12
+ $?.exitstatus == 0
11
13
  end
12
14
 
13
15
  end
@@ -6,24 +6,28 @@ module Notifaction
6
6
  #
7
7
  # @since 0.2.8
8
8
  def error(message, config)
9
+ config[:symbol] = "\u2716"
9
10
  inline(message, config, :red)
10
11
  end
11
12
 
12
13
  #
13
14
  # @since 0.2.8
14
15
  def warning(message, config)
16
+ config[:symbol] = "\u2011"
15
17
  inline(message, config, :yellow)
16
18
  end
17
19
 
18
20
  #
19
21
  # @since 0.2.8
20
22
  def success(message, config)
23
+ config[:symbol] = "\u2713"
21
24
  inline(message, config, :green)
22
25
  end
23
26
 
24
27
  #
25
28
  # @since 0.2.8
26
29
  def info(message, config)
30
+ config[:symbol] = "\u2011"
27
31
  inline(message, config, :blue)
28
32
  end
29
33
 
@@ -38,31 +42,41 @@ module Notifaction
38
42
  #
39
43
  # @since 0.2.8
40
44
  def note(message, config)
45
+ config[:symbol] = "\u2011"
41
46
  inline(message, config, :cyan)
42
47
  end
43
48
 
44
49
  #
45
50
  # @since 0.2.8
46
51
  def spit(message, config)
52
+ config[:fancy] = false
47
53
  inline(message, config)
48
54
  end
49
55
 
50
56
  #
51
57
  # @since 0.2.8
52
- def spacer
53
- inline("\u2011 =============", {}, :magenta)
58
+ def spacer(config)
59
+ config[:symbol] = "\u2011"
60
+ inline("=============", config, :magenta)
54
61
  end
55
62
 
56
63
  private
57
64
 
58
65
  #
59
66
  # @since 0.2.8
60
- def inline(message, config = [], colour = nil, style = nil)
61
- # formatting options
62
- message += " - #{Utils.formatted_time}" if config[:show_time]
63
- message = "#{config[:symbol]} #{message}" if config[:fancy]
67
+ def inline(message, config, colour = nil, style = nil)
68
+ if config.empty?
69
+ # no configuration provided, default to showing all config options
70
+ message += " - #{Utils.formatted_time}"
71
+ else
72
+ # update message content based on configuration variables
73
+ message += " - #{Utils.formatted_time}" if config[:show_time]
74
+ message = "#{config[:symbol]} #{message}" if config[:symbol] || config[:fancy]
75
+ end
64
76
 
65
- puts Style.format(message, colour, style)
77
+ puts Style.format(message, colour, style) unless config[:print] == false
78
+
79
+ true
66
80
  end
67
81
 
68
82
  end
@@ -1,3 +1,3 @@
1
1
  module Notifaction
2
- VERSION = "0.0.9"
2
+ VERSION = "0.2.0"
3
3
  end
data/notifaction.gemspec CHANGED
@@ -9,13 +9,10 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Яyan Priebe"]
10
10
  spec.email = ["rpriebe@me.com"]
11
11
 
12
- spec.summary = %q{Include terminal and OS notifications in your ruby projects}
13
- spec.description = %q{Include terminal and OS notifications in your ruby projects}
12
+ spec.summary = "Output status messages from your scripts/programs"
14
13
  spec.homepage = "https://rubygems.org/gems/notifaction"
15
14
  spec.license = "MIT"
16
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
18
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
16
  spec.require_paths = ["lib"]
20
17
 
21
18
  spec.add_development_dependency "bundler", "~> 1.11"
metadata CHANGED
@@ -1,66 +1,66 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Яyan Priebe
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.11'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '5.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description: Include terminal and OS notifications in your ruby projects
55
+ description:
56
56
  email:
57
57
  - rpriebe@me.com
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
63
- - ".travis.yml"
62
+ - .gitignore
63
+ - .travis.yml
64
64
  - Gemfile
65
65
  - LICENSE.txt
66
66
  - README.md
@@ -89,12 +89,12 @@ require_paths:
89
89
  - lib
90
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ">="
92
+ - - '>='
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - ">="
97
+ - - '>='
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
@@ -102,5 +102,5 @@ rubyforge_project:
102
102
  rubygems_version: 2.0.14.1
103
103
  signing_key:
104
104
  specification_version: 4
105
- summary: Include terminal and OS notifications in your ruby projects
105
+ summary: Output status messages from your scripts/programs
106
106
  test_files: []