Parent

Included Modules

Files

POM::Require

The Require class provide access to REQUIRE file, and models the categorized list of project dependencies. In essence it is an array of Dependency objects.

Constants

DEFAULT_FILE

Default file name to use when saving requirements to file.

FILE_PATTERN

File glob pattern to use to find a project’s requirements file.

Attributes

dependencies[R]

List of Dependency objects.

file[R]

Pathname of the requirements file.

Public Class Methods

file_pattern() click to toggle source

File glob pattern to use to find a project’s requirements file. This returns the constant FILE_PATTERN value.

# File lib/pom/require.rb, line 24
def self.file_pattern
  FILE_PATTERN
end
find(root) click to toggle source

Find the first matching requirements file.

# File lib/pom/require.rb, line 29
def self.find(root)
  root = Pathname.new(root)
  root.glob(file_pattern, File::FNM_CASEFOLD).first
end
new(root, file=nil) click to toggle source

New requirements class.

# File lib/pom/require.rb, line 41
def initialize(root, file=nil)
  @root = Pathname.new(root)
  @file = file || self.class.find(root)

  @dependencies = []

  if @file && @file.exist?
    data = YAML.load(File.new(@file))
    merge!(data)
  else
    warn "No REQUIRE file at #{root}" if $DEBUG
  end
end

Public Instance Methods

development() click to toggle source

List of all development dependencies.

# File lib/pom/require.rb, line 72
def development
  dependencies.select{ |dep| dep.development? }
end
each(&block) click to toggle source

Iterate over each dependency.

# File lib/pom/require.rb, line 56
def each(&block)
  dependencies.each(&block)
end
merge!(data) click to toggle source

Merge in another list of dependencies. This can by a Hash or another Require object.

# File lib/pom/require.rb, line 94
def merge!(data)
  data.each do |group, deps|
    deps.each do |pkg|
      dep = Dependency.new(pkg, group)
      @dependencies << dep
    end
  end
  @dependencies.uniq!   
end
requirements() click to toggle source

List of required depenedencies. This works by removing all optional dependencies from the dependencies list.

# File lib/pom/require.rb, line 67
def requirements
  dependencies.reject{ |dep| dep.optional? }
end
save!(file=nil) click to toggle source

Save dependency list to file in YAML format.

# File lib/pom/require.rb, line 87
def save!(file=nil)
  file = file || self.file || DEFAULT_FILE
  File.open(file, 'w'){ |f| f << to_yaml }
end
size() click to toggle source

Number of dependencies in total.

# File lib/pom/require.rb, line 61
def size
  dependencies.size
end
to_yaml(*args) click to toggle source

Convert dependencies list into categorized YAML.

# File lib/pom/require.rb, line 77
def to_yaml(*args)
  env = {}
  dependencies.each do |dep|
    env[dep.group] ||= []
    env[dep.group] << dep.to_s
  end
  env.to_yaml(*args)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.