class SharedTasks::Task
Public Class Methods
file_date()
click to toggle source
# File lib/shared_tasks.rb, line 138 def file_date @file.split("_").shift end
file_name()
click to toggle source
# File lib/shared_tasks.rb, line 134 def file_name @file.split("_").drop(1).join("_").split(".").remove_last.first end
file_route()
click to toggle source
# File lib/shared_tasks.rb, line 130 def file_route "lib/shared_tasks/#{@file}" end
load_and_run_task(task = file_name)
click to toggle source
# File lib/shared_tasks.rb, line 96 def load_and_run_task(task = file_name) load_file run_task(task) end
load_file()
click to toggle source
# File lib/shared_tasks.rb, line 101 def load_file load(file_route) end
route()
click to toggle source
# File lib/shared_tasks.rb, line 126 def route "lib/shared_tasks" end
run_single_task(name, task)
click to toggle source
# File lib/shared_tasks.rb, line 85 def run_single_task(name, task) @file = Dir.entries(route).select {|f| (!File.directory?(f) && f.include?("#{name}")) }.first if @file && File.exist?(file_route) load_and_run_task(task) else message = "There isnt a file with name given" puts message.center(100, ".") raise message end end
run_task(task = file_name)
click to toggle source
# File lib/shared_tasks.rb, line 105 def run_task(task = file_name) class_name = "#{file_name.camelize}Shared".constantize puts "Start at #{Time.zone.now}" if task == file_name class_name.methods(false).each do |metad| if metad != :destroy_actions && metad != :_validators puts "Running: #{metad.to_s} at #{Time.zone.now}" eval("#{class_name}.#{metad.to_s}") end end else if class_name.methods(false).include?(task.to_sym) puts "Running single task: #{task} at #{Time.zone.now}" eval("#{class_name}.#{task}") else raise "There isnt a task with name given => #{class_name}.#{task} " end end puts "End at #{Time.zone.now}" end
run_tasks()
click to toggle source
# File lib/shared_tasks.rb, line 73 def run_tasks puts "Running shared tasks" files = Dir.entries(route).select {|f| !File.directory?(f)} files.each do |file| @file = file SharedTasks::Task.where(task: file_date).first_or_create do load_and_run_task if File.exist?(file_route) end end end
Public Instance Methods
rollback_actions()
click to toggle source
# File lib/shared_tasks.rb, line 26 def rollback_actions @file = Dir.entries(route).select {|f| !File.directory?(f) && f.include?(self.task) }.first if @file && File.exist?(file_route) load_file run_task("destroy_actions") else message = "There isnt a file with name given - destroying data" puts message.center(100, ".") end end
Private Instance Methods
file_name()
click to toggle source
# File lib/shared_tasks.rb, line 50 def file_name @file.split("_").drop(1).join("_").split(".").remove_last.first end
file_route()
click to toggle source
# File lib/shared_tasks.rb, line 42 def file_route "lib/shared_tasks/#{@file}" end
load_file()
click to toggle source
# File lib/shared_tasks.rb, line 46 def load_file load(file_route) end
route()
click to toggle source
# File lib/shared_tasks.rb, line 38 def route "lib/shared_tasks" end
run_task(task = file_name)
click to toggle source
# File lib/shared_tasks.rb, line 54 def run_task(task = file_name) class_name = "#{file_name.camelize}Shared".constantize task_to_run = "#{class_name}.#{task}" puts ".......#{@file}..=> #{task_to_run}......" if class_name.respond_to?(task.to_sym) eval(task_to_run) else puts "method not allowed" end end