Class: OSGi::Dependencies

Inherits:
Object show all
Defined in:
lib/buildr4osgi/osgi/dependencies.rb

Overview

A class to read dependencies.yml, and get a flat array of projects and dependencies for a project.

Defined Under Namespace

Modules: SortedHash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project = nil) ⇒ Dependencies

Returns a new instance of Dependencies.



24
25
26
# File 'lib/buildr4osgi/osgi/dependencies.rb', line 24

def initialize(project = nil)
  @project = project
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



22
23
24
# File 'lib/buildr4osgi/osgi/dependencies.rb', line 22

def dependencies
  @dependencies
end

#projectsObject

Returns the value of attribute projects.



22
23
24
# File 'lib/buildr4osgi/osgi/dependencies.rb', line 22

def projects
  @projects
end

Instance Method Details

#readObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/buildr4osgi/osgi/dependencies.rb', line 28

def read() 
  base_dir = find_root(@project).base_dir
  @dependencies = []
  @projects = []
  @deps_yml = {}
  return unless File.exists? File.join(base_dir, "dependencies.yml")
  @deps_yml =YAML.load(File.read(File.join(base_dir, "dependencies.yml")))
  return if @deps_yml[@project.name].nil? || @deps_yml[@project.name]["dependencies"].nil?
  _read(@project, false)
  @dependencies = @dependencies.flatten.compact.uniq
  return @dependencies, @projects
end

#write(projects) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/buildr4osgi/osgi/dependencies.rb', line 41

def write(projects)
  base_dir = find_root(@project).base_dir
  written_dependencies = YAML.load(File.read(File.join(base_dir, "dependencies.yml"))) if File.exists? File.join(base_dir, "dependencies.yml")
  written_dependencies ||= {}
  written_dependencies.extend SortedHash
  projects.each {|p|
    p = p.name if p.is_a?(Project) 
    written_dependencies[p] ||= {}
    written_dependencies[p].extend SortedHash
    written_dependencies[p]["dependencies"] ||= []
    written_dependencies[p]["projects"] ||= []
    yield written_dependencies, p
    written_dependencies[p]["dependencies"].sort!
    written_dependencies[p]["projects"].sort!
  }
  Buildr::write File.join(base_dir, "dependencies.yml"), written_dependencies.to_yaml
end