Class: Cocina::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ CLI

Returns a new instance of CLI.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cocina/cli.rb', line 10

def initialize(target)
  super()

  @dependencies = []
  @config = Cocina::Config.new('Cocinafile')
  @logger = Kitchen::Logger.new(
    stdout: STDOUT,
    color: :white,
    progname: 'Cocina'
  )
  @primary_instance = instance(target)
  @primary_dependencies = primary_instance.dependencies
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



7
8
9
# File 'lib/cocina/cli.rb', line 7

def collection
  @collection
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/cocina/cli.rb', line 7

def config
  @config
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



7
8
9
# File 'lib/cocina/cli.rb', line 7

def dependencies
  @dependencies
end

#instancesObject (readonly)

Returns the value of attribute instances.



7
8
9
# File 'lib/cocina/cli.rb', line 7

def instances
  @instances
end

#loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/cocina/cli.rb', line 8

def logger
  @logger
end

#primary_dependenciesObject (readonly)

Returns the value of attribute primary_dependencies.



8
9
10
# File 'lib/cocina/cli.rb', line 8

def primary_dependencies
  @primary_dependencies
end

#primary_instanceObject (readonly)

Returns the value of attribute primary_instance.



8
9
10
# File 'lib/cocina/cli.rb', line 8

def primary_instance
  @primary_instance
end

Instance Method Details

#cleanupObject



55
56
57
58
59
60
# File 'lib/cocina/cli.rb', line 55

def cleanup
  log_banner "Cleaning up all dependencies"
  destroy_dependencies
  primary_instance.destroy
  nil
end

#converge_dependenciesObject



45
46
47
48
# File 'lib/cocina/cli.rb', line 45

def converge_dependencies
  logger.info "Dependencies: #{dependencies}"
  dependencies.each {|dep| converge_dependency dep }
end

#converge_dependency(dep) ⇒ Object



50
51
52
53
# File 'lib/cocina/cli.rb', line 50

def converge_dependency(dep)
  log_banner "Converging <#{dep}>"
  instance(dep).converge
end

#destroy_dependenciesObject



62
63
64
65
66
67
# File 'lib/cocina/cli.rb', line 62

def destroy_dependencies
  dependencies.each do |dep|
    logger.info "Destroying #{dep}"
    instance(dep).destroy
  end
end

#instance(id) ⇒ Object



34
35
36
# File 'lib/cocina/cli.rb', line 34

def instance(id)
  @config[id]
end

#log_banner(msg) ⇒ Object



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

def log_banner(msg)
  logger.banner "#{msg}"
end

#prepare_dependenciesObject



38
39
40
41
42
43
# File 'lib/cocina/cli.rb', line 38

def prepare_dependencies
  primary_dependencies.each do |dep|
    @dependencies.concat instance(dep).dependencies
    @dependencies << dep
  end
end

#runObject



24
25
26
27
28
29
30
31
32
# File 'lib/cocina/cli.rb', line 24

def run
  log_banner "Running for: #{primary_instance.name}"

  prepare_dependencies
  converge_dependencies

  primary_instance.verify
  cleanup
end