Class: NeedsManager

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

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.



17
18
19
20
21
22
# File 'lib/needs_manager.rb', line 17

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.



16
17
18
# File 'lib/needs_manager.rb', line 16

def env
  @env
end

#log_fileObject (readonly)

Returns the value of attribute log_file.



16
17
18
# File 'lib/needs_manager.rb', line 16

def log_file
  @log_file
end

#needsObject (readonly)

Returns the value of attribute needs.



16
17
18
# File 'lib/needs_manager.rb', line 16

def needs
  @needs
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/needs_manager.rb', line 16

def options
  @options
end

Class Method Details

.configure(task, needs, options) ⇒ Object



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

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

Instance Method Details

#configureObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/needs_manager.rb', line 24

def configure
  set_working_directory

  create_shell
  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



67
68
69
# File 'lib/needs_manager.rb', line 67

def create_bundler
  env[:bundler] = BundleManager.new(shell: env[:shell], repo: env[:repo])
end

#create_migratorObject



71
72
73
# File 'lib/needs_manager.rb', line 71

def create_migrator
  env[:migrator] = Migrator.new(shell: env[:shell], repo: env[:repo])
end

#create_repoObject



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

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

#create_shellObject



41
42
43
# File 'lib/needs_manager.rb', line 41

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

#create_test_runnerObject



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

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

#log_file_for(task) ⇒ Object



82
83
84
# File 'lib/needs_manager.rb', line 82

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

#repo_classObject



57
58
59
60
61
62
63
64
65
# File 'lib/needs_manager.rb', line 57

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

#set_working_directoryObject



36
37
38
39
# File 'lib/needs_manager.rb', line 36

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

#shell_classObject



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

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