class FeduxOrgStdlib::Rake::Task
This class is mainly used as basis for more specific class like {Shelltask} or {Projecttask}.
@see Rakefile
Attributes
description[R]
@!attribute [r] description
A description for the task
logger[R]
name[R]
@!attribute [r] name
Name of task.
task_arguments[R]
task_block[R]
verbose[R]
@!attribute [r] verbose (true)
Use verbose output. If this is set to true, the task will print the executed spec command to stdout.
working_directory[R]
Public Class Methods
new( description:, name: self.class.to_s.split(/::/).slice(-2..-1).join(':').gsub(/Task$/, '').underscore, arguments: [], define_in_ci_mode: true, activate_ci_mode: false, dependencies: [], &task_block )
click to toggle source
Create task instance
@param [String] description
A description for the task
@param [String] name
The name for the task (including namespace), e.g. namespace1:task1
@param [Array] arguments
Arguments for the task. Look [here](http://viget.com/extend/protip-passing-parameters-to-your-rake-tasks) for a better description on how to use arguments in rake tasks
@param [true,false] define_in_ci_mode
Should the task be defined and therefor available when in Continous Integration (CI)-mode + all needed dependencies (gems etc.)? It is best not to include some rubygems (debugger etc.) when running in CI-mode. CI-mode is detected by looking for a defined environment variable 'CI' (ENV['CI']).
@param [true,false] activate_ci_mode
Activate CI-mode when task is called.
@param [Array] dependencies
An array of other tasks this task depends on.
@yield
A block which is called before the "run_task"-method is called. The parameters it taskes depends on the number of parameters the block can take. If the block is defined which two parameters, it takes two parameters from the paramter 'arguments'.
# File lib/fedux_org_stdlib/rake/task.rb, line 67 def initialize( description:, name: self.class.to_s.split(/::/).slice(-2..-1).join(':').gsub(/Task$/, '').underscore, arguments: [], define_in_ci_mode: true, activate_ci_mode: false, dependencies: [], &task_block ) before_initialize @description = description @task_arguments = Array(arguments) @task_block = task_block @logger = FeduxOrgStdlib::Logging::Logger.new @working_directory = Dir.getwd @activate_ci_mode = activate_ci_mode @define_in_ci_mode = define_in_ci_mode if dependencies.blank? @name = name else @name = { name: Array(dependencies).map(&:to_sym) } end after_initialize define_task unless running_in_ci_mode? define_task if define_in_ci_mode? && running_in_ci_mode? end
Public Instance Methods
include(modules)
click to toggle source
Include module in instance
# File lib/fedux_org_stdlib/rake/task.rb, line 153 def include(modules) modules = Array(modules) modules.each { |m| self.class.include m } end
instance_binding()
click to toggle source
Binding to instance
# File lib/fedux_org_stdlib/rake/task.rb, line 148 def instance_binding binding end
Private Instance Methods
activate_ci_mode()
click to toggle source
Activate ci mode
# File lib/fedux_org_stdlib/rake/task.rb, line 103 def activate_ci_mode ENV['CI'] = 'true' end
activate_ci_mode?()
click to toggle source
Check if continous integration mode is activated
# File lib/fedux_org_stdlib/rake/task.rb, line 141 def activate_ci_mode? @activate_ci_mode == true end
after_initialize()
click to toggle source
Run code after initialize
# File lib/fedux_org_stdlib/rake/task.rb, line 108 def after_initialize; end
before_initialize()
click to toggle source
Run code before initialize
# File lib/fedux_org_stdlib/rake/task.rb, line 111 def before_initialize; end
define_in_ci_mode?()
click to toggle source
Should this task be defined in continous integration mode
# File lib/fedux_org_stdlib/rake/task.rb, line 131 def define_in_ci_mode? @define_in_ci_mode == true end
define_task()
click to toggle source
Define task
# File lib/fedux_org_stdlib/rake/task.rb, line 114 def define_task desc description unless ::Rake.application.last_comment task name, *task_arguments do |_, task_args| activate_ci_mode if activate_ci_mode? RakeFileUtils.__send__(:verbose, verbose) do instance_exec(*[self, task_args].slice(0, task_block.arity), &task_block) if task_block.respond_to? :call run_task verbose end end end
run_task(_verbose)
click to toggle source
Run code if task is executed
# File lib/fedux_org_stdlib/rake/task.rb, line 128 def run_task(_verbose); end
running_in_ci_mode?()
click to toggle source
Check if running in continous integration mode
# File lib/fedux_org_stdlib/rake/task.rb, line 136 def running_in_ci_mode? ENV.key? 'CI' end