Class: Aspera::Cli::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/cli/context.rb

Overview

Global objects shared with plugins

Constant Summary collapse

MEMBERS =

Members that must be non-nil after bootstrap (validated in #validate)

%i[options transfer config formatter persistency man_header presets http_config main_folder mailer secret_finder].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializenil

Initialize all members to nil, so that they are defined and can be validated later



42
43
44
45
46
# File 'lib/aspera/cli/context.rb', line 42

def initialize
  MEMBERS.each { |i| instance_variable_set(:"@#{i}", nil) }
  @progress_bar = nil
  @pac_executor = nil
end

Instance Attribute Details

#pac_executorObject

Optional: nil when no PAC script is configured



38
39
40
# File 'lib/aspera/cli/context.rb', line 38

def pac_executor
  @pac_executor
end

#progress_barObject

Optional: nil when progress bar is disabled



36
37
38
# File 'lib/aspera/cli/context.rb', line 36

def progress_bar
  @progress_bar
end

Instance Method Details

#only_manual!Symbol

Set the context to manual-only mode

Returns:

  • (Symbol)

    :only_manual



66
67
68
# File 'lib/aspera/cli/context.rb', line 66

def only_manual!
  @transfer = :only_manual
end

#only_manual?Boolean

Check if the context is in manual-only mode

Returns:

  • (Boolean)

    true if in manual-only mode



60
61
62
# File 'lib/aspera/cli/context.rb', line 60

def only_manual?
  transfer.eql?(:only_manual)
end

#validatenil

Validate that all mandatory members are non-nil (detect bootstrap bugs)

Returns:

  • (nil)

Raises:

  • (Aspera::AssertionError)

    if any member is not set



51
52
53
54
55
56
# File 'lib/aspera/cli/context.rb', line 51

def validate
  MEMBERS.each do |i|
    Aspera.assert(instance_variable_defined?(:"@#{i}")) { "context member @#{i} is not defined" }
    Aspera.assert(!instance_variable_get(:"@#{i}").nil?) { "context member @#{i} is nil" }
  end
end