Class: Batali::Origin::Path
- Inherits:
-
Batali::Origin
- Object
- Grimoire::Utility
- Utility
- Batali::Origin
- Batali::Origin::Path
- Includes:
- Bogo::Memoization
- Defined in:
- lib/batali/origin/path.rb
Overview
Fetch unit from local path
Direct Known Subclasses
Defined Under Namespace
Classes: Metadata
Instance Method Summary collapse
-
#initialize(*_) ⇒ Path
constructor
A new instance of Path.
-
#load_metadata ⇒ Smash
Metadata information.
- #units ⇒ Array<Unit>
Constructor Details
#initialize(*_) ⇒ Path
Returns a new instance of Path.
33 34 35 36 37 38 39 |
# File 'lib/batali/origin/path.rb', line 33 def initialize(*_) super self.identifier = Smash.new(:path => path).checksum unless(name?) self.name = identifier end end |
Instance Method Details
#load_metadata ⇒ Smash
Returns metadata information.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/batali/origin/path.rb', line 76 def memoize(:metadata) do if(File.exist?(json = File.join(path, 'metadata.json'))) MultiJson.load(json).to_smash elsif(File.exist?(rb = File.join(path, 'metadata.rb'))) struct = Metadata.new struct.set_state!(:value_collapse => true) struct.instance_eval(File.read(rb), rb, 1) struct._dump.to_smash else raise Errno::ENOENT.new("Failed to locate metadata file in cookbook directory! (path: #{path})") end end end |
#units ⇒ Array<Unit>
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/batali/origin/path.rb', line 42 def units memoize(:units) do info = if(info[:depends]) unless(info[:depends].first.is_a?(Array)) info[:depends] = [info[:depends]] end info[:depends] = info[:depends].map do |dep| case dep when String [dep, '> 0'] else dep.size == 1 ? dep.push('> 0') : dep end end end [ Unit.new( :name => info[:name], :version => info[:version], :dependencies => info.fetch(:depends, []), :source => Smash.new( :type => :path, :version => info[:version], :path => path, :dependencies => info.fetch(:depends, []), :cache_path => cache_path ) ) ] end end |