Sha256: ef5da840c0eb44c8cda3d07736f14c7e5c2ed1fd34f193fd299c1670f3176fb7

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

module Eco
  module API
    module Common
      module Loaders
        class Base
          extend Eco::API::Common::ClassHelpers
          include Eco::Language::AuxiliarLogger

          class << self
            # Sort order
            def <=>(other)
              created_at <=> other.created_at
            end

            # If still not set, it sets the `created_at` class timestamp.
            def set_created_at!
              @created_at ||= Time.now unless @created_at # rubocop:disable Naming/MemoizedInstanceVariableName
            end

            # Class creation timestamp, to be able to load them in the order they were declared.
            def created_at
              @created_at ||= Time.now
            end
          end

          # This method will be called when the BaseLoader is created
          # @note
          #   - this method should implement the loading logics for the given `Children` class.
          def initialize
            raise "You should implement this method"
          end

          private

          def simulate?
            options[:simulate] || options[:dry_run]
          end
          alias_method :dry_run?, :simulate?

          def session
            @session ||= ASSETS.session
          end

          def options
            @options ||= {}
          end

          def config
            session.config
          end

          def micro
            session.micro
          end

          def abort(msg, raising: true)
            logger.error(msg)
            raise msg if raising
            exit 1
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eco-helpers-2.7.2 lib/eco/api/common/loaders/base.rb
eco-helpers-2.7.1 lib/eco/api/common/loaders/base.rb
eco-helpers-2.7.0 lib/eco/api/common/loaders/base.rb