Class: Eco::API::Common::Session::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/common/session/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init = {}, session:) ⇒ Environment

Returns a new instance of Environment.

Parameters:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/eco/api/common/session/environment.rb', line 10

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)

  invalid_session = session && !session.is_a?(Eco::API::Session)
  raise "Expected an Eco::API::Session object. Given: #{session}" if invalid_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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/eco/api/common/session/environment.rb', line 3

def config
  @config
end

#file_managerObject (readonly) Also known as: fm

Returns the value of attribute file_manager.



4
5
6
# File 'lib/eco/api/common/session/environment.rb', line 4

def file_manager
  @file_manager
end

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/eco/api/common/session/environment.rb', line 4

def logger
  @logger
end

#sessionObject (readonly)

Returns the value of attribute session.



3
4
5
# File 'lib/eco/api/common/session/environment.rb', line 3

def session
  @session
end

Instance Method Details

#api(version: nil) ⇒ Object



52
53
54
# File 'lib/eco/api/common/session/environment.rb', line 52

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

#api?(version:) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/eco/api/common/session/environment.rb', line 56

def api?(version:)
  config.apis.active_api.version_available?(version)
end

#log(level, &block) ⇒ Object

Shortcut to logger.



61
62
63
64
65
# File 'lib/eco/api/common/session/environment.rb', line 61

def log(level, &block)
  return unless logger.respond_to?(:level)

  logger&.send(level, &block)
end

#mailerObject



25
26
27
28
# File 'lib/eco/api/common/session/environment.rb', line 25

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

#mailer?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/eco/api/common/session/environment.rb', line 30

def mailer?
  config.mailer.configured?
end

#s3uploaderObject



43
44
45
46
# File 'lib/eco/api/common/session/environment.rb', line 43

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

#s3uploader?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/eco/api/common/session/environment.rb', line 48

def s3uploader?
  config.s3storage.configured?
end

#sftpObject



34
35
36
37
# File 'lib/eco/api/common/session/environment.rb', line 34

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

#sftp?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/eco/api/common/session/environment.rb', line 39

def sftp?
  config.sftp.configured?
end