Sha256: b1b2770b094dcb7b340a5e34d1201ed6af5998af43372ca5759fd9ccd6f40cd4

Contents?: true

Size: 1.9 KB

Versions: 10

Compression:

Stored size: 1.9 KB

Contents

module Eco
  module API
    module Common
      module Session
        class Environment
          attr_reader :config, :session
          attr_reader :file_manager, :logger
          attr_reader :mailer, :sftp, :s3uploader

          alias_method :fm, :file_manager

          #@param init [Eco::API::Common::Session::Environment] object to ini the session environment
          #@param session [Eco::API::Session, nil] the current session
          def initialize(init = {}, session:)
            init = init.conf if init.is_a?(Environment)
            msg = "Expected object Eco::API::Session::Config or Environment. Given: #{init}"
            raise msg unless init.is_a?(Eco::API::Session::Config)
            raise "Expected an Eco::API::Session object. Given: #{session}" if session  && !session.is_a?(Eco::API::Session)

            @config  = init
            @session = session
            @file_manager = Eco::API::Common::Session::FileManager.new(enviro: self)
            @logger       = Eco::API::Common::Session::Logger.new(enviro: self)
          end

          def mailer
            return nil unless mailer?
            @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
          end

          def mailer?
            config.mailer.configured?
          end

          def sftp
            return nil unless sftp?
            @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
          end

          def sftp?
            config.sftp.configured?
          end

          def s3uploader
            return nil unless s3uploader?
            @s3uploader  ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
          end

          def s3uploader?
            config.s3storage.configured?
          end

          def api(version: nil)
            config.api(logger, version: version)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
eco-helpers-2.5.10 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.9 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.8 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.7 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.6 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.5 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.4 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.3 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.2 lib/eco/api/common/session/environment.rb
eco-helpers-2.5.1 lib/eco/api/common/session/environment.rb