notifaction 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9c48372819fc5caf672f85d8771cc8133c6db6f
4
- data.tar.gz: 904d9e2f65ba36b8b7cc7630b6b1d9d2cbc9893d
3
+ metadata.gz: d0c8013e2cbee495ce3e2f6cd13af414292c32f1
4
+ data.tar.gz: cdf7f71f1a75ad3074352e236571ad6eb7a1ca10
5
5
  SHA512:
6
- metadata.gz: f6cbf68833817f4f0d58bcf49e4f723ad3ed997425f8b587760ce3a84402dd4432fb3ebf6e93b2a066b5afe66e3d0d69e8b842298a6bff046e0184a927a9d937
7
- data.tar.gz: 86eb64d5339ff7af1dddab00f9a2d962cfb498a9f4a6a7ae785551aa9f9e8174e962a1e36cfb4708a4a0a8f711930aba76ee655aeb9b91ff9c3aab97741181e9
6
+ metadata.gz: b0ba2be5cecd9be5798f0ae4d94d11f2399c7559fc62e5364cda360748794922900f6f59feba335805aa7c1f5c358aa4a003f59c22921b389aa2a2efbf1237c3
7
+ data.tar.gz: bf3ef1b2ecd318ecd4fd6e9eee50f590d4c27519288d48de150ca3e3f510737ba7388d3aa230e85899d1bce16e1fb25ab4a05e6c53442b918c441f20d8422021
data/lib/notifaction.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "time"
2
2
  require "rbconfig"
3
3
 
4
+ require "notifaction/helpers"
4
5
  require "notifaction/type"
5
6
  require "notifaction/types/linux"
6
7
  require "notifaction/types/osx"
@@ -4,8 +4,10 @@ module Notifaction
4
4
  class Cfg
5
5
  attr_reader :hooks, :conf
6
6
 
7
+ #
8
+ # @since 0.4.0
7
9
  def initialize
8
- conf = YAML::load(File.open(Dir.home + '/.notifaction.yml'))
10
+ conf = YAML.load(File.open(Dir.home + "/.notifaction.yml"))
9
11
 
10
12
  @hooks = conf["hooks"] || []
11
13
  @conf = conf["config"] || {}
@@ -0,0 +1,20 @@
1
+ module Notifaction
2
+ module Helpers
3
+ # Alert the user that the method they've called is not supported
4
+ # @since 0.4.1
5
+ def deprecation_notice(version, config = {})
6
+ handler = Notifaction::Type::Terminal.new
7
+ handler.warning(
8
+ "Deprecated as of #{version}, current #{Notifaction::VERSION}",
9
+ config
10
+ )
11
+ handler.quit_soft
12
+ end
13
+
14
+ # Should method exit with Type::QUIT? Mainly used in tests
15
+ # @since 0.4.1
16
+ def auto_quit_enabled?(config, user_conf)
17
+ config[:auto_quit] == false || user_conf.conf["auto_quit"] == false
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,8 @@
1
1
  class Notify
2
+ extend Notifaction::Helpers
3
+
2
4
  # Display a notification bubble
5
+ # @since 0.1.0
3
6
  def self.bubble(message, title)
4
7
  if Utils.os == :macosx
5
8
  handler = Notifaction::Type::OSX.new
@@ -8,9 +11,11 @@ class Notify
8
11
  end
9
12
 
10
13
  handler.bubble(message, title)
11
- handler.quit
14
+ handler.quit_ok
12
15
  end
13
16
 
17
+ # Display a modal popup with a close button
18
+ # @since 0.1.0
14
19
  def self.modal(message, title)
15
20
  if Utils.os == :macosx
16
21
  handler = Notifaction::Type::OSX.new
@@ -19,92 +24,56 @@ class Notify
19
24
  end
20
25
 
21
26
  handler.modal(message, title)
22
- handler.quit
27
+ handler.quit_ok
23
28
  end
24
29
 
25
30
  # Prints a pre-formatted error message to the console
31
+ # @since 0.1.0
26
32
  def self.error(message, config = {})
27
33
  handler = Notifaction::Type::Terminal.new
28
34
  handler.error(message, config)
29
- handler.quit unless self.auto_quit_enabled(config, handler.user_conf)
35
+ handler.quit unless auto_quit_enabled?(config, handler.user_conf)
30
36
  end
31
37
 
32
38
  # Prints a pre-formatted warning message to the console
39
+ # @since 0.1.0
33
40
  def self.warning(message, config = {})
34
41
  handler = Notifaction::Type::Terminal.new
35
42
  handler.warning(message, config)
36
43
  end
37
44
 
38
45
  # Prints a pre-formatted informational message to the console
46
+ # @since 0.1.0
39
47
  def self.info(message, config = {})
40
48
  handler = Notifaction::Type::Terminal.new
41
49
  handler.info(message, config)
42
50
  end
43
51
 
44
52
  # Prints a pre-formatted secondary informational message to the console
45
- def self.sinfo(message, config = {})
46
- handler = Notifaction::Type::Terminal.new
47
- handler.note(message, config)
48
- end
49
-
53
+ # @since 0.2.0
50
54
  def self.note(message, config = {})
51
55
  handler = Notifaction::Type::Terminal.new
52
56
  handler.note(message, config)
53
57
  end
54
58
 
55
59
  # Prints a pre-formatted success message to the console
60
+ # @since 0.1.0
56
61
  def self.success(message, config = {})
57
62
  handler = Notifaction::Type::Terminal.new
58
63
  handler.success(message, config)
59
64
  end
60
65
 
61
66
  # Prints a pre-formatted unstyled message to the console
67
+ # @since 0.1.0
62
68
  def self.spit(message, config = {})
63
69
  handler = Notifaction::Type::Terminal.new
64
70
  handler.spit(message, config)
65
71
  end
66
72
 
67
- # Send status updates to WorkingOn
68
- def self.workingon(message, print_info_message = false)
69
- self.deprecation_notice("0.3.0")
70
- end
71
-
72
73
  # pretty-print a spacer
74
+ # @since 0.1.0
73
75
  def self.spacer(config = {})
74
76
  handler = Notifaction::Type::Terminal.new
75
77
  handler.spacer(config)
76
78
  end
77
-
78
- def self.configure
79
- self.deprecation_notice("0.3.0")
80
-
81
- yield self if block_given?
82
- end
83
-
84
- def self.print_output
85
- true
86
- end
87
-
88
- def self.print_timestamps
89
- true
90
- end
91
-
92
- # register new plugins
93
- def self.plugins=(plugin_config_arr)
94
- self.deprecation_notice("0.3.0")
95
- end
96
-
97
- private_class_method
98
-
99
- #
100
- # @since 0.2.8
101
- def deprecation_notice(version)
102
- puts "Deprecated as of #{version}, current #{Notifaction::VERSION}"
103
- end
104
-
105
- #
106
- # @since 0.3.0
107
- def self.auto_quit_enabled(config, user_conf)
108
- config[:auto_quit] == false || user_conf.conf["auto_quit"] == false
109
- end
110
79
  end
@@ -1,25 +1,32 @@
1
1
  module Notifaction
2
- module Style
3
- @map = {
4
- colour: {
5
- red: 31,
6
- green: 32,
7
- yellow: 33,
8
- blue: 34,
9
- magenta: 35,
10
- cyan: 36,
11
- white: 37,
12
- null: 0
13
- },
14
- style: {
15
- reset: 0,
16
- bold: 1,
17
- underline: 4,
18
- normal: ""
2
+ class Style
3
+ # Create the map hash
4
+ # @since 0.4.1
5
+ def initialize
6
+ @map = {
7
+ colour: {
8
+ red: 31,
9
+ green: 32,
10
+ yellow: 33,
11
+ blue: 34,
12
+ magenta: 35,
13
+ cyan: 36,
14
+ white: 37,
15
+ null: 0
16
+ },
17
+ style: {
18
+ reset: 0,
19
+ bold: 1,
20
+ underline: 4,
21
+ normal: ""
22
+ }
19
23
  }
20
- }
24
+ end
21
25
 
22
- def self.format(message, colour = nil, style = nil)
26
+ # Return an ASCII-formatted string for display in common command line
27
+ # terminals
28
+ # @since 0.0.1
29
+ def format(message, colour = nil, style = nil)
23
30
  c = @map[:colour][colour.to_sym] unless colour.nil?
24
31
 
25
32
  if style.nil?
@@ -1,3 +1,4 @@
1
+ require "notifaction/style"
1
2
  require "net/http"
2
3
  require "uri"
3
4
 
@@ -6,22 +7,44 @@ module Notifaction
6
7
  class Base
7
8
  attr_reader :user_conf
8
9
 
10
+ # Exit code to indicate everything is ok!
11
+ OK = 0
12
+ # Exit code to indicate a force quit (exit) call, meaning the program
13
+ # quit with an error
14
+ QUIT = 1
15
+ # Exit code to indicate that the program exited with a non-zero exit code,
16
+ # but not one that resulted in a force quit
17
+ QUIT_SOFT = 2
18
+
9
19
  #
10
20
  # @since 0.3.0.1
11
21
  def initialize
12
22
  @user_conf = Notifaction::Cfg.new
23
+ @style = Notifaction::Style.new
13
24
  end
14
25
 
15
26
  #
16
27
  # @since 0.2.8
17
- def deprecation_notice(version)
18
- puts "Deprecated as of #{version}, current #{Notifaction::VERSION}"
28
+ def quit
29
+ exit(QUIT)
19
30
  end
20
31
 
21
32
  #
22
- # @since 0.2.8
23
- def quit
24
- exit
33
+ # @since 0.4.1
34
+ def quit_soft
35
+ QUIT_SOFT
36
+ end
37
+
38
+ #
39
+ # @since 0.4.1
40
+ def ok
41
+ OK
42
+ end
43
+
44
+ #
45
+ # @since 0.4.1
46
+ def quit_ok
47
+ exit(OK)
25
48
  end
26
49
 
27
50
  #
@@ -1,6 +1,8 @@
1
1
  module Notifaction
2
2
  module Type
3
3
  class Linux < Type::Base
4
+ #
5
+ # @since 0.1.0
4
6
  def bubble(message, title)
5
7
  @response = `notify-send "#{title}" "#{message}"`
6
8
  $?.exitstatus == 0
@@ -8,6 +10,8 @@ module Notifaction
8
10
  fire_hooks({ method: __method__, message: message, title: title })
9
11
  end
10
12
 
13
+ #
14
+ # @since 0.1.0
11
15
  def modal(message, title)
12
16
  nil
13
17
  end
@@ -1,18 +1,30 @@
1
1
  module Notifaction
2
2
  module Type
3
3
  class OSX < Type::Base
4
+ #
5
+ # @since 0.1.0
4
6
  def bubble(message, title)
5
7
  @response = `osascript -e 'display notification "#{message}" with title "#{title}"'`
6
8
  $?.exitstatus == 0
7
9
 
8
- fire_hooks(method: __method__, message: message, title: title)
10
+ if fire_hooks(method: __method__, message: message, title: title)
11
+ quit_ok
12
+ else
13
+ quit_soft
14
+ end
9
15
  end
10
16
 
17
+ #
18
+ # @since 0.1.0
11
19
  def modal(message, title, icon = :caution)
12
20
  @response = `osascript -e 'tell app "System Events" to display dialog "#{message}" buttons {"OK"} default button 1 with title "#{title}" with icon #{icon}'`
13
21
  $?.exitstatus == 0
14
22
 
15
- fire_hooks(method: __method__, message: message, title: title)
23
+ if fire_hooks(method: __method__, message: message, title: title)
24
+ quit_ok
25
+ else
26
+ quit_soft
27
+ end
16
28
  end
17
29
  end
18
30
  end
@@ -1,5 +1,3 @@
1
- require "notifaction/style"
2
-
3
1
  module Notifaction
4
2
  module Type
5
3
  class Terminal < Type::Base
@@ -74,21 +72,29 @@ module Notifaction
74
72
  message = "#{config[:symbol]} #{message}" if show_symbol(config)
75
73
  end
76
74
 
77
- puts Style.format(message, colour, style) unless show_message(config)
78
-
79
- fire_hooks(method: __method__, message: message, config: config)
75
+ puts @style.format(message, colour, style) unless show_message(config)
80
76
 
81
- true
77
+ if fire_hooks(method: __method__, message: message, config: config)
78
+ ok
79
+ else
80
+ soft_quit
81
+ end
82
82
  end
83
83
 
84
+ #
85
+ # @since 0.4.0
84
86
  def show_symbol(config)
85
87
  config[:symbol] || config[:fancy] || @user_conf.conf["fancy"] == true
86
88
  end
87
89
 
90
+ #
91
+ # @since 0.4.0
88
92
  def show_time(config)
89
93
  config[:show_time] || @user_conf.conf["show_time"]
90
94
  end
91
95
 
96
+ #
97
+ # @since 0.4.0
92
98
  def show_message(config)
93
99
  config[:print] == false || @user_conf.conf["print"] == false
94
100
  end
@@ -1,5 +1,8 @@
1
1
  module Notifaction
2
2
  class Utils
3
+ # Returns a formatted time string
4
+ # Used, mainly, for printing timestamps next to terminal output
5
+ # @since 0.0.1
3
6
  def self.formatted_time(time = nil)
4
7
  if time.nil?
5
8
  time = Time.now
@@ -8,6 +11,8 @@ module Notifaction
8
11
  time.strftime("%e/%-m/%Y @ %I:%M:%S%P")
9
12
  end
10
13
 
14
+ # Determine the current OS
15
+ # @since 0.0.1
11
16
  def self.os
12
17
  host_os = RbConfig::CONFIG['host_os']
13
18
 
@@ -1,3 +1,3 @@
1
1
  module Notifaction
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Яyan Priebe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-06 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - bin/setup
71
71
  - lib/notifaction.rb
72
72
  - lib/notifaction/config.rb
73
+ - lib/notifaction/helpers.rb
73
74
  - lib/notifaction/notify.rb
74
75
  - lib/notifaction/style.rb
75
76
  - lib/notifaction/type.rb