Sha256: 88a6ac53f2e0f9af5b44a429afed706e0fb67c4970679470343ec1a67557bde4

Contents?: true

Size: 1.37 KB

Versions: 12

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'avm/apps/jobs/variables_source'
require 'eac_ruby_utils/core_ext'

module Avm
  module Apps
    module Jobs
      module Base
        common_concern do
          include ::ActiveSupport::Callbacks

          enable_console_speaker
          enable_simple_cache
          enable_listable
          common_constructor :instance, :options, default: [{}] do
            if option_list.present?
              self.options = option_list.hash_keys_validate!(options.symbolize_keys)
            end
          end
          define_callbacks(*jobs)
        end

        module ClassMethods
          def jobs
            const_get('JOBS').dup
          end
        end

        module InstanceMethods
          def option_list
            nil
          end

          def run
            start_banner if respond_to?(:start_banner)
            run_jobs
            ::Avm::Result.success('Done!')
          rescue ::Avm::Result::Error => e
            e.to_result
          end

          def variables_source
            ::Avm::Apps::Jobs::VariablesSource.new(self, instance)
          end

          protected

          def run_jobs
            jobs.each do |job|
              run_callbacks job do
                send(job)
              end
            end
          end

          def jobs
            self.class.jobs
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
avm-tools-0.98.0 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-apps-0.2.0 lib/avm/apps/jobs/base.rb
avm-tools-0.97.0 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-tools-0.96.0 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-apps-0.1.1 lib/avm/apps/jobs/base.rb
avm-tools-0.95.0 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-tools-0.94.3 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-tools-0.94.2 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-tools-0.94.1 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-apps-0.1.0 lib/avm/apps/jobs/base.rb
avm-tools-0.94.0 vendor/avm-apps/lib/avm/apps/jobs/base.rb
avm-tools-0.93.0 vendor/avm-apps/lib/avm/apps/jobs/base.rb