Module: Mattock::TaskMixin
- Includes:
- CascadingDefinition
- Included in:
- FileCreationTask, FileTask, MultiTask, Task
- Defined in:
- lib/mattock/task.rb
Overview
A configurable subclass of Rake::Task, such that you can use a configuration block to change how a common task behaves, while still overriding Rake API methods like Task#needed? and Task#timestamp
Rake Tasks Defined
task = task_class.define_task(*task_args) do action end copy_settings_to(task)
Defined Under Namespace
Modules: ClassMethods
Constant Summary
Constant Summary
Constants included from Configurable
Instance Settings Summary (collapse)
-
- (Object) task_name
The value of setting task_name.
-
- (Object) task_args
The value of setting task_args.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) action
- - (Object) define
-
- (TaskMixin) initialize(*args)
A new instance of TaskMixin.
- - (Object) inspect
- - (Object) resolve_configuration
-
- (Object) task_class
I continue to look for an alternative here.
Methods included from CascadingDefinition
#confirm_configuration, #default_configuration
Methods included from Configurable
#check_required, #copy_settings_to, #nil_fields, #required_fields, #setting, #settings, #setup_defaults, #unset?
Methods included from Configurable::ClassMethods
#copy_settings, #default_values, #included, #missing_required_fields_on, #nested, #nil_fields, #required_fields, #set_defaults_on, #setting, #settings
Class Method Details
+ (Object) included(mod)
22 23 24 25 |
# File 'lib/mattock/task.rb', line 22 def self.included(mod) mod.class_eval{ extend ClassMethods } super end |
Instance Method Details
- (Object) action
44 45 |
# File 'lib/mattock/task.rb', line 44 def action end |
- (Object) define
63 64 65 66 67 68 |
# File 'lib/mattock/task.rb', line 63 def define task = task_class.define_task(*task_args) do action end copy_settings_to(task) end |
- (TaskMixin) initialize(*args)
A new instance of TaskMixin
27 28 29 30 31 32 33 34 |
# File 'lib/mattock/task.rb', line 27 def initialize(*args) configs = args.take_while{|arg| Configurable === arg} @extracted_task_args = args[configs.length..-1] if @extracted_task_args.any?{|arg| Configurable === arg} raise "Mattock::Task classes should be created with parent configs, then Rake task args" end super(*configs) end |
- (Object) inspect
59 60 61 |
# File 'lib/mattock/task.rb', line 59 def inspect "#{self.class.name}: #{self.task_args.inspect}" end |
- (Object) resolve_configuration
36 37 38 39 40 41 42 |
# File 'lib/mattock/task.rb', line 36 def resolve_configuration if @extracted_task_args.empty? self.task_args = [task_name] else self.task_args = @extracted_task_args end end |
- (Object) task_class
I continue to look for an alternative here. The trouble is that deep inside of define_task, Rake actually instantiates the Task - so in wanting to be able to override members of Task, it's hard to get the virtues of CascadingDefinition as well (maybe the virtues could be had without the actual mixin?)
52 53 54 55 56 57 |
# File 'lib/mattock/task.rb', line 52 def task_class return @task_class if @task_class @task_class = Class.new(self.class) do define_method :initialize, Rake::Task.instance_method(:initialize) end end |