Class: OpsBuild::Berkshelf

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir: nil, silent: true) ⇒ Berkshelf

Returns a new instance of Berkshelf.



8
9
10
11
12
13
14
15
# File 'lib/ops_build/berkshelf.rb', line 8

def initialize(dir: nil, silent: true)
  Validations::check_binary!('berks')

  @dir = dir || Dir.mktmpdir('berks')
  @opts = ''

  @opts << '-q' if silent
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/ops_build/berkshelf.rb', line 6

def dir
  @dir
end

#optsObject (readonly)

Returns the value of attribute opts.



6
7
8
# File 'lib/ops_build/berkshelf.rb', line 6

def opts
  @opts
end

Instance Method Details

#cleanupObject

Cleanup Berks directory



33
34
35
# File 'lib/ops_build/berkshelf.rb', line 33

def cleanup
  FileUtils.rm_rf(@dir)
end

#installObject

Run berks install



26
27
28
29
# File 'lib/ops_build/berkshelf.rb', line 26

def install
  OpsBuild.logger.info('Installing cookbooks with berks')
  Utils::execute("berks install #{@opts}", log_prefix: 'berks:')
end

#vendorObject

Run berks vendor



19
20
21
22
# File 'lib/ops_build/berkshelf.rb', line 19

def vendor
  OpsBuild.logger.info("Vendoring cookbooks with berks to #{@dir}")
  Utils::execute("berks vendor #{@opts} #{@dir}", log_prefix: 'berks:')
end