Class: NeedsManager

Inherits:
Object
  • Object
show all
Defined in:
lib/sfb_scripts/needs_manager.rb

Constant Summary collapse

BUNDLER_MAX_THREAD_COUNT =
2
MIGRATOR_MAX_THREAD_COUNT =
8

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, needs, options) ⇒ NeedsManager

Returns a new instance of NeedsManager.



13
14
15
16
17
18
# File 'lib/sfb_scripts/needs_manager.rb', line 13

def initialize(task, needs, options)
  @log_file = log_file_for(task)
  @needs = needs
  @options = options
  @env = {}
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



12
13
14
# File 'lib/sfb_scripts/needs_manager.rb', line 12

def env
  @env
end

#log_fileObject (readonly)

Returns the value of attribute log_file.



12
13
14
# File 'lib/sfb_scripts/needs_manager.rb', line 12

def log_file
  @log_file
end

#needsObject (readonly)

Returns the value of attribute needs.



12
13
14
# File 'lib/sfb_scripts/needs_manager.rb', line 12

def needs
  @needs
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/sfb_scripts/needs_manager.rb', line 12

def options
  @options
end

Class Method Details

.configure(task, needs, options) ⇒ Object



8
9
10
# File 'lib/sfb_scripts/needs_manager.rb', line 8

def self.configure(task, needs, options)
  new(task, needs, options).configure
end

Instance Method Details

#configureObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sfb_scripts/needs_manager.rb', line 20

def configure
  set_working_directory

  create_shell
  create_folder_guard

  create_repo if needs.include? :repo
  create_bundler if needs.include? :bundler
  create_migrator if needs.include? :migrator
  create_test_runner if needs.include? :test_runner

  return env
end

#create_bundlerObject



72
73
74
75
# File 'lib/sfb_scripts/needs_manager.rb', line 72

def create_bundler
  queue = WorkQueue.new(BUNDLER_MAX_THREAD_COUNT, nil)
  env[:bundler] = BundleManager.new(shell: env[:shell], repo: env[:repo], queue: queue, folder_guard: env[:folder_guard])
end

#create_folder_guardObject



53
54
55
56
# File 'lib/sfb_scripts/needs_manager.rb', line 53

def create_folder_guard
  denied_folders = options[:ignore] || []
  env[:folder_guard] = FolderGuard.new(denied_folders)
end

#create_migratorObject



77
78
79
80
# File 'lib/sfb_scripts/needs_manager.rb', line 77

def create_migrator
  queue = WorkQueue.new(MIGRATOR_MAX_THREAD_COUNT, nil)
  env[:migrator] = Migrator.new(shell: env[:shell], repo: env[:repo], queue: queue, folder_guard: env[:folder_guard])
end

#create_repoObject



58
59
60
# File 'lib/sfb_scripts/needs_manager.rb', line 58

def create_repo
  env[:repo] = repo_class.new(shell: env[:shell])
end

#create_shellObject



39
40
41
# File 'lib/sfb_scripts/needs_manager.rb', line 39

def create_shell
  env[:shell] = shell_class.new(log_file, @working_directory)
end

#create_test_runnerObject



82
83
84
85
86
87
# File 'lib/sfb_scripts/needs_manager.rb', line 82

def create_test_runner
  env[:test_runner] = TestRunner.new(
    shell: env[:shell],
    all_engines: options[:all_engines]
  )
end

#log_file_for(task) ⇒ Object



89
90
91
# File 'lib/sfb_scripts/needs_manager.rb', line 89

def log_file_for(task)
  "/tmp/#{task}.log"
end

#repo_classObject



62
63
64
65
66
67
68
69
70
# File 'lib/sfb_scripts/needs_manager.rb', line 62

def repo_class
  if options[:repo_type] == :active
    ActiveRepo
  elsif options[:repo_type] == :lazy
    LazyRepo
  else
    Repo
  end
end

#set_working_directoryObject



34
35
36
37
# File 'lib/sfb_scripts/needs_manager.rb', line 34

def set_working_directory
  @working_directory = Repo.root_dir
  Dir.chdir(@working_directory)
end

#shell_classObject



43
44
45
46
47
48
49
50
51
# File 'lib/sfb_scripts/needs_manager.rb', line 43

def shell_class
  if options[:verbose]
    VerboseShellRunner
  elsif options[:loud]
    LoudShellRunner
  else
    ShellRunner
  end
end