Class: CrontabRb::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/crontab_rb/parse.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParse

Returns a new instance of Parse.



7
8
9
10
11
# File 'lib/crontab_rb/parse.rb', line 7

def initialize
  @template     = "cd :path && bundle exec bin/rails runner -e #{Rails.env} ':command' >/dev/null 2>&1"
  @job_template = "/bin/bash -l -c ':job'"
  @path         = Dir.pwd
end

Class Method Details

.from_databaseObject



3
4
5
# File 'lib/crontab_rb/parse.rb', line 3

def self.from_database
  new.call
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/crontab_rb/parse.rb', line 13

def call
  records = Database.all
  return "\n" if records.empty?
  contents = []
  records.each do |record|
    options = record
    options[:type] = record[:time]
    options[:time] = Template::EVERY[options[:time]]
    options[:path] = @path
    job   = process_template(@template, options)
    task  = process_template(@job_template, options.merge(:job => job))
    timer = process_timer(options)
    contents << timer + " " + task + "\n"
  end
  contents.join("\n")
end