Class: Tasks

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

Constant Summary collapse

@@default =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Tasks

Returns a new instance of Tasks.



8
9
10
11
12
# File 'lib/tasks.rb', line 8

def initialize(env = nil)
  @@default = self
  @env = env
  @env = Environment.new if @env.nil?
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



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

def env
  @env
end

Class Method Details

.execute_task(task) ⇒ Object



37
38
39
40
# File 'lib/tasks.rb', line 37

def self.execute_task(task)
  @@default = Tasks.new if @@default.nil?
  @@default.execute_task task
end

Instance Method Details

#execute(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/tasks.rb', line 14

def execute(value)
  if value.respond_to?(:execute)
    value.update if value.respond_to?(:update)
    value.execute
  elsif value.is_a?(String)
    puts `#{value}`
  elsif value.is_a?(Array)
    value.each { |e| execute(e) }
  end
end

#execute_task(task) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tasks.rb', line 25

def execute_task(task)
  if defined?(COMMANDS) && COMMANDS.key?(task)
    puts DELIMITER if defined?(DEBUG)
    puts ":#{task}" unless @env.colorize?
    if @env.colorize?
      require "ansi/code"
      puts ANSI.white + ANSI.bold + ":#{task}" + ANSI.reset if @env.colorize?
    end
    execute(COMMANDS[task])
  end
end