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

#initialize ⇒ nil

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



44
45
46
47
48
49
# File 'lib/aspera/cli/context.rb', line 44

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

Instance Attribute Details

#help_requested ⇒ Object

true when help is requested (-h)



40
41
42
# File 'lib/aspera/cli/context.rb', line 40

def help_requested
  @help_requested
end

#pac_executor ⇒ Object

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_bar ⇒ Object

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



69
70
71
# File 'lib/aspera/cli/context.rb', line 69

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



63
64
65
# File 'lib/aspera/cli/context.rb', line 63

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

#validate ⇒ nil

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

Returns:

  • (nil)

Raises:

  • (Aspera::AssertionError) —

    if any member is not set



54
55
56
57
58
59
# File 'lib/aspera/cli/context.rb', line 54

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