Class: Dapp::Builder::Chef::Berksfile

Inherits:
Object
  • Object
show all
Defined in:
lib/dapp/builder/chef/berksfile.rb

Overview

Berksfile

Defined Under Namespace

Classes: Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(home_path, path) ⇒ Berksfile

Returns a new instance of Berksfile.



33
34
35
36
37
38
# File 'lib/dapp/builder/chef/berksfile.rb', line 33

def initialize(home_path, path)
  @home_path = home_path
  @path = path
  @local_cookbooks = {}
  @parser = Parser.new(self)
end

Instance Attribute Details

#home_pathObject (readonly)

Parser



29
30
31
# File 'lib/dapp/builder/chef/berksfile.rb', line 29

def home_path
  @home_path
end

#local_cookbooksObject (readonly)

Returns the value of attribute local_cookbooks.



31
32
33
# File 'lib/dapp/builder/chef/berksfile.rb', line 31

def local_cookbooks
  @local_cookbooks
end

#pathObject (readonly)

Returns the value of attribute path.



30
31
32
# File 'lib/dapp/builder/chef/berksfile.rb', line 30

def path
  @path
end

Instance Method Details

#add_local_cookbook_path(name, path) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dapp/builder/chef/berksfile.rb', line 40

def add_local_cookbook_path(name, path)
  raise(::Dapp::Builder::Chef::Error, code: :berksfile_absolute_path_forbidden,
                                      data: { cookbook: name, path: path }) if path.start_with? '/'

  desc = {
    name: name,
    path: home_path.join(path),
    chefignore: [],
  }

  if desc[:path].join('chefignore').exist?
    chefignore_patterns = desc[:path].join('chefignore').read.split("\n").map(&:strip)
    desc[:chefignore] = Dir[*chefignore_patterns.map {|pattern| desc[:path].join(pattern)}]
      .map(&Pathname.method(:new))
  end

  @local_cookbooks[name] = desc
end

#local_cookbook(name) ⇒ Object



63
64
65
# File 'lib/dapp/builder/chef/berksfile.rb', line 63

def local_cookbook(name)
  local_cookbooks[name]
end

#local_cookbook?(name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/dapp/builder/chef/berksfile.rb', line 59

def local_cookbook?(name)
  local_cookbooks.key? name
end