Class: Capistrano::Cron::JobList
- Inherits:
-
Object
- Object
- Capistrano::Cron::JobList
- Defined in:
- lib/capistrano/cron/job_list.rb
Instance Attribute Summary collapse
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #env(variable, value) ⇒ Object
- #every(frequency, options = {}) ⇒ Object
- #generate_cron_output ⇒ Object
-
#initialize(options) ⇒ JobList
constructor
A new instance of JobList.
- #job_type(name, template) ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #set(variable, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ JobList
Returns a new instance of JobList.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/capistrano/cron/job_list.rb', line 9 def initialize() @jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {} if .is_a? String = {string: } end pre_set([:set]) set(:bundle_command, [:bundle_command]) if [:bundle_command] set(:path, [:path]) if [:path] set(:environment, [:environment].to_s) if [:environment] set(:environment_variable, "RAILS_ENV") @roles = [:roles] || [] setup_file = File.("../setup.rb", __FILE__) setup = File.read(setup_file) schedule = if [:string] [:string] elsif [:file] File.read([:file]) end instance_eval(setup, setup_file) instance_eval(schedule, [:file] || "<eval>") end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
44 45 46 |
# File 'lib/capistrano/cron/job_list.rb', line 44 def method_missing(name, *args, &block) @set_variables.has_key?(name) ? @set_variables[name] : super end |
Instance Attribute Details
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
7 8 9 |
# File 'lib/capistrano/cron/job_list.rb', line 7 def roles @roles end |
Instance Method Details
#env(variable, value) ⇒ Object
52 53 54 |
# File 'lib/capistrano/cron/job_list.rb', line 52 def env(variable, value) @env[variable.to_s] = value end |
#every(frequency, options = {}) ⇒ Object
56 57 58 59 60 |
# File 'lib/capistrano/cron/job_list.rb', line 56 def every(frequency, = {}) @current_time_scope = frequency @options = yield end |
#generate_cron_output ⇒ Object
82 83 84 |
# File 'lib/capistrano/cron/job_list.rb', line 82 def generate_cron_output [environment_variables, cron_jobs].compact.join end |
#job_type(name, template) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/capistrano/cron/job_list.rb', line 62 def job_type(name, template) singleton_class.class_eval do define_method(name) do |task, *args| = {task: task, template: template} .merge!(args[0]) if args[0].is_a? Hash [:mailto] ||= @options.fetch(:mailto, :default_mailto) # :cron_log was an old option for output redirection, it remains for backwards compatibility [:output] = ([:cron_log] || @cron_log) if defined?(@cron_log) || .has_key?(:cron_log) # :output is the newer, more flexible option. [:output] = @output if defined?(@output) && !.has_key?(:output) @jobs[.fetch(:mailto)] ||= {} @jobs[.fetch(:mailto)][@current_time_scope] ||= [] @jobs[.fetch(:mailto)][@current_time_scope] << Capistrano::Cron::Job.new(@options.merge(@set_variables).merge()) end end end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
48 49 50 |
# File 'lib/capistrano/cron/job_list.rb', line 48 def respond_to_missing?(name, include_private = false) @set_variables.has_key?(name) || super end |
#set(variable, value) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/capistrano/cron/job_list.rb', line 36 def set(variable, value) variable = variable.to_sym return if @pre_set_variables[variable] instance_variable_set(:"@#{variable}", value) @set_variables[variable] = value end |