From c676bb98feb9266cd7385076c3da68b479cfe5ec Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 11 Oct 2019 07:20:34 -0500 Subject: [PATCH] More strict module loading required by newer ruby versions --- app/assets/javascripts/dunlop/base.coffee | 1 - .../stylesheets/dunlop-semantic-ui.sass | 4 ++-- app/helpers/dunlop/application_helper.rb | 10 ++++---- app/helpers/dunlop/authorization_helper.rb | 4 ++-- .../dunlop/application_record_additions.rb | 2 +- app/models/dunlop/execution_batch_model.rb | 6 ++--- app/models/dunlop/source_file_model.rb | 9 +++---- app/models/dunlop/target_file_model.rb | 8 +++---- app/models/dunlop/user_model.rb | 2 +- .../dunlop/workflow_instance_batch_model.rb | 2 +- app/models/dunlop/workflow_instance_model.rb | 12 +++++----- app/models/dunlop/workflow_step_model.rb | 10 ++++---- app/services/dunlop/ability.rb | 14 +++++------ app/services/dunlop/loggable.rb | 24 +++++++++---------- app/services/dunlop/nested_logger.rb | 4 ++-- app/services/dunlop/overdue_handling.rb | 4 ++-- app/services/dunlop/workflow.rb | 2 +- .../workflow_steps_in_batch_finished.rb | 4 ++-- app/services/json_column_coder.rb | 3 +++ lib/dunlop/engine.rb | 2 +- 20 files changed, 65 insertions(+), 62 deletions(-) diff --git a/app/assets/javascripts/dunlop/base.coffee b/app/assets/javascripts/dunlop/base.coffee index 746b645..ac53310 100644 --- a/app/assets/javascripts/dunlop/base.coffee +++ b/app/assets/javascripts/dunlop/base.coffee @@ -39,5 +39,4 @@ class Dunlop label_or_callback = 'anonymous' (@setup_callbacks[label_or_callback] ||= []).push labelled_callback - @Dunlop = new Dunlop() diff --git a/app/assets/stylesheets/dunlop-semantic-ui.sass b/app/assets/stylesheets/dunlop-semantic-ui.sass index 269e029..87bd720 100644 --- a/app/assets/stylesheets/dunlop-semantic-ui.sass +++ b/app/assets/stylesheets/dunlop-semantic-ui.sass @@ -1,7 +1,7 @@ @import ./dunlop/mixins -@import ./dunlop-semantic/calendar -@import ./dunlop-semantic/ui-calendar-additions +//@import ./dunlop-semantic/calendar +//@import ./dunlop-semantic/ui-calendar-additions @import ./dunlop-semantic/convenience-helpers @import ./dunlop/components/environment-ribbon //@import ./dunlop/components/user_management diff --git a/app/helpers/dunlop/application_helper.rb b/app/helpers/dunlop/application_helper.rb index 5b92cf9..e53e235 100644 --- a/app/helpers/dunlop/application_helper.rb +++ b/app/helpers/dunlop/application_helper.rb @@ -1,10 +1,10 @@ module Dunlop module ApplicationHelper - include Dunlop::ActiveClassHelper - include Dunlop::AuthorizationHelper - include Dunlop::TableHelper - include Dunlop::StateBadgeHelper - include Dunlop::InterpretedTextHelper + include ::Dunlop::ActiveClassHelper + include ::Dunlop::AuthorizationHelper + include ::Dunlop::TableHelper + include ::Dunlop::StateBadgeHelper + include ::Dunlop::InterpretedTextHelper delegate :mathjax_path, to: :main_app def application_name diff --git a/app/helpers/dunlop/authorization_helper.rb b/app/helpers/dunlop/authorization_helper.rb index c36cd66..f2b666d 100644 --- a/app/helpers/dunlop/authorization_helper.rb +++ b/app/helpers/dunlop/authorization_helper.rb @@ -1,11 +1,11 @@ module Dunlop::AuthorizationHelper def has_permission_of_type(type, user = current_user) - Dunlop::Ability.has_permission_of_type(type, user) + ::Dunlop::Ability.has_permission_of_type(type, user) end # - if any_permission_starts_with 'source-file' # NOTE: always true for admin users def any_permission_starts_with(expression, user = current_user) - Dunlop::Ability.any_permission_starts_with(expression, user) + ::Dunlop::Ability.any_permission_starts_with(expression, user) end end diff --git a/app/models/dunlop/application_record_additions.rb b/app/models/dunlop/application_record_additions.rb index 9316818..957bd67 100644 --- a/app/models/dunlop/application_record_additions.rb +++ b/app/models/dunlop/application_record_additions.rb @@ -1,7 +1,7 @@ module Dunlop module ApplicationRecordAdditions extend ActiveSupport::Concern - include Dunlop::ApplicationRecordAdditions::EpochWeeks + include ::Dunlop::ApplicationRecordAdditions::EpochWeeks included do self.abstract_class = true diff --git a/app/models/dunlop/execution_batch_model.rb b/app/models/dunlop/execution_batch_model.rb index e4cba8d..fe1d2c1 100644 --- a/app/models/dunlop/execution_batch_model.rb +++ b/app/models/dunlop/execution_batch_model.rb @@ -2,7 +2,7 @@ module Dunlop::ExecutionBatchModel extend ActiveSupport::Concern included do - include Dunlop::Loggable + include ::Dunlop::Loggable state_machine initial: :new do after_transition { |o| o.log_state_transition } @@ -61,9 +61,9 @@ module Dunlop::ExecutionBatchModel end def execute! - return if Dunlop::ExecutionBatchPid.new(batch_pid_id).locked? + return if ::Dunlop::ExecutionBatchPid.new(batch_pid_id).locked? batch = nil - Dunlop::ExecutionBatchPid.new(batch_pid_id).lock do + ::Dunlop::ExecutionBatchPid.new(batch_pid_id).lock do batch = create batch.execute_process end diff --git a/app/models/dunlop/source_file_model.rb b/app/models/dunlop/source_file_model.rb index f608071..f3f1075 100644 --- a/app/models/dunlop/source_file_model.rb +++ b/app/models/dunlop/source_file_model.rb @@ -9,7 +9,7 @@ module Dunlop::SourceFileModel end end - include Dunlop::SourceFileModel::ConversionHelpers + include ::Dunlop::SourceFileModel::ConversionHelpers included do include Dunlop::Loggable @@ -19,7 +19,7 @@ module Dunlop::SourceFileModel Dunlop.source_file_models << self scope :processed, -> { where state: ['active', 'inactive'] } - mount_uploader :original_file, Dunlop::SourceFileUploader unless defined?(Paperclip) # CarrierWave still default. + mount_uploader :original_file, ::Dunlop::SourceFileUploader unless defined?(Paperclip) # CarrierWave still default. # used by dunlop-file_transfer def default_file @@ -82,11 +82,11 @@ module Dunlop::SourceFileModel else original_file.path end - Dunlop::FileZip.unzip(source_path, working_file.path) + ::Dunlop::FileZip.unzip(source_path, working_file.path) end def pre_process_working_file(target_path = working_file.path) - Dunlop::FileSed.fix_line_endings(target_path) + ::Dunlop::FileSed.fix_line_endings(target_path) end def load_source_records @@ -213,6 +213,7 @@ module Dunlop::SourceFileModel first end + #TODO: this is not compatible with multiple source_file impolementations in one application def recent_ids group(:sti_type).map do |combination| sti_type = combination.sti_type diff --git a/app/models/dunlop/target_file_model.rb b/app/models/dunlop/target_file_model.rb index 7bdf575..216b39e 100644 --- a/app/models/dunlop/target_file_model.rb +++ b/app/models/dunlop/target_file_model.rb @@ -12,13 +12,13 @@ module Dunlop::TargetFileModel end included do - include Dunlop::Loggable + include ::Dunlop::Loggable 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. + mount_uploader :original_file, ::Dunlop::TargetFileUploader unless defined?(Paperclip) # CarrierWave still default. # used by dunlop-file_transfer def default_file original_file @@ -135,9 +135,9 @@ module Dunlop::TargetFileModel end def gzip_file - return if Dunlop::FileZip.mime_type(working_file.path) == "application/x-gzip" # no double action and working file replacement + return if ::Dunlop::FileZip.mime_type(working_file.path) == "application/x-gzip" # no double action and working file replacement local_working_file = new_working_file - Dunlop::FileZip.gzip(working_file.path,local_working_file.path) + ::Dunlop::FileZip.gzip(working_file.path,local_working_file.path) working_file.unlink rescue SystemCallError # container permission issue self.working_file = local_working_file end diff --git a/app/models/dunlop/user_model.rb b/app/models/dunlop/user_model.rb index b222c24..c2e11f5 100644 --- a/app/models/dunlop/user_model.rb +++ b/app/models/dunlop/user_model.rb @@ -11,7 +11,7 @@ module Dunlop end def settings - @settings ||= Dunlop::UserSettings.new(self, settings_storage) + @settings ||= ::Dunlop::UserSettings.new(self, settings_storage) end def all_role_names diff --git a/app/models/dunlop/workflow_instance_batch_model.rb b/app/models/dunlop/workflow_instance_batch_model.rb index deb14e7..f911e56 100644 --- a/app/models/dunlop/workflow_instance_batch_model.rb +++ b/app/models/dunlop/workflow_instance_batch_model.rb @@ -2,7 +2,7 @@ module Dunlop::WorkflowInstanceBatchModel extend ActiveSupport::Concern included do - include Dunlop::ProcessIdentification + include ::Dunlop::ProcessIdentification has_many :workflow_instances, inverse_of: :workflow_instance_batch end diff --git a/app/models/dunlop/workflow_instance_model.rb b/app/models/dunlop/workflow_instance_model.rb index 2e4cffd..24297b4 100644 --- a/app/models/dunlop/workflow_instance_model.rb +++ b/app/models/dunlop/workflow_instance_model.rb @@ -2,12 +2,12 @@ module Dunlop::WorkflowInstanceModel extend ActiveSupport::Concern included do - include Dunlop::WorkflowInstanceModel::StateMachineHandling - include Dunlop::WorkflowInstanceModel::WorkflowStepHandling - include Dunlop::WorkflowInstanceModel::ArchivedHandling - include Dunlop::WorkflowInstanceModel::CategorizationAndResetHandling - include Dunlop::ProcessIdentification - include Dunlop::CollectionLookup + include ::Dunlop::WorkflowInstanceModel::StateMachineHandling + include ::Dunlop::WorkflowInstanceModel::WorkflowStepHandling + include ::Dunlop::WorkflowInstanceModel::ArchivedHandling + include ::Dunlop::WorkflowInstanceModel::CategorizationAndResetHandling + include ::Dunlop::ProcessIdentification + include ::Dunlop::CollectionLookup @scenario_workflow_step_names = [] belongs_to :workflow_instance_batch, inverse_of: :workflow_instances, optional: true diff --git a/app/models/dunlop/workflow_step_model.rb b/app/models/dunlop/workflow_step_model.rb index f3837a3..7ed1c7d 100644 --- a/app/models/dunlop/workflow_step_model.rb +++ b/app/models/dunlop/workflow_step_model.rb @@ -1,12 +1,12 @@ module Dunlop::WorkflowStepModel extend ActiveSupport::Concern - include Dunlop::WorkflowStepModel::StateMachine - include Dunlop::ProcessIdentification - include Dunlop::AttributeChangesTracking + include ::Dunlop::WorkflowStepModel::StateMachine + include ::Dunlop::ProcessIdentification + include ::Dunlop::AttributeChangesTracking included do - include Dunlop::CollectionLookup - include Dunlop::WorkflowStepModel::NotesHandling + include ::Dunlop::CollectionLookup + include ::Dunlop::WorkflowStepModel::NotesHandling belongs_to :workflow_instance, optional: true #include HasManyChangeEvents end diff --git a/app/services/dunlop/ability.rb b/app/services/dunlop/ability.rb index 01b03c4..34a08f0 100644 --- a/app/services/dunlop/ability.rb +++ b/app/services/dunlop/ability.rb @@ -26,11 +26,11 @@ module Dunlop::Ability end def has_permission_of_type(type) - Dunlop::Ability.has_permission_of_type(type, user) + ::Dunlop::Ability.has_permission_of_type(type, user) end def any_permission_starts_with(expression) - Dunlop::Ability.any_permission_starts_with(expression, user) + ::Dunlop::Ability.any_permission_starts_with(expression, user) end def setup_dunlop_abilities @@ -62,12 +62,12 @@ module Dunlop::Ability roles.push get_role_for_role_name(role_name) end user.role_names_admin.each do |role_name| - roles.push get_role_for_role_name(role_name, role: Dunlop::Ability::AdminRole, verify_class: false) + roles.push get_role_for_role_name(role_name, role: ::Dunlop::Ability::AdminRole, verify_class: false) end @all_roles = roles.compact end - def get_role_for_role_name(role_name, role: Dunlop::Ability::UserRole, verify_class: true) + def get_role_for_role_name(role_name, role: ::Dunlop::Ability::UserRole, verify_class: true) return unless role_name =~ /\w+-\w+-[\w:\/-]+/ ability, type, class_name = role_name.split('-', 3) case type @@ -154,12 +154,12 @@ module Dunlop::Ability def add_dunlop_allowed_authorization_classes! result = ['Dunlop::Engine'] - if Dunlop.has_workflow? + if ::Dunlop.has_workflow? result += ['WorkflowInstance', 'WorkflowInstanceBatch'] result += WorkflowInstance.possible_workflow_step_names.map{|name| name.to_s.classify } end - result += SourceFile.classes.map(&:name) if Dunlop.has_source_files? - result += TargetFile.classes.map(&:name) if Dunlop.has_target_files? + result += SourceFile.classes.map(&:name) if ::Dunlop.has_source_files? + result += TargetFile.classes.map(&:name) if ::Dunlop.has_target_files? @allowed_authorization_classes |= result end end diff --git a/app/services/dunlop/loggable.rb b/app/services/dunlop/loggable.rb index 727e6a7..934ae5f 100644 --- a/app/services/dunlop/loggable.rb +++ b/app/services/dunlop/loggable.rb @@ -9,18 +9,18 @@ module Dunlop::Loggable scope ||= caller[0][/`.*'/][1..-2] options[:exception_notifier] = true unless options.has_key?(:exception_notifier) backtrace = nil - Dunlop::NestedLogger.scope('empty sandbox', benchmark: false) do - result = Dunlop::NestedLogger.scope(scope, options) do + ::Dunlop::NestedLogger.scope('empty sandbox', benchmark: false) do + result = ::Dunlop::NestedLogger.scope(scope, options) do begin yield rescue => e failed! ExceptionNotifier.notify_exception(e) if options[:exception_notifier] - backtrace = Dunlop::LogEntry.exception_to_backtrace(e) - Dunlop::NestedLogger.error(e.message) + backtrace = ::Dunlop::LogEntry.exception_to_backtrace(e) + ::Dunlop::NestedLogger.error(e.message) end end - log_yaml = Dunlop::NestedLogger.flush_as_yaml + log_yaml = ::Dunlop::NestedLogger.flush_as_yaml log_entries.create(body: log_yaml, backtrace: backtrace) if log_yaml.present? result # return block result end @@ -30,23 +30,23 @@ module Dunlop::Loggable scope ||= caller[0][/`.*'/][1..-2] e = nil backtrace = nil - Dunlop::NestedLogger.scope('empty sandbox', benchmark: false) do - Dunlop::NestedLogger.scope(scope, options) do + ::Dunlop::NestedLogger.scope('empty sandbox', benchmark: false) do + ::Dunlop::NestedLogger.scope(scope, options) do begin yield rescue => e - backtrace = Dunlop::LogEntry.exception_to_backtrace(e) - Dunlop::NestedLogger.error(e.message) + backtrace = ::Dunlop::LogEntry.exception_to_backtrace(e) + ::Dunlop::NestedLogger.error(e.message) end end - log_yaml = Dunlop::NestedLogger.flush_as_yaml + log_yaml = ::Dunlop::NestedLogger.flush_as_yaml log_entries.create(body: log_yaml, backtrace: backtrace) if log_yaml.present? end raise e if e end def logger - Dunlop::NestedLogger + ::Dunlop::NestedLogger end def log_state_transition @@ -54,6 +54,6 @@ module Dunlop::Loggable end def log_entry - Dunlop::LogEntryCreator.new(self) + ::Dunlop::LogEntryCreator.new(self) end end diff --git a/app/services/dunlop/nested_logger.rb b/app/services/dunlop/nested_logger.rb index 39aeb6b..c01696d 100644 --- a/app/services/dunlop/nested_logger.rb +++ b/app/services/dunlop/nested_logger.rb @@ -88,7 +88,7 @@ module Dunlop::NestedLogger end def flush_as_yaml - (f = flush.presence) ? YAML.dump(f, Dunlop::NestedLogger.options[:yaml_options]).sub("---\n", '') : '' + (f = flush.presence) ? YAML.dump(f, ::Dunlop::NestedLogger.options[:yaml_options]).sub("---\n", '') : '' end def log(options={}) @@ -150,7 +150,7 @@ module Dunlop::NestedLogger end def to_entry - Dunlop::NestedLogger.formatter.call(severity, datetime, progname, msg) + ::Dunlop::NestedLogger.formatter.call(severity, datetime, progname, msg) end end diff --git a/app/services/dunlop/overdue_handling.rb b/app/services/dunlop/overdue_handling.rb index bb865e1..618db30 100644 --- a/app/services/dunlop/overdue_handling.rb +++ b/app/services/dunlop/overdue_handling.rb @@ -43,11 +43,11 @@ module Dunlop::OverdueHandling workflow_step_proxy = WorkflowStepProxy.new(workflow_step, options) workflow_step_proxy.instance_eval(&block) if block workflow_step_proxy.register_callbacks! - Dunlop::OverdueHandling.registry[workflow_step] = workflow_step_proxy + ::Dunlop::OverdueHandling.registry[workflow_step] = workflow_step_proxy end def the_final_states_are(states) - Dunlop::OverdueHandling.final_states = states + ::Dunlop::OverdueHandling.final_states = states end end diff --git a/app/services/dunlop/workflow.rb b/app/services/dunlop/workflow.rb index 318d247..b21f7a3 100644 --- a/app/services/dunlop/workflow.rb +++ b/app/services/dunlop/workflow.rb @@ -3,7 +3,7 @@ module Dunlop::Workflow class << self attr_accessor :configuration def configuration - @configuration ||= Dunlop::Workflow::Configuration.new + @configuration ||= ::Dunlop::Workflow::Configuration.new end end diff --git a/app/services/dunlop/workflow_steps_in_batch_finished.rb b/app/services/dunlop/workflow_steps_in_batch_finished.rb index 5d8a602..d5e3422 100644 --- a/app/services/dunlop/workflow_steps_in_batch_finished.rb +++ b/app/services/dunlop/workflow_steps_in_batch_finished.rb @@ -62,11 +62,11 @@ module Dunlop::WorkflowStepsInBatchFinished def on_finishing_of(workflow_step, options = {}, &block) workflow_step_proxy = WorkflowStepProxy.new workflow_step_proxy.instance_eval(&block) - Dunlop::WorkflowStepsInBatchFinished.registry[workflow_step] = workflow_step_proxy + ::Dunlop::WorkflowStepsInBatchFinished.registry[workflow_step] = workflow_step_proxy end def the_final_states_are(states) - Dunlop::WorkflowStepsInBatchFinished.final_states = states + ::Dunlop::WorkflowStepsInBatchFinished.final_states = states end end diff --git a/app/services/json_column_coder.rb b/app/services/json_column_coder.rb index 7520897..1fc048f 100644 --- a/app/services/json_column_coder.rb +++ b/app/services/json_column_coder.rb @@ -32,3 +32,6 @@ class JSONColumnCoder end end +# rails 6 does not eager load the JSONColumnCoder notation +class JsonColumnCoder < JSONColumnCoder +end diff --git a/lib/dunlop/engine.rb b/lib/dunlop/engine.rb index cfcb016..4711b78 100644 --- a/lib/dunlop/engine.rb +++ b/lib/dunlop/engine.rb @@ -40,7 +40,7 @@ module 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) + helper ::Dunlop::ApplicationHelper if respond_to?(:helper) end end