Class: New::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/new/task.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_config) ⇒ Task

Returns a new instance of Task.



8
9
10
11
# File 'lib/new/task.rb', line 8

def initialize project_config
  @project_config = project_config
  run
end

Class Method Details

.inherited(task_class) ⇒ Object



4
5
6
# File 'lib/new/task.rb', line 4

def self.inherited task_class
  task_class.name = caller.first[/[a-z_]+?(?=\.rb)/].to_sym
end

.nameObject



16
# File 'lib/new/task.rb', line 16

def self.name; @name; end

.name=(name) ⇒ Object



13
14
15
# File 'lib/new/task.rb', line 13

def self.name= name
  @name = name
end

Instance Method Details

#nameObject



17
# File 'lib/new/task.rb', line 17

def name; self.class.name.to_sym; end

#optionsObject

Return only the options for the given task



35
36
37
38
# File 'lib/new/task.rb', line 35

def options
  default_options = self.class::OPTIONS rescue {}
  @options ||= default_options.deep_merge(project_options[:tasks][name])
end

#project_optionsObject

Return ALL available options



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/new/task.rb', line 21

def project_options
  custom_options = New.custom_config
  all_options = custom_options.deep_merge(@project_config)

  # Groom tasks (prevent tasks from the custom config from polluting the project config)
  all_options[:tasks].each_key do |task|
    all_options[:tasks].delete(task) unless @project_config[:tasks].has_key?(task)
  end

  @project_options ||= all_options
end