Class: Eco::API::Common::Session::Environment
- Defined in:
- lib/eco/api/common/session/environment.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file_manager ⇒ Object
(also: #fm)
readonly
Returns the value of attribute file_manager.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #api(version: nil) ⇒ Object
- #api?(version:) ⇒ Boolean
-
#initialize(init = {}, session:) ⇒ Environment
constructor
A new instance of Environment.
-
#log(level, &block) ⇒ Object
Shortcut to logger.
- #mailer ⇒ Object
- #mailer? ⇒ Boolean
- #s3uploader ⇒ Object
- #s3uploader? ⇒ Boolean
- #sftp ⇒ Object
- #sftp? ⇒ Boolean
Constructor Details
#initialize(init = {}, session:) ⇒ Environment
Returns a new instance of Environment.
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
#config ⇒ Object (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_manager ⇒ Object (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 |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/eco/api/common/session/environment.rb', line 4 def logger @logger end |
#session ⇒ Object (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
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 |
#mailer ⇒ Object
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
31 32 33 |
# File 'lib/eco/api/common/session/environment.rb', line 31 def mailer? config.mailer.configured? end |
#s3uploader ⇒ Object
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
51 52 53 |
# File 'lib/eco/api/common/session/environment.rb', line 51 def s3uploader? config.s3storage.configured? end |
#sftp ⇒ Object
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
41 42 43 |
# File 'lib/eco/api/common/session/environment.rb', line 41 def sftp? config.sftp.configured? end |