Module: Berksfiler

Defined in:
lib/berksfiler.rb,
lib/berksfiler/version.rb,
lib/berksfiler/formatter.rb,
lib/berksfiler/generator.rb

Overview

Berksfiler programmatically generates Berksfiles with correct dependencies

Defined Under Namespace

Classes: Formatter, Generator

Constant Summary collapse

CONFIG_FILE =
Pathname('.berksfiler.yml').expand_path
EXCLUDED_DIRS_REGEX =

reject . and .. when globbing the cookbooks dir

/^\./
CONFIG_DEFAULTS =
{
  cookbooks_root: 'cookbooks',
  common_cookbooks: [],
  excluded_cookbooks: [],
  cookbook_options: []
}
VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.common_cookbooksObject



28
29
30
# File 'lib/berksfiler.rb', line 28

def self::common_cookbooks
  config.common_cookbooks
end

.configObject

Get the loaded config (a Configurability::Config object)



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

def self::config
  Configurability.loaded_config
end

.cookbook_optionsObject



24
25
26
# File 'lib/berksfiler.rb', line 24

def self::cookbook_options
  config.cookbook_options
end

.cookbooks_rootObject



20
21
22
# File 'lib/berksfiler.rb', line 20

def self::cookbooks_root
  Pathname(config.cookbooks_root).expand_path
end

.emplace_berksfile(cookbook) ⇒ Object

Generate a berksfile and place it in a cookbook



62
63
64
65
66
67
68
# File 'lib/berksfiler.rb', line 62

def self::emplace_berksfile(cookbook)
  puts "Generating Berksfile for local cookbook '#{cookbook}'"
  content = Generator.generate_berksfile(cookbook)
  open(File.join(cookbooks_root, cookbook, 'Berksfile'), 'w') do |f|
    f << content
  end
end

.excluded_cookbooksObject



32
33
34
# File 'lib/berksfiler.rb', line 32

def self::excluded_cookbooks
  config.excluded_cookbooks
end

.load_config(config_file = nil) ⇒ Object

Load the specified config_file and install the config



42
43
44
45
46
# File 'lib/berksfiler.rb', line 42

def self::load_config(config_file = nil)
  config_file ||= CONFIG_FILE
  config = Configurability::Config.load(config_file, CONFIG_DEFAULTS)
  config.install
end

.local_cookbooksObject

returns an array of all local cookbooks (basically a directory listing of the cookbook_root)



50
51
52
53
54
# File 'lib/berksfiler.rb', line 50

def self::local_cookbooks
  @local_cookbooks ||= Dir.entries(cookbooks_root).reject do |dir|
    dir =~ EXCLUDED_DIRS_REGEX
  end
end

.runObject

for all local cookbooks, excluding ‘excluded_cookbooks`, calculate all dependencies and programmatically generate a Berksfile for that cookbook which takes into account the correct sources for all dependencies.



73
74
75
76
77
# File 'lib/berksfiler.rb', line 73

def self::run
  local_cookbooks - excluded_cookbooks.each do |cb|
    emplace_berksfile(cb)
  end
end

.specific_cookbooksObject

returns an array of all cookbooks that have non-default options



57
58
59
# File 'lib/berksfiler.rb', line 57

def self::specific_cookbooks
  local_cookbooks + cookbook_options.map { |cb| cb['name'] }
end