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
Constant Summary collapse
- CONFIG_FILE =
Pathname('.berksfiler.yml').
- 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
- .common_cookbooks ⇒ Object
-
.config ⇒ Object
Get the loaded config (a Configurability::Config object).
- .cookbook_options ⇒ Object
- .cookbooks_root ⇒ Object
-
.emplace_berksfile(cookbook) ⇒ Object
Generate a berksfile and place it in a
cookbook. - .excluded_cookbooks ⇒ Object
-
.load_config(config_file = nil) ⇒ Object
Load the specified
config_fileand install the config. -
.local_cookbooks ⇒ Object
returns an array of all local cookbooks (basically a directory listing of the cookbook_root).
-
.run ⇒ Object
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.
-
.specific_cookbooks ⇒ Object
returns an array of all cookbooks that have non-default options.
Class Method Details
.common_cookbooks ⇒ Object
28 29 30 |
# File 'lib/berksfiler.rb', line 28 def self::common_cookbooks config.common_cookbooks end |
.config ⇒ Object
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_options ⇒ Object
24 25 26 |
# File 'lib/berksfiler.rb', line 24 def self:: config. end |
.cookbooks_root ⇒ Object
20 21 22 |
# File 'lib/berksfiler.rb', line 20 def self::cookbooks_root Pathname(config.cookbooks_root). 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_cookbooks ⇒ Object
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_cookbooks ⇒ Object
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 |
.run ⇒ Object
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_cookbooks ⇒ Object
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 + .map { |cb| cb['name'] } end |