Class: ChoresKit::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args) ⇒ Task

Returns a new instance of Task.



7
8
9
10
# File 'lib/chores_kit/chore/task.rb', line 7

def initialize(name, *args)
  @name = name
  @args = args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

rubocop:disable Style/MethodMissing



25
26
27
28
29
30
31
# File 'lib/chores_kit/chore/task.rb', line 25

def method_missing(name, *args)
  attributes = { callable: args, callee: self }

  if name == :sh
    @callable = Executors::Shell.new(name, attributes)
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/chores_kit/chore/task.rb', line 5

def name
  @name
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chores_kit/chore/task.rb', line 12

def run
  raise "Task doesn't have any executors" if @callable.nil?

  puts "Running #{@callable.friendly_name} executor with command #{@callable.command} at #{Time.now}"

  duration = Benchmark.realtime do
    @callable.run!
  end

  puts "Took #{Integer(duration * 1000)}ms to run\n\n"
end