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
# File 'lib/crontab_rb/parse.rb', line 7

def initialize
  @job_template = ":time /bin/bash -l -c 'cd :path && bundle exec :command'"
  @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



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

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
    out = process_template(@job_template, options)
    out = process_template(out, options)
    contents << out + "\n"
  end
  contents.join("\n")
end