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:



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

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.



6
7
8
# File 'lib/eco/api/common/session/environment.rb', line 6

def config
  @config
end

#file_managerObject (readonly) Also known as: fm

Returns the value of attribute file_manager.



7
8
9
# File 'lib/eco/api/common/session/environment.rb', line 7

def file_manager
  @file_manager
end

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/eco/api/common/session/environment.rb', line 7

def logger
  @logger
end

#sessionObject (readonly)

Returns the value of attribute session.



6
7
8
# File 'lib/eco/api/common/session/environment.rb', line 6

def session
  @session
end

Instance Method Details

#api(version: nil) ⇒ Object



55
56
57
# 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)


59
60
61
# File 'lib/eco/api/common/session/environment.rb', line 59

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

#log(level, &block) ⇒ Object

Shortcut to logger.



64
65
66
67
68
# File 'lib/eco/api/common/session/environment.rb', line 64

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

  logger&.send(level, &block)
end

#mailerObject



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

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

#mailer?Boolean

Returns:

  • (Boolean)


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

def mailer?
  config.mailer.configured?
end

#s3uploaderObject



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

def s3uploader
  return nil 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



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

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

#sftp?Boolean

Returns:

  • (Boolean)


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

def sftp?
  config.sftp.configured?
end