Class: Xronor::DSL::Job
- Inherits:
-
Object
- Object
- Xronor::DSL::Job
- Includes:
- Checker
- Defined in:
- lib/xronor/dsl/job.rb
Instance Method Summary collapse
-
#initialize(frequency, options, &block) ⇒ Job
constructor
A new instance of Job.
- #process_template(template, options) ⇒ Object
- #result ⇒ Object
Methods included from Checker
Constructor Details
#initialize(frequency, options, &block) ⇒ Job
Returns a new instance of Job.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/xronor/dsl/job.rb', line 6 def initialize(frequency, , &block) @frequency = frequency @options = schedule = case frequency when String # cron expression frequency when Symbol, Numeric # DSL (:hour, 1.min, 1.hour, ...) Xronor::DSL::ScheduleConverter.convert(frequency, ) else raise ArgumentError, "Invalid frequency #{frequency}" end @result = OpenStruct.new( description: nil, name: "", schedule: schedule, command: "", ) instance_eval(&block) end |
Instance Method Details
#process_template(template, options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/xronor/dsl/job.rb', line 35 def process_template(template, ) template.gsub(/:\w+/) do |key| before_and_after = [$`[-1..-1], $'[0..0]] option = [key.sub(':', '').to_sym] || key if before_and_after.all? { |c| c == "'" } escape_single_quotes(option) elsif before_and_after.all? { |c| c == '"' } escape_double_quotes(option) else option end end.gsub(/\s+/m, " ").strip end |
#result ⇒ Object
50 51 52 53 |
# File 'lib/xronor/dsl/job.rb', line 50 def result required(:name, @result.name) @result end |