Class: Pendulum::DSL::Schedule

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/pendulum/dsl/schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

included

Constructor Details

#initialize(name, &block) ⇒ Schedule

Returns a new instance of Schedule.



7
8
9
10
# File 'lib/pendulum/dsl/schedule.rb', line 7

def initialize(name, &block)
  self.name = name
  self.instance_eval(&block) if block_given?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/pendulum/dsl/schedule.rb', line 5

def name
  @name
end

Instance Method Details

#cron(cron) ⇒ Object



19
20
21
# File 'lib/pendulum/dsl/schedule.rb', line 19

def cron(cron)
  @cron = %i(hourly daily monthly).include?(cron) ? "@#{cron}" : cron
end

#priority(priority) ⇒ Object



23
24
25
# File 'lib/pendulum/dsl/schedule.rb', line 23

def priority(priority)
  @priority = priority.is_a?(Integer) ? priority : priority_id_of(priority)
end

#query_file(path) ⇒ Object



15
16
17
# File 'lib/pendulum/dsl/schedule.rb', line 15

def query_file(path)
  query(File.read(path))
end

#result(type, &block) ⇒ Object



31
32
33
34
# File 'lib/pendulum/dsl/schedule.rb', line 31

def result(type, &block)
  result = Result.new(type, &block)
  @result = result.to_url
end

#result_json(type, hash = {}) ⇒ Object



36
37
38
# File 'lib/pendulum/dsl/schedule.rb', line 36

def result_json(type, hash = {})
  @result = {type: type}.merge(hash).to_json
end

#result_url(url) ⇒ Object



27
28
29
# File 'lib/pendulum/dsl/schedule.rb', line 27

def result_url(url)
  @result = url
end

#to_paramsObject



40
41
42
43
44
45
# File 'lib/pendulum/dsl/schedule.rb', line 40

def to_params
  instance_variables.inject({}) do |params, v|
    params[v.to_s.delete('@').to_sym] = instance_variable_get(v)
    params
  end
end