rubiclifier 1.0.0 → 2.0.0

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
  SHA256:
3
- metadata.gz: 885f96560267ed31c84cbfb59268f890140f9b91daa1b3ff08657badd28db7ba
4
- data.tar.gz: c46f05c22899e4568578e299f358796676c66ac1122519c3cfd96d904dfc006c
3
+ metadata.gz: 55728a2ee2075c6e1f9dff351518b86f3fa3723697724e690bfd42d5e88a86e4
4
+ data.tar.gz: e506ac9933ce858270541697e10242c6cbd7b1f030174da731036d22dd276e6c
5
5
  SHA512:
6
- metadata.gz: 1a49292eacc335a78e2f8dd4c092af026e2dad15c0403da1c8f2956d4417ef01c138af80bcccd564c0916c5a38983d31bc2eda1683aea70aab57416dc4c0098c
7
- data.tar.gz: a84da6fb10722920c681c133be30f4e24bfe06b318f6e4f12b6115da4f0f6542abd892e2b42cd4df71da73950a96ad04e66a205e80b258f98df350cccd396c0d
6
+ metadata.gz: 79b1be94b2c6cdfba1c356cd8ed0e17e12e2ab36b07e1f4b528cb23f024edb2a5af565de5220fb878bdeb3c7ccd7813a9783512ca463816da366886b2555f51a
7
+ data.tar.gz: 1234dc02fc367519b1713ac1987bc76b6c3c4b9d28cf1678a9aa2846644a239367f9c8599c1c65ce3e540efd21e8763401c6d8a846599eb4fa166f7142ff6974
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative "../lib/cli/rubiclifier_cli.rb"
4
4
 
5
- RubiclifierCli.new(ARGV).call
5
+ RubiclifierCli.new(ARGV, __FILE__.split("/").last).call
@@ -5,12 +5,14 @@ require_relative "./setting.rb"
5
5
 
6
6
  module Rubiclifier
7
7
  class BaseApplication
8
- attr_reader :args
9
- private :args
8
+ attr_reader :args, :executable_name
9
+ private :args, :executable_name
10
10
 
11
- def initialize(args)
11
+ def initialize(args, executable_name)
12
12
  @args = Args.new(args)
13
- DB.hydrate(data_directory, migrations_location) if feature_enabled?(Feature::DATABASE)
13
+ @executable_name = executable_name
14
+ Feature.set_enabled(all_features)
15
+ DB.hydrate(data_directory, migrations_location) if Feature.enabled?(Feature::DATABASE)
14
16
  end
15
17
 
16
18
  def call
@@ -41,12 +43,8 @@ module Rubiclifier
41
43
  []
42
44
  end
43
45
 
44
- def executable_name
45
- raise NotImplementedError
46
- end
47
-
48
46
  def data_directory
49
- raise NotImplementedError if feature_enabled?(Feature::DATABASE)
47
+ raise NotImplementedError if Feature.enabled?(Feature::DATABASE)
50
48
  end
51
49
 
52
50
  def migrations_location
@@ -61,8 +59,9 @@ module Rubiclifier
61
59
 
62
60
  def all_brew_dependencies
63
61
  @abd ||= [
64
- ("sqlite" if feature_enabled?(Feature::DATABASE)),
65
- ("terminal-notifier" if feature_enabled?(Feature::NOTIFICATIONS))
62
+ ("sqlite" if Feature.enabled?(Feature::DATABASE)),
63
+ ("terminal-notifier" if Feature.enabled?(Feature::NOTIFICATIONS)),
64
+ ("sleepwatcher" if Feature.enabled?(Feature::IDLE_DETECTION))
66
65
  ].concat(brew_dependencies).compact
67
66
  end
68
67
 
@@ -88,7 +87,7 @@ module Rubiclifier
88
87
  end
89
88
 
90
89
  def needs_setup?
91
- !all_brew_dependencies.empty? || !settings.empty? || feature_enabled?(Feature::BACKGROUND)
90
+ !all_brew_dependencies.empty? || !settings.empty? || Feature.enabled?(Feature::BACKGROUND)
92
91
  end
93
92
 
94
93
  def setup_or_fail
@@ -109,7 +108,7 @@ module Rubiclifier
109
108
 
110
109
  puts
111
110
 
112
- if feature_enabled?(Feature::BACKGROUND)
111
+ if Feature.enabled?(Feature::BACKGROUND)
113
112
  setup_as_background_service
114
113
  else
115
114
  puts("Finished setup! Run with `".green + "#{executable_name}" + "`".green)
@@ -141,9 +140,5 @@ module Rubiclifier
141
140
  puts("Finished setup!".green)
142
141
  end
143
142
  end
144
-
145
- def feature_enabled?(feature)
146
- all_features.include?(feature)
147
- end
148
143
  end
149
144
  end
@@ -1,4 +1,4 @@
1
- require "rubiclifier"
1
+ require_relative "../rubiclifier.rb"
2
2
 
3
3
  class RubiclifierCli < Rubiclifier::BaseApplication
4
4
  attr_reader :project_name
@@ -14,6 +14,7 @@ class RubiclifierCli < Rubiclifier::BaseApplication
14
14
  puts(" --background | Generate with background service setup steps")
15
15
  puts(" --database | Generate with a persistent database")
16
16
  puts(' --homebrew "[first [second]]" | Require specific homebrew kegs')
17
+ puts(" --idle-detection | Generate with ability to detect if user is idle")
17
18
  puts(" --notifications | Generate with notification functionality")
18
19
  puts(" --settings | Generate with persistent setting functionality")
19
20
  puts
@@ -1,4 +1,4 @@
1
- require "rubiclifier"
1
+ require_relative "../rubiclifier.rb"
2
2
 
3
3
  class TemplateHydrator
4
4
  attr_reader :args, :project_name
@@ -33,6 +33,7 @@ class TemplateHydrator
33
33
  @features ||= [
34
34
  (Rubiclifier::Feature::BACKGROUND if args.boolean("background")),
35
35
  (Rubiclifier::Feature::DATABASE if (args.boolean("database") || include_settings?)),
36
+ (Rubiclifier::Feature::IDLE_DETECTION if args.boolean("idle-detection")),
36
37
  (Rubiclifier::Feature::NOTIFICATIONS if args.boolean("notifications")),
37
38
  ].compact
38
39
  end
@@ -12,6 +12,7 @@ module Rubiclifier
12
12
  end
13
13
 
14
14
  def self.conn
15
+ Feature.fail_unless_enabled(Feature::DATABASE)
15
16
  @conn
16
17
  end
17
18
 
@@ -3,5 +3,18 @@ module Rubiclifier
3
3
  BACKGROUND = "BACKGROUND"
4
4
  DATABASE = "DATABASE"
5
5
  NOTIFICATIONS = "NOTIFICATIONS"
6
+ IDLE_DETECTION = "IDLE_DETECTION"
7
+
8
+ def self.set_enabled(features)
9
+ @enabled = features
10
+ end
11
+
12
+ def self.enabled?(feature)
13
+ @enabled.include?(feature)
14
+ end
15
+
16
+ def self.fail_unless_enabled(feature)
17
+ raise "Looks like you're trying to use feature 'Rubiclifier::Feature::#{feature}' without specifying it in your features." unless Feature.enabled?(feature)
18
+ end
6
19
  end
7
20
  end
@@ -0,0 +1,19 @@
1
+ require_relative "./feature.rb"
2
+
3
+ module Rubiclifier
4
+ class IdleDetector
5
+ def self.set_idle_seconds_threshold(idle_seconds_threshold)
6
+ @idle_seconds_threshold = idle_seconds_threshold
7
+ end
8
+
9
+ def self.idle_seconds_threshold
10
+ @idle_seconds_threshold || 120
11
+ end
12
+
13
+ def self.is_idle?
14
+ Feature.fail_unless_enabled(Feature::IDLE_DETECTION)
15
+ seconds_idle = `/usr/local/sbin/sleepwatcher -g`.to_i / 10
16
+ seconds_idle > idle_seconds_threshold
17
+ end
18
+ end
19
+ end
@@ -1,8 +1,12 @@
1
+ require_relative "./feature.rb"
2
+
1
3
  module Rubiclifier
2
4
  class Notification
3
5
  attr_reader :title, :message, :subtitle, :icon, :url
4
6
  private :title, :message, :subtitle, :icon, :url
7
+
5
8
  def initialize(title, message, subtitle = nil, icon = nil, url = nil)
9
+ Feature.fail_unless_enabled(Feature::NOTIFICATIONS)
6
10
  @title = title
7
11
  @message = message
8
12
  @subtitle = subtitle
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
  \e[32mThanks for installing <%= project_name %>!\e[0m
17
17
  \e[32mSet it up by running `\e[0m<%= project_name %> --setup\e[32m`\e[0m
18
18
 
19
- MSG
19
+ MSG
20
20
  end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "<%= project_name %>"
3
+ require_relative "../lib/<%= project_name %>.rb"
4
4
 
5
- <%= project_name_camel_case %>.new(ARGV).call
5
+ <%= project_name_camel_case %>.new(ARGV, __FILE__.split("/").last).call
@@ -36,10 +36,6 @@ class <%= project_name_camel_case %> < Rubiclifier::BaseApplication
36
36
  ]
37
37
  end
38
38
  <%- end -%>
39
-
40
- def executable_name
41
- "<%= project_name %>"
42
- end
43
39
  <%- if feature_enabled?(Rubiclifier::Feature::DATABASE) -%>
44
40
 
45
41
  def data_directory
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubiclifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Grinstead
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-09 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: kyleag@hey.com
@@ -28,6 +28,7 @@ files:
28
28
  - lib/colorized_strings.rb
29
29
  - lib/database.rb
30
30
  - lib/feature.rb
31
+ - lib/idle_detector.rb
31
32
  - lib/notification.rb
32
33
  - lib/rubiclifier.rb
33
34
  - lib/setting.rb