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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/eco/api/common/session/environment.rb', line 18

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

Instance Attribute Details

#apiObject (readonly)

, :host, :version



10
11
12
# File 'lib/eco/api/common/session/environment.rb', line 10

def api
  @api
end

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/eco/api/common/session/environment.rb', line 9

def config
  @config
end

#file_managerObject (readonly) Also known as: fm

Returns the value of attribute file_manager.



11
12
13
# File 'lib/eco/api/common/session/environment.rb', line 11

def file_manager
  @file_manager
end

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/eco/api/common/session/environment.rb', line 11

def logger
  @logger
end

#mailerObject (readonly)

Returns the value of attribute mailer.



12
13
14
# File 'lib/eco/api/common/session/environment.rb', line 12

def mailer
  @mailer
end

#s3uploaderObject (readonly)

Returns the value of attribute s3uploader.



12
13
14
# File 'lib/eco/api/common/session/environment.rb', line 12

def s3uploader
  @s3uploader
end

#sessionObject (readonly)

Returns the value of attribute session.



9
10
11
# File 'lib/eco/api/common/session/environment.rb', line 9

def session
  @session
end

#sftpObject (readonly)

Returns the value of attribute sftp.



12
13
14
# File 'lib/eco/api/common/session/environment.rb', line 12

def sftp
  @sftp
end

Instance Method Details

#mailer?Boolean



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

def mailer?
  config.mailer.configured?
end

#new_apiObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/eco/api/common/session/environment.rb', line 64

def new_api
  return nil unless config.apis.active_api

  log_connection = config.logger.log_connection?
  logg = log_connection ? logger : ::Logger.new(IO::NULL)

  api = config.api(logg)

  unless log_connection
    logger.info("Created connection pointing to '#{config.apis.active_api.host}' in '#{config.apis.active_api.mode}' mode")
    api.logger.level = ::Logger::UNKNOWN
  end

  @api = api
  api
end

#s3uploader?Boolean



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

def s3uploader?
  config.s3storage.configured?
end

#sftp?Boolean



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

def sftp?
  config.sftp.configured?
end