Manage and formalize target-file jobs and keep track of source- and target-file includings

This commit is contained in:
2018-05-06 10:50:00 -03:00
parent f795c28c5a
commit ec21710fea
4 changed files with 29 additions and 1 deletions
+1
View File
@@ -16,6 +16,7 @@ module Dunlop::SourceFileModel
has_many :downloads, class_name: 'Dunlop::FileDownload', as: :file
attr_accessor :working_file
belongs_to :creator, polymorphic: true, optional: true
Dunlop.source_file_models << self
mount_uploader :original_file, Dunlop::SourceFileUploader unless defined?(Paperclip) # CarrierWave still default.
+1
View File
@@ -14,6 +14,7 @@ module Dunlop::TargetFileModel
has_many :downloads, class_name: 'Dunlop::FileDownload', as: :file
attr_accessor :working_file, :original_file
attr_accessor :resource
Dunlop.target_file_models << self
mount_uploader :original_file, Dunlop::TargetFileUploader unless defined?(Paperclip) # CarrierWave still default.
# used by dunlop-file_transfer
+8
View File
@@ -20,4 +20,12 @@ module Dunlop
def self.has_target_files?
'TargetFile'.safe_constantize
end
def self.source_file_models
@source_file_models ||= []
end
def self.target_file_models
@target_file_models ||= []
end
end
+19 -1
View File
@@ -37,6 +37,8 @@ end
module Dunlop
class Engine < ::Rails::Engine
isolate_namespace Dunlop
#TODO this generates noise and pollutes API based implementations (Like Panda)
initializer 'dunlop.action_controller' do |app|
ActiveSupport.on_load :action_controller do
helper Dunlop::ApplicationHelper if respond_to?(:helper)
@@ -50,12 +52,28 @@ module Dunlop
end
# add migrations to containing application
initializer :append_migrations do |app|
initializer 'dunlop.append_migrations' do |app|
unless app.root.to_s.match root.to_s
config.paths["db/migrate"].expanded.each do |expanded_path|
app.config.paths["db/migrate"] << expanded_path
end
end
end
config.after_initialize do
# Auto generate target-file's ::Job classes having purpose triggering .generate on the class
Dunlop.target_file_models.each do |target_file_base_model|
## Generte a job for all target files
base_job = "#{target_file_base_model.name.deconstantize}::ApplicationJob".constantize
target_file_base_model.classes.each do |cls|
next if cls.const_defined?(:Job)
cls::Job = Class.new base_job do
def perform
self.class.name.sub(/::Job$/, '').constantize.generate!
end
end
end
end
end
end
end