Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use "roles" instead of "[on_]server_roles"

  • Loading branch information...
commit ee28226d79b1ca47563443aade0baf190f20e1cc 1 parent e28122b
@cap10morgan cap10morgan authored
View
4 bin/whenever
@@ -32,8 +32,8 @@ OptionParser.new do |opts|
opts.on('-k', '--cut [lines]', 'Cut lines from the top of the cronfile') do |lines|
options[:cut] = lines.to_i if lines
end
- opts.on('-r', '--server-roles [role1,role2]', 'Comma-separated list of server roles to generate cron jobs for') do |roles|
- options[:server_roles] = roles.split(',').map(&:to_sym) if roles
+ opts.on('-r', '--roles [role1,role2]', 'Comma-separated list of server roles to generate cron jobs for') do |roles|
+ options[:roles] = roles.split(',').map(&:to_sym) if roles
end
opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
end.parse!
View
8 lib/whenever/job.rb
@@ -2,14 +2,14 @@
module Whenever
class Job
- attr_reader :at, :server_roles
+ attr_reader :at, :roles
def initialize(options = {})
@options = options
@at = options.delete(:at)
@template = options.delete(:template)
@job_template = options.delete(:job_template) || ":job"
- @server_roles = Array.wrap(options.delete(:on_server_roles))
+ @roles = Array.wrap(options.delete(:roles))
@options[:output] = Whenever::Output::Redirection.new(options[:output]).to_s if options.has_key?(:output)
@options[:environment] ||= :production
@options[:path] = Shellwords.shellescape(@options[:path] || Whenever.path)
@@ -24,8 +24,8 @@ def output
out.gsub(/%/, '\%')
end
- def has_server_role?(role)
- server_roles.empty? || server_roles.include?(role)
+ def has_role?(role)
+ roles.empty? || roles.include?(role)
end
protected
View
10 lib/whenever/job_list.rb
@@ -1,6 +1,6 @@
module Whenever
class JobList
- attr_reader :server_roles
+ attr_reader :roles
def initialize(options)
@jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {}
@@ -11,7 +11,7 @@ def initialize(options)
pre_set(options[:set])
- @server_roles = options[:server_roles] || []
+ @roles = options[:roles] || []
setup_file = File.expand_path('../setup.rb', __FILE__)
setup = File.read(setup_file)
@@ -131,11 +131,11 @@ def cron_jobs
shortcut_jobs = []
regular_jobs = []
- output_all = server_roles.empty?
+ output_all = roles.empty?
@jobs.each do |time, jobs|
jobs.each do |job|
- next unless output_all || server_roles.any? do |r|
- job.has_server_role?(r)
+ next unless output_all || roles.any? do |r|
+ job.has_role?(r)
end
Whenever::Output::Cron.output(time, job) do |cron|
cron << "\n\n"
View
10 test/unit/job_test.rb
@@ -7,13 +7,13 @@ class JobTest < Test::Unit::TestCase
assert_equal 'foo', new_job(:at => 'foo').at
end
- should "return the :on_server_roles set when #server_roles is called" do
- assert_equal ['foo', 'bar'], new_job(:on_server_roles => ['foo', 'bar']).server_roles
+ should "return the :roles set when #roles is called" do
+ assert_equal ['foo', 'bar'], new_job(:roles => ['foo', 'bar']).roles
end
- should "return whether it has a server_role from #has_server_role?" do
- assert new_job(:on_server_roles => 'foo').has_server_role?('foo')
- assert_equal false, new_job(:on_server_roles => 'bar').has_server_role?('foo')
+ should "return whether it has a role from #has_role?" do
+ assert new_job(:roles => 'foo').has_role?('foo')
+ assert_equal false, new_job(:roles => 'bar').has_role?('foo')
end
should "substitute the :task when #output is called" do
Please sign in to comment.
Something went wrong with that request. Please try again.