Class: Kamaze::Project::Tools::Vagrant::Composer

Inherits:
Object
  • Object
show all
Defined in:
lib/kamaze/project/tools/vagrant/composer.rb,
lib/kamaze/project/tools/vagrant/composer.rb,
lib/kamaze/project/tools/vagrant/composer/file.rb

Overview

Compose boxes data structure from files

Defined Under Namespace

Classes: File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Composer

Initialize from given path

Parameters:

  • path (String)


35
36
37
# File 'lib/kamaze/project/tools/vagrant/composer.rb', line 35

def initialize(path)
  @path = ::Pathname.new(path)
end

Instance Attribute Details

#pathPathname (readonly)

Path to files describing boxes

defaults to ./vagrant

Returns:

  • (Pathname)


30
31
32
# File 'lib/kamaze/project/tools/vagrant/composer.rb', line 30

def path
  @path
end

Instance Method Details

#boxesHash

Get boxes

Returns:

  • (Hash)


56
57
58
59
60
61
# File 'lib/kamaze/project/tools/vagrant/composer.rb', line 56

def boxes
  results = {}
  files.each { |file| results[file.name] = file.load }

  results
end

#boxes?Boolean

Denote existence of configured boxes

Returns:

  • (Boolean)


49
50
51
# File 'lib/kamaze/project/tools/vagrant/composer.rb', line 49

def boxes?
  !boxes.empty?
end

#dumpString

Dump (boxes) config

Returns:

  • (String)


42
43
44
# File 'lib/kamaze/project/tools/vagrant/composer.rb', line 42

def dump
  ::YAML.dump(boxes)
end

#filesArray<File>

Get files used to generate boxes

Files are indexed by name. Overrides and non-loablde files are excluded during listing.

Returns:



69
70
71
72
73
74
75
# File 'lib/kamaze/project/tools/vagrant/composer.rb', line 69

def files
  Dir.glob("#{path}/*.yml")
     .delete_if { |file| /\.override.yml$/ =~ file }
     .map { |file| File.new(file) }
     .keep_if(&:loadable?)
     .freeze
end

#sourcesArray<Pathname>

Get files related to "box files"

Almost all files stored in path are considered as source

Returns:

  • (Array<Pathname>)


82
83
84
85
86
87
# File 'lib/kamaze/project/tools/vagrant/composer.rb', line 82

def sources
  Dir.glob("#{path}/**/**")
     .map { |path| ::Pathname.new(path) }
     .keep_if(&:file?)
     .sort_by(&:to_s).freeze
end