crontab_rb 0.2.1 → 0.2.3

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: 90295009745221e88388bc43c9412b57f01ac563
4
- data.tar.gz: 893850a83ed362887a1cd3ad2418816bdf95dd87
3
+ metadata.gz: 5b60c0a525c46f023908c26bbe2ea37089d5716e
4
+ data.tar.gz: 2f15e35e88fd24da38870480787bfd13786fed87
5
5
  SHA512:
6
- metadata.gz: d66381416963cb2535d4f8fbe328bce0d3c9011081028898441ff2db3fbefaca2818bcf012033c6130268a8d21f8d10c8e9affceae3dd91d4af456e866d40ef8
7
- data.tar.gz: e1727aadc3daed1765517c82e2d72b28e4735db10868ad9eaec7e24b230b84923461ca263d08a3cfca797ca6159da7dde7df8c519976742747563f1d7f8a7e5f
6
+ metadata.gz: 5b83653cf9035dd3cdc15bf4726bb30c145ee9302c20ffa17efbd2bd767e97351ab22b2354d633fa7a2e44161eb13582744ed2f52fde70480d178f04967c6f75
7
+ data.tar.gz: 16492f6abce8b3a0e993fc149ed1d41208cb32cb90f50e236618419bcdc075ee1de168b8e65fb04f0f23d3619673adac218fb48b5ebb4825e8aaa39e5eaf02e5
data/lib/crontab_rb.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "crontab_rb/version"
2
2
  require "crontab_rb/configuration"
3
-
4
3
  module CrontabRb
5
4
  class << self
6
5
  attr_accessor :configuration
@@ -71,7 +71,7 @@ module CrontabRb
71
71
  end
72
72
 
73
73
  def write_crontab
74
- CrontabRb::Write.write_crontab
74
+ Write.write_crontab
75
75
  end
76
76
  end
77
77
  end
@@ -5,7 +5,8 @@ module CrontabRb
5
5
  end
6
6
 
7
7
  def initialize
8
- @job_template = ":time /bin/bash -l -c 'cd :path && bundle exec bin/rails runner -e #{Rails.env} ':command''"
8
+ @template = "cd :path && bundle exec bin/rails runner -e production ':command'"
9
+ @job_template = "/bin/bash -l -c ':job'"
9
10
  @path = Dir.pwd
10
11
  end
11
12
 
@@ -18,30 +19,31 @@ module CrontabRb
18
19
  options[:type] = record[:time]
19
20
  options[:time] = Template::EVERY[options[:time]]
20
21
  options[:path] = @path
21
- out = process_template(@job_template, options)
22
- out = process_template(out, options)
23
- contents << out + "\n"
22
+ job = process_template(@template, options)
23
+ task = process_template(@job_template, options.merge(:job => job))
24
+ timer = process_timer(options)
25
+ contents << timer + " " + task + "\n"
24
26
  end
25
27
  contents.join("\n")
26
28
  end
27
29
 
28
30
  protected
29
31
 
32
+ def process_timer(options)
33
+ options[:time].gsub(/:\w+/) do |key|
34
+ if options[:type].to_i/60 <= 1
35
+ options[:at].to_i
36
+ else
37
+ t = options[:at].to_i*60
38
+ Time.at(t).utc.strftime("%M %H")
39
+ end
40
+ end.gsub(/\s+/m, " ").strip
41
+ end
42
+
30
43
  def process_template(template, options)
31
44
  template.gsub(/:\w+/) do |key|
32
45
  before_and_after = [$`[-1..-1], $'[0..0]]
33
- key_symbol = key.sub(':', '').to_sym
34
- option = ''
35
- if key_symbol === :at
36
- if options[:type].to_i/60 <= 1
37
- option = options[:at].to_i
38
- else
39
- t = options[:at].to_i*60
40
- option = Time.at(t).utc.strftime("%M %H")
41
- end
42
- else
43
- option = options[key_symbol] || key
44
- end
46
+ option = options[key.sub(':', '').to_sym] || key
45
47
 
46
48
  if before_and_after.all? { |c| c == "'" }
47
49
  escape_single_quotes(option)
@@ -1,3 +1,3 @@
1
1
  module CrontabRb
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crontab_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nguyen Anh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler