Class: Monolith::Berksfile
- Inherits:
-
Object
- Object
- Monolith::Berksfile
- Defined in:
- lib/monolith/berksfile.rb
Instance Attribute Summary collapse
-
#berksfile ⇒ Object
readonly
Returns the value of attribute berksfile.
-
#cached_cookbooks ⇒ Object
readonly
Returns the value of attribute cached_cookbooks.
Instance Method Summary collapse
-
#cookbooks(path) ⇒ Object
Retrieve all cookbooks listed in the berksfile.
-
#initialize(options) ⇒ Berksfile
constructor
A new instance of Berksfile.
-
#install ⇒ Object
Runs berks install.
- #monolith_action(action, cookbook, dep, destination) ⇒ Object
-
#monolith_obj(cookbook, dep, destination) ⇒ Object
Feteches the appropriate monolith location object for a given cookbook dependency.
Constructor Details
#initialize(options) ⇒ Berksfile
Returns a new instance of Berksfile.
9 10 11 12 13 14 15 16 17 |
# File 'lib/monolith/berksfile.rb', line 9 def initialize() Berkshelf.ui.mute! if Monolith.formatter.quiet begin @berksfile = Berkshelf::Berksfile.() rescue Berkshelf::BerksfileNotFound => e Monolith.formatter.error(e) exit(e.status_code) end end |
Instance Attribute Details
#berksfile ⇒ Object (readonly)
Returns the value of attribute berksfile.
6 7 8 |
# File 'lib/monolith/berksfile.rb', line 6 def berksfile @berksfile end |
#cached_cookbooks ⇒ Object (readonly)
Returns the value of attribute cached_cookbooks.
7 8 9 |
# File 'lib/monolith/berksfile.rb', line 7 def cached_cookbooks @cached_cookbooks end |
Instance Method Details
#cookbooks(path) ⇒ Object
Retrieve all cookbooks listed in the berksfile.
Can take a block to do something with each cookbook.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/monolith/berksfile.rb', line 30 def cookbooks(path) FileUtils.mkdir_p(path) cached_cookbooks = @cached_cookbooks if block_given? cached_cookbooks.each do |cookbook| destination = File.join(File.(path), cookbook.cookbook_name) dep = berksfile.get_dependency(cookbook.cookbook_name) yield cookbook, dep, destination end end cached_cookbooks end |
#install ⇒ Object
Runs berks install. This is needed before we install cookbooks ourselves to make sure berkshelf has a local copy of them for us to clone from or copy. However, it’s not needed for other commands, so it separated out here.
23 24 25 |
# File 'lib/monolith/berksfile.rb', line 23 def install @cached_cookbooks = @berksfile.install end |
#monolith_action(action, cookbook, dep, destination) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/monolith/berksfile.rb', line 44 def monolith_action(action, cookbook, dep, destination) obj = monolith_obj(cookbook, dep, destination) if obj.nil? Monolith.formatter.unsupported_location(cookbook, dep) else obj.send(action) end end |
#monolith_obj(cookbook, dep, destination) ⇒ Object
Feteches the appropriate monolith location object for a given cookbook dependency. I.e. Monolith::FooLocation.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/monolith/berksfile.rb', line 55 def monolith_obj(cookbook, dep, destination) if dep.nil? or dep.location.nil? Monolith::DefaultLocation.new(cookbook, dep, destination) else klass = dep.location.class.name.split('::')[-1] Monolith.formatter.debug("Location class for " \ "#{cookbook.cookbook_name} is #{klass}") if Monolith.const_defined?(klass) Monolith.const_get(klass).new(cookbook, dep, destination) end end end |