Class: Aspera::Agent::Factory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/aspera/agent/factory.rb

Overview

Factory for Agents

Constant Summary collapse

ALL =

Available agents: :long : Capitalized name string, :short : single character symbol

Dir.children(File.dirname(File.expand_path(__FILE__)))
  .select{ |file| file.end_with?(Environment::RB_EXT)}
  .map{ |file| File.basename(file, Environment::RB_EXT).to_sym}
  .reject{ |item| IGNORED_ITEMS.include?(item)}.to_h do |agent_sym|
  [agent_sym, {
    long:  agent_sym.to_s.capitalize,
    short: agent_sym.eql?(:direct) ? :a : agent_sym.to_s[0].to_sym
  }.freeze]
end.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceFactory

Returns the singleton instance of Factory

Returns:

  • (Factory)

    the singleton instance



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/aspera/agent/factory.rb', line 13

class Factory
  include Singleton

  # Create new agent
  def create(agent, options)
    Log.dump(:options, options)
    require "aspera/agent/#{agent}"
    Aspera::Agent.const_get(agent.to_s.capitalize).new(**options)
  end

  IGNORED_ITEMS = %i[factory base]
  # Available agents: :long : Capitalized name string, :short : single character symbol
  ALL =
    Dir.children(File.dirname(File.expand_path(__FILE__)))
      .select{ |file| file.end_with?(Environment::RB_EXT)}
      .map{ |file| File.basename(file, Environment::RB_EXT).to_sym}
      .reject{ |item| IGNORED_ITEMS.include?(item)}.to_h do |agent_sym|
      [agent_sym, {
        long:  agent_sym.to_s.capitalize,
        short: agent_sym.eql?(:direct) ? :a : agent_sym.to_s[0].to_sym
      }.freeze]
    end.freeze
  private_constant :IGNORED_ITEMS
end

Instance Method Details

#create(agent, options) ⇒ Object

Create new agent



17
18
19
20
21
# File 'lib/aspera/agent/factory.rb', line 17

def create(agent, options)
  Log.dump(:options, options)
  require "aspera/agent/#{agent}"
  Aspera::Agent.const_get(agent.to_s.capitalize).new(**options)
end