Class: Cupper::Cookbook
- Inherits:
-
Object
- Object
- Cupper::Cookbook
- Defined in:
- lib/cupper/cookbook.rb
Instance Method Summary collapse
- #all_cookbook_files(collector) ⇒ Object
- #all_recipes(collector) ⇒ Object
- #expand_cookbook_files(files) ⇒ Object
- #generate ⇒ Object
-
#initialize(cookbookname = 'default') ⇒ Cookbook
constructor
TODO: Read config file to tell the project path and configs.
- #setup_paths ⇒ Object
- #text_type?(file) ⇒ Boolean
Constructor Details
#initialize(cookbookname = 'default') ⇒ Cookbook
TODO: Read config file to tell the project path and configs
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cupper/cookbook.rb', line 8 def initialize(cookbookname='default') @cookbook_path = "#{Dir.getwd}/#{cookbookname}" @cookbook_files_path = "#{@cookbook_path}/files" @cookbook_recipes_path = "#{@cookbook_path}/recipes" @recipe_deps = [ # TODO this is hard code to reflect all_recipes. Refactor this later "#{cookbookname}::cookbook_file", "#{cookbookname}::links", "#{cookbookname}::groups", "#{cookbookname}::services", "#{cookbookname}::users", "#{cookbookname}::packages", ] setup_paths end |
Instance Method Details
#all_cookbook_files(collector) ⇒ Object
46 47 48 |
# File 'lib/cupper/cookbook.rb', line 46 def all_cookbook_files(collector) (collector.extract 'files') end |
#all_recipes(collector) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/cupper/cookbook.rb', line 36 def all_recipes(collector) Recipe.new(@cookbook_recipes_path, collector, 'recipe', 'default', @recipe_deps).create Recipe.new(@cookbook_recipes_path, collector, '_cookbook_file', 'cookbook_files').create Recipe.new(@cookbook_recipes_path, collector, '_links', 'links').create Recipe.new(@cookbook_recipes_path, collector, '_groups', 'groups').create Recipe.new(@cookbook_recipes_path, collector, '_services', 'services').create Recipe.new(@cookbook_recipes_path, collector, '_users', 'users').create Recipe.new(@cookbook_recipes_path, collector, '_package', 'packages').create end |
#expand_cookbook_files(files) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cupper/cookbook.rb', line 54 def (files) files.each do |attr| if text_type?(attr) and !(attr[1]['related'].nil?) source = attr[0].split('/').last content = attr[1]['content'] CookbookFile.new(@cookbook_files_path, source, content, 'cookbook_file').create end # TODO: This is a work around to source list file # should be replaced for a better logic if text_type?(attr) and attr[0].include? "/etc/apt/sources.list" source = attr[0].split('/').last content = attr[1]['content'] CookbookFile.new(@cookbook_files_path, source, content, 'cookbook_file').create end end end |
#generate ⇒ Object
29 30 31 32 33 34 |
# File 'lib/cupper/cookbook.rb', line 29 def generate collector = Collect.new collector.setup all_recipes(collector) all_cookbook_files(collector) end |
#setup_paths ⇒ Object
23 24 25 26 27 |
# File 'lib/cupper/cookbook.rb', line 23 def setup_paths Dir.mkdir(@cookbook_path) unless Dir.exists?(@cookbook_path) Dir.mkdir(@cookbook_files_path) unless Dir.exists?(@cookbook_files_path) Dir.mkdir(@cookbook_recipes_path) unless Dir.exists?(@cookbook_recipes_path) end |
#text_type?(file) ⇒ Boolean
50 51 52 |
# File 'lib/cupper/cookbook.rb', line 50 def text_type?(file) file[1]['type'].match('text') or file[1]['type'].match('ASCII') end |