rubiclifier 1.1.1 → 2.1.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
  SHA256:
3
- metadata.gz: bf1b8199e6b2fee2377bff63ad86d107274bfcc46b331ae5d4632c86403fad91
4
- data.tar.gz: 446e3fdba77b10bb618cc2708a542ee7b1371eff221b03940a8315c58db39918
3
+ metadata.gz: 9bd877c04ce5198289182cdb85cb74c101b6bde7a7dfc6bce8455fe5f357d173
4
+ data.tar.gz: 518e54becb28e254694bb1c38fbecd2a73dc2544e6d310b1ae011d793f3e94b6
5
5
  SHA512:
6
- metadata.gz: 3c4c57ec314d300dabed106cbd00edf8579cf5e047078b50fd5ad002e64cd31bbb6674b97d8ebd06f2c2e043b82f57d51bf7109b6dd665a8a68084babfcd4d9a
7
- data.tar.gz: 60b00b7faea76268e6ddbcb755357720f768307a4f718a8c1b0909f19a0c128c7f5c3c705e63b3dd74b7f3f9873030ea1b0adde5b0bd46582bcd80567b24ed35
6
+ metadata.gz: e88a6e9af97bb3866332004645d0f328f23062c9e6322bef9f54bebac5ef0ee24a655d1cd544fa54bf8e017cdf8e4f4844826738a5d1c33f404cdbde7ea6b7cf
7
+ data.tar.gz: 119d79a2fc89651748b2cf677d06558736f49163aa23bf4ef2e98d41f882379646fe4f8d605ddb0fe689a243c36efcbd79ca6563edbc44fb5d6dbdc8186f253a
data/Gemfile CHANGED
@@ -4,3 +4,9 @@ gemspec
4
4
 
5
5
  gem "httparty"
6
6
  gem "sqlite3"
7
+ gem "sinatra"
8
+
9
+ group :test do
10
+ gem "byebug"
11
+ gem "rspec"
12
+ end
@@ -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,28 +5,43 @@ 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
17
19
  show_help if args.command == "help" || args.boolean("help", "h")
18
20
  setup_or_fail if needs_setup?
19
- run_application
21
+ if Feature.enabled?(Feature::SERVER)
22
+ run_server
23
+ else
24
+ run_application
25
+ end
20
26
  end
21
27
 
22
28
  def show_help
23
29
  raise NotImplementedError
24
30
  end
25
31
 
32
+ def run_server
33
+ raise NotImplementedError
34
+ end
35
+
26
36
  def run_application
27
37
  raise NotImplementedError
28
38
  end
29
39
 
40
+ def run_server
41
+ server_class.hydrate
42
+ server_class.run!
43
+ end
44
+
30
45
  def additional_setup
31
46
  end
32
47
 
@@ -41,12 +56,8 @@ module Rubiclifier
41
56
  []
42
57
  end
43
58
 
44
- def executable_name
45
- raise NotImplementedError
46
- end
47
-
48
59
  def data_directory
49
- raise NotImplementedError if feature_enabled?(Feature::DATABASE)
60
+ raise NotImplementedError if Feature.enabled?(Feature::DATABASE)
50
61
  end
51
62
 
52
63
  def migrations_location
@@ -61,14 +72,15 @@ module Rubiclifier
61
72
 
62
73
  def all_brew_dependencies
63
74
  @abd ||= [
64
- ("sqlite" if feature_enabled?(Feature::DATABASE)),
65
- ("terminal-notifier" if feature_enabled?(Feature::NOTIFICATIONS))
75
+ ("sqlite" if Feature.enabled?(Feature::DATABASE)),
76
+ ("terminal-notifier" if Feature.enabled?(Feature::NOTIFICATIONS)),
77
+ ("sleepwatcher" if Feature.enabled?(Feature::IDLE_DETECTION))
66
78
  ].concat(brew_dependencies).compact
67
79
  end
68
80
 
69
81
  def brew_dependencies_installed?
70
82
  all_brew_dependencies.all? do |dep|
71
- system("brew list #{dep} &> /dev/null")
83
+ system("/usr/local/bin/brew list #{dep} &> /dev/null")
72
84
  end
73
85
  end
74
86
 
@@ -88,7 +100,7 @@ module Rubiclifier
88
100
  end
89
101
 
90
102
  def needs_setup?
91
- !all_brew_dependencies.empty? || !settings.empty? || feature_enabled?(Feature::BACKGROUND)
103
+ !all_brew_dependencies.empty? || !settings.empty? || Feature.enabled?(Feature::BACKGROUND)
92
104
  end
93
105
 
94
106
  def setup_or_fail
@@ -109,7 +121,7 @@ module Rubiclifier
109
121
 
110
122
  puts
111
123
 
112
- if feature_enabled?(Feature::BACKGROUND)
124
+ if Feature.enabled?(Feature::BACKGROUND)
113
125
  setup_as_background_service
114
126
  else
115
127
  puts("Finished setup! Run with `".green + "#{executable_name}" + "`".green)
@@ -141,9 +153,5 @@ module Rubiclifier
141
153
  puts("Finished setup!".green)
142
154
  end
143
155
  end
144
-
145
- def feature_enabled?(feature)
146
- all_features.include?(feature)
147
- end
148
156
  end
149
157
  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,7 +14,9 @@ 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")
19
+ puts(" --server | Generate with server")
18
20
  puts(" --settings | Generate with persistent setting functionality")
19
21
  puts
20
22
  exit
@@ -44,6 +46,10 @@ class RubiclifierCli < Rubiclifier::BaseApplication
44
46
  unless template_hydrator.feature_enabled?(Rubiclifier::Feature::DATABASE)
45
47
  system("rm #{project_name}/migrations.rb")
46
48
  end
49
+ unless template_hydrator.feature_enabled?(Rubiclifier::Feature::SERVER)
50
+ system("rm #{project_name}/lib/server.rb")
51
+ system("rm -rf #{project_name}/public")
52
+ end
47
53
  puts("Finished creating project #{project_name}! Build out the application in #{project_name}/lib/#{project_name}.rb".green)
48
54
  end
49
55
 
@@ -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,7 +33,9 @@ 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")),
38
+ (Rubiclifier::Feature::SERVER if args.boolean("server")),
37
39
  ].compact
38
40
  end
39
41
 
@@ -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,19 @@ module Rubiclifier
3
3
  BACKGROUND = "BACKGROUND"
4
4
  DATABASE = "DATABASE"
5
5
  NOTIFICATIONS = "NOTIFICATIONS"
6
+ IDLE_DETECTION = "IDLE_DETECTION"
7
+ SERVER = "SERVER"
8
+
9
+ def self.set_enabled(features)
10
+ @enabled = features
11
+ end
12
+
13
+ def self.enabled?(feature)
14
+ @enabled.include?(feature)
15
+ end
16
+
17
+ def self.fail_unless_enabled(feature)
18
+ raise "Looks like you're trying to use feature 'Rubiclifier::Feature::#{feature}' without specifying it in your features." unless Feature.enabled?(feature)
19
+ end
6
20
  end
7
21
  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
@@ -0,0 +1,13 @@
1
+ require 'sinatra/base'
2
+
3
+ module Rubiclifier
4
+ class Server < Sinatra::Base
5
+ def self.hydrate
6
+ raise NotImplementedError
7
+ end
8
+
9
+ get "/" do
10
+ redirect("/index.html")
11
+ end
12
+ end
13
+ end
@@ -2,4 +2,4 @@
2
2
 
3
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
@@ -1,4 +1,7 @@
1
1
  require "rubiclifier"
2
+ <%- if feature_enabled?(Rubiclifier::Feature::SERVER) -%>
3
+ require_relative "./server.rb"
4
+ <%- end -%>
2
5
 
3
6
  class <%= project_name_camel_case %> < Rubiclifier::BaseApplication
4
7
  def show_help
@@ -15,12 +18,18 @@ class <%= project_name_camel_case %> < Rubiclifier::BaseApplication
15
18
  exit
16
19
  end
17
20
 
21
+ <%- if feature_enabled?(Rubiclifier::Feature::SERVER) -%>
22
+ def server_class
23
+ Server
24
+ end
25
+ <%- else -%>
18
26
  def run_application
19
27
  while true
20
28
  puts "Running!"
21
29
  sleep 5
22
30
  end
23
31
  end
32
+ <%- end -%>
24
33
  <%- if !features.empty? -%>
25
34
 
26
35
  def features
@@ -36,12 +45,6 @@ class <%= project_name_camel_case %> < Rubiclifier::BaseApplication
36
45
  ]
37
46
  end
38
47
  <%- end -%>
39
- <%- if needs_setup? -%>
40
-
41
- def executable_name
42
- "<%= project_name %>"
43
- end
44
- <%- end -%>
45
48
  <%- if feature_enabled?(Rubiclifier::Feature::DATABASE) -%>
46
49
 
47
50
  def data_directory
@@ -0,0 +1,8 @@
1
+ require "rubiclifier"
2
+
3
+ class Server < Rubiclifier::Server
4
+ def self.hydrate
5
+ set :public_folder, "#{File.expand_path(File.dirname(__FILE__) + "/..")}/public"
6
+ set :port, 5000
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <title><%= project_name %></title>
7
+ </head>
8
+
9
+ <body>
10
+ <h1><%= project_name %></h1>
11
+ </body>
12
+ </html>
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubiclifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Grinstead
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-10 00:00:00.000000000 Z
11
+ date: 2020-07-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email: kyleag@hey.com
15
15
  executables:
16
16
  - rubiclifier
@@ -28,8 +28,10 @@ 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
34
+ - lib/server.rb
33
35
  - lib/setting.rb
34
36
  - project_template/.gitignore
35
37
  - project_template/Gemfile
@@ -39,13 +41,15 @@ files:
39
41
  - project_template/bin/PROJECT_NAME.erb
40
42
  - project_template/lib/PROJECT_NAME.rb.erb
41
43
  - project_template/lib/api.rb
44
+ - project_template/lib/server.rb
42
45
  - project_template/migrations.rb
46
+ - project_template/public/index.html.erb
43
47
  homepage: https://rubygems.org/gems/rubiclifier
44
48
  licenses:
45
49
  - MIT
46
50
  metadata:
47
51
  source_code_uri: https://github.com/MrGrinst/rubiclifier
48
- post_install_message:
52
+ post_install_message:
49
53
  rdoc_options: []
50
54
  require_paths:
51
55
  - lib
@@ -60,9 +64,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
64
  - !ruby/object:Gem::Version
61
65
  version: '0'
62
66
  requirements: []
63
- rubyforge_project:
67
+ rubyforge_project:
64
68
  rubygems_version: 2.7.6.2
65
- signing_key:
69
+ signing_key:
66
70
  specification_version: 4
67
71
  summary: Easily spin up new Ruby CLI applications with built-in backgrounding and
68
72
  data storage.