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



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

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

#api?(version:) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#log(level, &block) ⇒ Object

Shortcut to logger.



67
68
69
70
71
# File 'lib/eco/api/common/session/environment.rb', line 67

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

  logger&.send(level, &block)
end

#mailerObject



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

def mailer
  return unless mailer?

  @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
end

#mailer?Boolean

Returns:

  • (Boolean)


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

def mailer?
  config.mailer.configured?
end

#s3uploaderObject



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

def s3uploader
  return unless s3uploader?

  @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
end

#s3uploader?Boolean

Returns:

  • (Boolean)


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

def s3uploader?
  config.s3storage.configured?
end

#sftpObject



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

def sftp
  return unless sftp?

  @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
end

#sftp?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/eco/api/common/session/environment.rb', line 41

def sftp?
  config.sftp.configured?
end