fcl_rails_daemon 2.1.3 → 2.2.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
  SHA1:
3
- metadata.gz: 46d9f55f127a497aefb330e40204df3ad00378cb
4
- data.tar.gz: c99f8fac19da272a9112f2583cf0338d2bce9825
3
+ metadata.gz: 2812e8712e70cd9dcccc4915ed1d0714037eadb5
4
+ data.tar.gz: b2483783251ac74199ac467c0900b6d707992983
5
5
  SHA512:
6
- metadata.gz: 42e400e529858c892534cdeec110a83b3d0181b092e6e572455334d3002dcdefc69f71aa7a09f8aa2e6b7416aadc859d828b73a02da806293dfb85be2cd229df
7
- data.tar.gz: 2894f0d4836839e0e7b9ac4cfa6986629fab0bb5256f829665e064462f401415e5ca2f095edcb2be6cf51b1040e6b89886ef29a4b2cbab9e21c53156adb8fe48
6
+ metadata.gz: 88265935ca8a53b14e7eb9971c726aa24d37dc8eeaad5b6949f7536f42c360eed7ff15d7e5e3b9811d1795fbc11f370951f8661351318c138f6fb31e56dab1c5
7
+ data.tar.gz: 168f9ef00edf03fa6d78cbb1ee00ed14e9de2430951c5a6c5c53edf0b6cf4f070498d4e4e4589c996c945b1680ecc2feb2127973bcbca8ccf4ff7ade6c1d53e3
data/README.md CHANGED
@@ -27,9 +27,9 @@ After installation you need to create the directories and configuration files fo
27
27
 
28
28
  Will be created:
29
29
 
30
- * *config/fcld_rails_daemon.rb* (File where the commands are recorded)
31
- * *tmp/pids/fcld.yml* (Pids file where the commands are recorded)
32
- * *lib/fcl_rails_daemon/command_sample.rb* (A command template)
30
+ * **config/fcld_rails_daemon.rb** (File where the commands are recorded)
31
+ * **tmp/pids/fcld.yml** (Pids file where the commands are recorded)
32
+ * **lib/fcl_rails_daemon/command_sample.rb** (A command template)
33
33
 
34
34
 
35
35
  ## How to use?
@@ -38,9 +38,15 @@ Will be created:
38
38
 
39
39
  $ fcld --create my_first_command
40
40
 
41
- * Adds a command in lib/fcl_rails_daemon
42
- * Records the command in config/fcl_rails_daemon.rb
41
+ * Add the command file in **lib/fcl_rails_daemon**
42
+ * Records the command in **config/fcl_rails_daemon.rb**
43
43
 
44
+ #### [--destroy] Destroy a command
45
+
46
+ $ fcld --destroy my_first_command
47
+
48
+ * Remove the command file in **lib/fcl_rails_daemon**
49
+ * Remove record of the command in **config/fcl_rails_daemon.rb**
44
50
 
45
51
  #### [--help] Displays the manual for commands and options
46
52
 
data/bin/fcld CHANGED
@@ -1,78 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
- require 'fileutils'
3
- require 'fcl_rails_daemon/config'
2
+ require 'fcl_rails_daemon/setup'
4
3
 
5
- base = DAEMON_ROOT
6
- config_dir = File.join(base, DAEMON_CONFIG['config_path'])
7
- FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
8
- commands_file = File.join(config_dir, 'fcl_rails_daemon.rb')
4
+ setup = FclRailsDaemon::Setup.new
9
5
 
10
6
  if ARGV.include? "--configure"
11
- commands_file_content = <<-FILE
12
- # To register commands use the FclRailsDaemon::Recorder class
13
- # :command is the command name
14
- # :class_reference is the class to which it is
15
- #
16
- # FclRailsDaemon::Recorder.add(command: 'command_sample', class_reference: CommandSample)
17
-
18
- FILE
19
-
20
- File.open(commands_file, 'wb') {|f| f.write(commands_file_content) } unless File.exist?(commands_file)
21
-
22
- command_sample_content = <<-FILE
23
- class CommandSample < FclRailsDaemon::Daemon
24
-
25
- # Is necessary to implement the method "initialize"
26
- def initialize
27
- # Set the parameter "command" (name that will be referenced in the command entered in the terminal)
28
- # The parameter "log" is optional but suggest it is set a log for each command to prevent many commands write on deafult log (if you have many commands in your application)
29
- # The parameter "process_name" is optional (is the name that will be assigned to the process)
30
- super(command: "command_sample", log: "log/command_sample.log", process_name: "command_sample")
31
- end
32
-
33
- # Is necessary to implement the method "self.help"
34
- def self.help
35
- # Should return a hash with " description" and "example"
36
- {
37
- description: "This command is a sample - Run every 1 minute",
38
- sample: ["--command command_sample |start|stop|restart|status|"]
39
- }
40
- end
41
-
42
- # Is necessary to implement the method "run"
43
- def run
44
- # Call the run method of the parent class (super) through a block that will contain your code
45
- # You can optionally provide the parameter "loop" and "sleep" for the command to run repeatedly
46
- super(loop: true, sleep:10) do
47
- puts "Running "+ @command +" :)"
48
- end
49
- end
50
-
51
- end
52
-
53
- FILE
54
-
55
- commands_dir = DAEMON_CONFIG['command_path']
56
- commands_dir = File.join(base, commands_dir)
57
- FileUtils.mkdir_p(commands_dir) unless File.directory?(commands_dir)
58
-
59
- command_file = File.join(commands_dir, 'command_sample.rb')
60
- File.open(command_file, 'wb') {|f| f.write(command_sample_content) } unless File.exists?(command_file)
61
-
62
- log_dir = "log"
63
- log_dir = File.join(base, log_dir)
64
- FileUtils.mkdir_p(log_dir) unless File.directory?(log_dir)
65
-
66
- pids_dir = File.join(base, "tmp/pids")
67
- pids_file = File.join(base, DAEMON_CONFIG['pids_file'])
68
- FileUtils.mkdir_p(pids_dir) unless File.directory?(pids_dir)
69
- File.open(pids_file, 'wb') {|f| f << "fcl_rails_daemon:" } unless File.exist?(pids_file)
70
-
7
+ setup.configure
71
8
  puts " ༼ つ ◕_◕ ༽つ OK... Gem has been set!!! "
72
9
  exit
73
10
  end
74
11
 
75
- unless File.exist?(commands_file)
12
+ unless File.exist?(setup.config_file)
76
13
  puts " ༼ つ ◕_◕ ༽つ OOOPS... Gem has not yet been set. To set run 'fcld --configure' "
77
14
  exit
78
15
  end
@@ -83,13 +20,15 @@ if ARGV.include?("--env")
83
20
  ENV['RAILS_ENV'] = env
84
21
  end
85
22
 
86
- #check if exist rails environment file
87
23
  env_file = File.join(DAEMON_ROOT, "config", "environment.rb")
88
- raise " ༼ つ ◕_◕ ༽つ OOOPS... Could not find the Rails environment file. " unless File.exist? env_file
89
- require env_file
24
+ if File.exist? env_file
25
+ require env_file
26
+ else
27
+ puts " ༼ つ ◕_◕ ༽つ OOOPS... Could not find the Rails environment file. "
28
+ end
90
29
 
30
+ # load gem
91
31
  require 'fcl_rails_daemon'
92
- require 'fcl_rails_daemon/version'
93
32
 
94
33
  begin
95
34
  FclRailsDaemon::Manager.run(ARGV)
@@ -97,4 +36,3 @@ rescue => e
97
36
  puts e.message
98
37
  e.backtrace.each {|l| puts l}
99
38
  end
100
-
@@ -19,12 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.required_ruby_version = '>= 2.0.0'
20
20
 
21
21
  spec.summary = %q{This gem was developed to facilitate the creation and management processes in rails projects.}
22
- spec.description = %q{This gem creation commands makes it easy ( Ruby scripts) to run in the background ( daemon ). \n
23
- It has a friendly CLI to manage processes related to commands.}
22
+ spec.description = %q{This gem creation commands makes it easy ( Ruby scripts) to run in the background ( daemon ). It has a friendly CLI to manage processes related to commands.}
24
23
 
25
24
  spec.add_dependency "bundler"
26
25
  spec.add_dependency "activesupport"
27
- spec.add_dependency "rake"
28
26
  spec.add_dependency "daemons", "~> 1.2"
29
27
 
30
28
  spec.add_development_dependency "rspec"
@@ -1,15 +1,13 @@
1
- require "rails"
2
- require "fcl_rails_daemon/version"
3
- require "fcl_rails_daemon/config"
4
- require 'fileutils'
1
+ require "fcl_rails_daemon/setup"
5
2
  require 'yaml'
6
3
  require 'daemons'
7
- require 'active_support'
8
4
 
9
5
  module FclRailsDaemon end
10
- require_relative "core/daemon"
11
- require_relative "core/recorder.rb"
12
- require_relative "core/manager.rb"
6
+
7
+ require "fcl_rails_daemon/core/command_line"
8
+ require "fcl_rails_daemon/core/daemon"
9
+ require "fcl_rails_daemon/core/recorder.rb"
10
+ require "fcl_rails_daemon/core/manager.rb"
13
11
 
14
12
  # Load commands files
15
13
  command_dir = File.join(DAEMON_ROOT, DAEMON_CONFIG['command_path'])
@@ -18,4 +16,3 @@ raise " ༼ つ ◕_◕ ༽つ OOOPS... Could not find the command directory. Ru
18
16
  Dir[File.join(command_dir, "**/*.rb")].each {|file| load file }
19
17
 
20
18
  load File.join(DAEMON_ROOT, "config", "fcl_rails_daemon.rb")
21
-
@@ -1,5 +1,5 @@
1
- DAEMON_ROOT = File.expand_path("")
2
- DAEMON_CONFIG = {
1
+ DAEMON_ROOT ||= File.expand_path("")
2
+ DAEMON_CONFIG ||= {
3
3
  "pids_file" => 'tmp/pids/fcld.yml',
4
4
  "default_log" => 'log/fcld.log',
5
5
  "command_prefix" => 'fcld',
@@ -0,0 +1,92 @@
1
+ module FclRailsDaemon
2
+ class CommandGenerator
3
+
4
+ @@file_record ||= File.join(DAEMON_ROOT, DAEMON_CONFIG['register_file'] )
5
+
6
+ def self.file_record
7
+ @@file_record
8
+ end
9
+
10
+ def self.inflect(command)
11
+ @@command_camel = ActiveSupport::Inflector.camelize(command)
12
+ @@command_undescore = ActiveSupport::Inflector.underscore(command)
13
+ end
14
+
15
+ def self.create(command)
16
+ inflect command
17
+ content = get_content(command)
18
+ file = File.join(DAEMON_ROOT, DAEMON_CONFIG['command_path'], @@command_undescore + '.rb' )
19
+ if File.exist?(file)
20
+ puts " ༼ つ ◕_◕ ༽つ OOOPS... Command already exists. "
21
+ else
22
+ File.open(file, 'wb') {|f| f.write(content) }
23
+ register(command)
24
+ puts " ༼ つ ◕_◕ ༽つ OK... Command created and registered!!! "
25
+ end
26
+ end
27
+
28
+ def self.register(command)
29
+ inflect command
30
+ content = "\nFclRailsDaemon::Recorder.add(command: '#{@@command_undescore}', class_reference: #{@@command_camel})"
31
+ File.open(@@file_record, 'a+') {|f| f << content }
32
+ end
33
+
34
+ def self.get_content(command)
35
+ inflect command
36
+ content = <<-FILE
37
+ class #{@@command_camel} < FclRailsDaemon::Daemon
38
+
39
+ # Is necessary to implement the method "initialize"
40
+ def initialize
41
+ # Set the parameter "command" (name that will be referenced in the command entered in the terminal)
42
+ # The parameter "log" is optional but suggest it is set a log for each command to prevent many commands write on deafult log (if you have many commands in your application)
43
+ # The parameter "process_name" is optional (is the name that will be assigned to the process)
44
+ super(command: "#{@@command_undescore}", log: "log/#{@@command_undescore}.log", process_name: "#{@@command_undescore}")
45
+ end
46
+
47
+ # Is necessary to implement the method "self.help"
48
+ def self.help
49
+ # Should return a hash with " description" and "example"
50
+ {
51
+ description: "This command is a sample, write here a valid description - Run every 10 seconds",
52
+ sample: ["--command #{@@command_undescore} |start|stop|restart|status|"]
53
+ }
54
+ end
55
+
56
+ # Is necessary to implement the method "run"
57
+ def run
58
+ # Call the run method of the parent class (super) through a block that will contain your code
59
+ # You can optionally provide the parameter "loop" and "sleep" for the command to run repeatedly
60
+ super(loop: true, sleep:10) do
61
+ puts "Running "+ @command +" :)"
62
+ end
63
+ end
64
+
65
+ end
66
+ FILE
67
+ content
68
+ end
69
+
70
+ def self.destroy(command)
71
+ inflect command
72
+ file = File.join(DAEMON_ROOT, DAEMON_CONFIG['command_path'], @@command_undescore + '.rb' )
73
+ if File.exist?(file)
74
+ FileUtils.rm_rf(file)
75
+ unregister(command)
76
+ puts " ༼ つ ◕_◕ ༽つ OK... Command was destroyed!!! "
77
+ else
78
+ puts " ༼ つ ◕_◕ ༽つ OOOPS... Command does not exist. "
79
+ end
80
+ end
81
+
82
+ def self.unregister(command)
83
+ inflect command
84
+ new_lines = ''
85
+ IO.readlines(@@file_record).map do |line|
86
+ new_lines += line unless line.match(/#{@@command_undescore}/)
87
+ end
88
+ File.open(@@file_record, 'w') {|f| f.puts new_lines }
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,10 @@
1
+ module FclRailsDaemon
2
+ class CommandLine
3
+
4
+ def self.parse_option(option, argv)
5
+ i = argv.index(option) + 1
6
+ argv[i]
7
+ end
8
+
9
+ end
10
+ end
@@ -7,25 +7,19 @@ module FclRailsDaemon
7
7
  self.logs if argv.include?('--logs')
8
8
  self.set_process_name(argv) if (argv.include?('--command') && argv.include?('--process_name'))
9
9
  self.create_command(argv) if argv.include?('--create')
10
+ self.destroy_command(argv) if argv.include?('--destroy')
10
11
  self.help(ARGV) unless self.valid?(argv)
11
12
 
12
13
  command ||= nil
14
+ command = CommandLine.parse_option('--command', argv) if argv.include?('--command')
13
15
  action = argv.last
14
- if argv.include?('--command')
15
- i = argv.index('--command') + 1
16
- command = argv[i]
17
- end
18
16
  registered = self.get_registered command
19
17
  registered.each { |command| command.send(action) }
20
18
  end
21
19
 
22
20
  def self.help(argv)
23
- action = argv.last
24
21
  command ||= nil
25
- if (argv.include?('--command') && argv.include?('--help'))
26
- i = argv.index('--command') + 1
27
- command = argv[i]
28
- end
22
+ command = CommandLine.parse_option('--command', argv) if (argv.include?('--command') && argv.include?('--help'))
29
23
  helpers = self.get_helpers(command)
30
24
  self.show_helpers helpers
31
25
  end
@@ -35,7 +29,6 @@ module FclRailsDaemon
35
29
  end
36
30
 
37
31
  private
38
-
39
32
  def self.get_registered(command = nil)
40
33
  list = []
41
34
  @@registered ||= {}
@@ -82,6 +75,8 @@ module FclRailsDaemon
82
75
  puts " #{prefix} --env production start\n\n"
83
76
  puts " [--create] to create a new command"
84
77
  puts " #{prefix} --create my_first_command\n\n"
78
+ puts " [--destroy] to destroy a command"
79
+ puts " #{prefix} --destroy my_first_command\n\n"
85
80
  puts " [--command] to control specific command"
86
81
  puts " #{prefix} --command sample_command start\n"
87
82
  puts " [--process_name] to define a name for the process"
@@ -105,83 +100,32 @@ module FclRailsDaemon
105
100
  end
106
101
 
107
102
  def self.create_command(argv)
108
- i = argv.index('--create') + 1
109
- command = argv[i]
103
+ command = CommandLine.parse_option('--create', argv)
110
104
  unless command
111
105
  puts " ༼ つ ◕_◕ ༽つ OOOPS... The command name has not been defined "
112
106
  exit
113
107
  end
114
- if Daemon.commands_valid.include? command
115
- puts " ༼ つ ◕_◕ ༽つ OOOPS... The command can not be named #{command} "
116
- exit
117
- end
118
-
119
- command_camel = ActiveSupport::Inflector.camelize(command)
120
- command_undescore = ActiveSupport::Inflector.underscore(command)
121
-
122
- content = <<-FILE
123
- class #{command_camel} < FclRailsDaemon::Daemon
124
-
125
- # Is necessary to implement the method "initialize"
126
- def initialize
127
- # Set the parameter "command" (name that will be referenced in the command entered in the terminal)
128
- # The parameter "log" is optional but suggest it is set a log for each command to prevent many commands write on deafult log (if you have many commands in your application)
129
- # The parameter "process_name" is optional (is the name that will be assigned to the process)
130
- super(command: "#{command_undescore}", log: "log/#{command_undescore}.log", process_name: "#{command_undescore}")
131
- end
132
-
133
- # Is necessary to implement the method "self.help"
134
- def self.help
135
- # Should return a hash with " description" and "example"
136
- {
137
- description: "This command is a sample - Run every 1 minute",
138
- sample: ["--command #{command_undescore} |start|stop|restart|status|"]
139
- }
140
- end
141
-
142
- # Is necessary to implement the method "run"
143
- def run
144
- # Call the run method of the parent class (super) through a block that will contain your code
145
- # You can optionally provide the parameter "loop" and "sleep" for the command to run repeatedly
146
- super(loop: true, sleep:10) do
147
- puts "Running "+ @command +" :)"
108
+ validate_command_name(command)
109
+ FclRailsDaemon::CommandGenerator.create(command)
110
+ exit
148
111
  end
149
- end
150
-
151
- end
152
- FILE
153
-
154
- file = File.join(DAEMON_ROOT, DAEMON_CONFIG['command_path'], command_undescore + '.rb' )
155
112
 
156
- if File.exist?(file)
157
- puts " つ ◕_◕ ༽つ OOOPS... Command already exists. "
158
- else
159
- File.open(file, 'wb') {|f| f.write(content) }
160
-
161
- file_record = File.join(DAEMON_ROOT, DAEMON_CONFIG['register_file'] )
162
- content_to_register = "\nFclRailsDaemon::Recorder.add(command: '#{command_undescore}', class_reference: #{command_camel})"
163
- File.open(file_record, 'a+') {|f| f << content_to_register }
164
-
165
- puts " ༼ つ ◕_◕ ༽つ OK... Command created and registered!!! "
166
- puts "New command: #{file} "
167
- puts "Commands registered: #{file_record} "
113
+ def self.destroy_command(argv)
114
+ command = CommandLine.parse_option('--destroy', argv)
115
+ unless command
116
+ puts " ◕_◕ ༽つ OOOPS... The command name has not been defined "
117
+ exit
168
118
  end
119
+ validate_command_name command
120
+ FclRailsDaemon::CommandGenerator.destroy(command)
169
121
  exit
170
122
  end
171
123
 
172
124
  def self.set_process_name(argv)
173
- i = argv.index('--command') + 1
174
- command = argv[i]
175
- i = argv.index('--process_name') + 1
176
- name = argv[i]
177
- if Daemon.commands_valid.include? command
178
- puts " ༼ つ ◕_◕ ༽つ OOOPS... The command can not be named #{command} "
179
- exit
180
- end
181
- if Daemon.commands_valid.include? name
182
- puts " ༼ つ ◕_◕ ༽つ OOOPS... The process can not be named #{command} "
183
- exit
184
- end
125
+ command = CommandLine.parse_option('--command', argv)
126
+ name = CommandLine.parse_option('--process_name', argv)
127
+ validate_command_name command
128
+ validate_process_name name
185
129
  registered = self.get_registered command
186
130
  registered.each { |command| command.process_name = name }
187
131
  end
@@ -197,5 +141,18 @@ end
197
141
  exit
198
142
  end
199
143
 
144
+ def self.validate_command_name(command)
145
+ if Daemon.commands_valid.include? command
146
+ puts " ༼ つ ◕_◕ ༽つ OOOPS... The command can not be named #{command} "
147
+ exit
148
+ end
149
+ end
150
+
151
+ def self.validate_process_name(process_name)
152
+ if Daemon.commands_valid.include? process_name
153
+ puts " ༼ つ ◕_◕ ༽つ OOOPS... The process can not be named #{process_name} "
154
+ exit
155
+ end
156
+ end
200
157
  end
201
158
  end
@@ -0,0 +1,62 @@
1
+ require 'fileutils'
2
+ require 'active_support'
3
+ require 'fcl_rails_daemon/config'
4
+ require 'fcl_rails_daemon/core/command_generator'
5
+
6
+ module FclRailsDaemon
7
+ class Setup
8
+
9
+ attr_reader :base, :config_dir, :config_file, :commands_dir, :command_sample_file, :logs_dir, :pids_dir, :pids_file
10
+
11
+ def initialize
12
+ @base = DAEMON_ROOT
13
+ @config_dir = File.join(@base, DAEMON_CONFIG['config_path'])
14
+ @config_file = File.join(@config_dir, 'fcl_rails_daemon.rb')
15
+
16
+ @commands_dir = File.join(@base, DAEMON_CONFIG['command_path'])
17
+ @command_sample_file = File.join(@commands_dir, 'command_sample.rb')
18
+
19
+ @logs_dir = File.join(@base, "log")
20
+
21
+ @pids_dir = File.join(@base, "tmp/pids")
22
+ @pids_file = File.join(@base, DAEMON_CONFIG['pids_file'])
23
+ end
24
+
25
+ def configure
26
+ create_config
27
+ create_command_sample
28
+ create_pids
29
+ create_logs
30
+ end
31
+
32
+ def create_config
33
+ content = <<-FILE
34
+ # To register commands use the FclRailsDaemon::Recorder class
35
+ # :command is the command name
36
+ # :class_reference is the class to which it is
37
+ #
38
+ # FclRailsDaemon::Recorder.add(command: 'command_sample', class_reference: CommandSample)
39
+
40
+ FILE
41
+ FileUtils.mkdir_p(@config_dir) unless File.directory?(@config_dir)
42
+ File.open(@config_file, 'wb') {|f| f.write(content) } unless File.exist?(@config_file)
43
+ end
44
+
45
+ def create_command_sample
46
+ content = FclRailsDaemon::CommandGenerator.get_content("command_sample")
47
+ FileUtils.mkdir_p(@commands_dir) unless File.directory?(@commands_dir)
48
+ File.open(@command_sample_file, 'wb') {|f| f.write(content) } unless File.exists?(@command_sample_file)
49
+ end
50
+
51
+ def create_pids
52
+ FileUtils.mkdir_p(@pids_dir) unless File.directory?(@pids_dir)
53
+ File.open(@pids_file, 'wb') {|f| f << "fcl_rails_daemon:" } unless File.exist?(@pids_file)
54
+ end
55
+
56
+ def create_logs
57
+ FileUtils.mkdir_p(@logs_dir) unless File.directory?(@logs_dir)
58
+ end
59
+
60
+
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module FclRailsDaemon
2
- VERSION = "2.1.3"
2
+ VERSION ||= "2.2.0"
3
3
  end
@@ -1,11 +1,102 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FclRailsDaemon do
4
- it 'has a version number' do
5
- expect(FclRailsDaemon::VERSION).not_to be nil
4
+
5
+ before(:each) do
6
+ @setup = FclRailsDaemon::Setup.new
7
+ @setup.configure
8
+ end
9
+
10
+ after(:each) do
11
+ FileUtils.rm_rf @setup.config_dir
12
+ FileUtils.rm_rf @setup.logs_dir
13
+ FileUtils.rm_rf @setup.pids_dir
14
+ FileUtils.rm_rf @setup.command_sample_file
15
+ end
16
+
17
+ describe "Environment Variables" do
18
+ it 'has a version number' do
19
+ expect(FclRailsDaemon::VERSION).not_to be nil
20
+ end
21
+ context "Config" do
22
+ it 'has a root path defined' do
23
+ expect(DAEMON_ROOT).instance_of? String
24
+ end
25
+ it 'has config collection defined' do
26
+ expect(DAEMON_CONFIG).instance_of? Hash
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#{FclRailsDaemon::CommandGenerator.inspect}" do
32
+ subject(:create_command) do
33
+ FclRailsDaemon::CommandGenerator.create "new_command"
34
+ file = File.join(@setup.commands_dir, "new_command.rb")
35
+ end
36
+ subject(:remove_command) do
37
+ file = File.join(@setup.commands_dir, "new_command.rb")
38
+ FileUtils.rm_rf(file) if File.exist? file
39
+ end
40
+ it 'creation of the a command' do
41
+ path = create_command
42
+ expect(File.exist? path).to eq(true)
43
+ remove_command
44
+ end
45
+
46
+ subject(:register_command) do
47
+ FclRailsDaemon::CommandGenerator.register "new_command"
48
+ record = "FclRailsDaemon::Recorder.add(command: 'new_command', class_reference: NewCommand)"
49
+ end
50
+ it 'register a command' do
51
+ record = register_command
52
+ content = File.read(FclRailsDaemon::CommandGenerator.file_record)
53
+ expect(content).to include record
54
+ end
55
+
56
+ subject(:unregister_command) { FclRailsDaemon::CommandGenerator.unregister "new_command" }
57
+ it 'unregister a command' do
58
+ record = register_command
59
+ FclRailsDaemon::CommandGenerator.unregister "new_command"
60
+ content = File.read(FclRailsDaemon::CommandGenerator.file_record)
61
+ expect(content).not_to include record
62
+ end
6
63
  end
7
64
 
8
- it 'does something useful' do
9
- expect(false).to eq(false)
65
+ describe "#{FclRailsDaemon::Recorder}" do
66
+ it "register new command" do
67
+ FclRailsDaemon::Recorder.add(command: 'new_command', class_reference: String )
68
+ expect(FclRailsDaemon::Recorder.load).to include "new_command"
69
+ end
10
70
  end
71
+
72
+ describe "#{FclRailsDaemon::Daemon}" do
73
+ let(:new_command) do
74
+ FclRailsDaemon::CommandGenerator.create "new_command"
75
+ file = File.join(@setup.commands_dir, "new_command.rb")
76
+ end
77
+ let(:destroy_new_command) { FclRailsDaemon::CommandGenerator.destroy "new_command" }
78
+ subject(:start_new_command) { `#{"bundle exec fcld --command new_command start"}` }
79
+ subject(:stop_new_command) { `#{"bundle exec fcld --command new_command stop"}` }
80
+
81
+ it "start a command" do
82
+ new_command
83
+ output = start_new_command
84
+ expect(output).to include("new_command", "started")
85
+
86
+ stop_new_command
87
+ destroy_new_command
88
+ end
89
+
90
+ it "stop a command" do
91
+ new_command
92
+ start_new_command
93
+ output = stop_new_command
94
+ expect(output).to include("new_command", "stopped")
95
+
96
+ destroy_new_command
97
+ end
98
+ end
99
+
100
+
101
+
11
102
  end
@@ -1,2 +1,29 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'fcl_rails_daemon/setup'
4
+ (FclRailsDaemon::Setup.new).configure
2
5
  require 'fcl_rails_daemon'
6
+
7
+ RSpec.configure do |config|
8
+ config.before(:all, &:silence_output)
9
+ config.after(:all, &:enable_output)
10
+ end
11
+
12
+ public
13
+ # Redirects stderr and stdout to /dev/null.
14
+ def silence_output
15
+ @orig_stderr = $stderr
16
+ @orig_stdout = $stdout
17
+
18
+ # redirect stderr and stdout to /dev/null
19
+ $stderr = File.new('/dev/null', 'w')
20
+ $stdout = File.new('/dev/null', 'w')
21
+ end
22
+
23
+ # Replace stdout and stderr so anything else is output correctly.
24
+ def enable_output
25
+ $stderr = @orig_stderr
26
+ $stdout = @orig_stdout
27
+ @orig_stderr = nil
28
+ @orig_stdout = nil
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fcl_rails_daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: daemons
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,9 +66,8 @@ dependencies:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
- description: |-
84
- This gem creation commands makes it easy ( Ruby scripts) to run in the background ( daemon ). \n
85
- It has a friendly CLI to manage processes related to commands.
69
+ description: This gem creation commands makes it easy ( Ruby scripts) to run in the
70
+ background ( daemon ). It has a friendly CLI to manage processes related to commands.
86
71
  email:
87
72
  - w-osilva@hotmail.com
88
73
  executables:
@@ -101,13 +86,15 @@ files:
101
86
  - bin/console
102
87
  - bin/fcld
103
88
  - bin/setup
104
- - fcl_rails_daemon-2.1.2.gem
105
89
  - fcl_rails_daemon.gemspec
106
- - lib/core/daemon.rb
107
- - lib/core/manager.rb
108
- - lib/core/recorder.rb
109
90
  - lib/fcl_rails_daemon.rb
110
91
  - lib/fcl_rails_daemon/config.rb
92
+ - lib/fcl_rails_daemon/core/command_generator.rb
93
+ - lib/fcl_rails_daemon/core/command_line.rb
94
+ - lib/fcl_rails_daemon/core/daemon.rb
95
+ - lib/fcl_rails_daemon/core/manager.rb
96
+ - lib/fcl_rails_daemon/core/recorder.rb
97
+ - lib/fcl_rails_daemon/setup.rb
111
98
  - lib/fcl_rails_daemon/version.rb
112
99
  - spec/fcl_rails_daemon_spec.rb
113
100
  - spec/spec_helper.rb
Binary file