Class: RailsTasker::TaskFile

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

Constant Summary collapse

UP_STATUS =
'up'.freeze
DOWN_STATUS =
'down'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename: '') ⇒ TaskFile

Returns a new instance of TaskFile.



11
12
13
14
# File 'lib/rails_tasker/task_file.rb', line 11

def initialize(filename: '')
  @filename = filename
  @timestamp, @task_name = parse_filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



16
17
18
# File 'lib/rails_tasker/task_file.rb', line 16

def filename
  @filename
end

#task_nameObject (readonly)

Returns the value of attribute task_name.



16
17
18
# File 'lib/rails_tasker/task_file.rb', line 16

def task_name
  @task_name
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



16
17
18
# File 'lib/rails_tasker/task_file.rb', line 16

def timestamp
  @timestamp
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_tasker/task_file.rb', line 28

def call
  load_object
  output = nil

  unless task_klass.nil?
    output = task_klass.call
    complete_task!

    unload_object
  end

  output
end

#pending?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/rails_tasker/task_file.rb', line 18

def pending?
  @is_pending ||= !timestamp.empty? && !Task.completed_task?(
    version: timestamp
  )
end

#statusObject



24
25
26
# File 'lib/rails_tasker/task_file.rb', line 24

def status
  pending? ? DOWN_STATUS : UP_STATUS
end