class Setup::Project

The Project class encapsulates information about the project/package setup is handling.

Setup.rb can use information about your project to provide additional features.

To inform Setup.rb of the project’s name, version and load path you can create a file in you project’s root directory called ‘.index`. This is a YAML file with minimum entries of:

---
name: foo
version: 1.0.0
paths:
  load: [lib]

See [Indexer](github.com/rubyworks/indexer) for more information about this file and how to easily maintain it.

If a ‘.index` file is not found Setup.rb will look for `.setup/name`, `.setup/version` and `.setup/loadpath` files for this information.

As of v5.1.0, Setup.rb no longer recognizes the VERSION file

Constants

ROOT_MARKER

Match used to determine the root dir of a project.

Attributes

dotindex[R]
load_path[R]
loadpath[R]
name[R]

The name of the package, used to install docs in system doc/ruby-{name}/ location.

version[R]

Current version number of project.

Public Class Methods

new() click to toggle source
# File lib/setup/project.rb, line 33
def initialize
  @dotindex_file = find('.index')

  @dotindex = YAML.load_file(@dotindex_file) if @dotindex_file

  @name     = nil
  @version  = nil
  @loadpath = ['lib']

  if @dotindex
    @name     = @dotindex['name']
    @version  = @dotindex['version']
    @loadpath = (@dotindex['paths'] || {})['load']
  else
    if file = find('.setup/name')
      @name = File.read(file).strip
    end
    if file = find('.setup/version')
      @version = File.read(file).strip
    end
    if file = find('.setup/loadpath')
      @loadpath = File.read(file).strip
    end
  end
end

Public Instance Methods

compiles?() click to toggle source
# File lib/setup/project.rb, line 96
def compiles?
  !extensions.empty?
end
document() click to toggle source
# File lib/setup/project.rb, line 106
def document
  Dir.glob(File.join(rootdir, '.document')).first
end
extconfs() click to toggle source

Setup.rb uses ‘ext/**/extconf.rb` as convention for the location of compiled scripts.

# File lib/setup/project.rb, line 86
def extconfs
  @extconfs ||= Dir['ext/**/extconf.rb']
end
extensions() click to toggle source
# File lib/setup/project.rb, line 91
def extensions
  @extensions ||= extconfs.collect{ |f| File.dirname(f) }
end
find(glob, flags=0) click to toggle source

Find a file relative to project’s root directory.

# File lib/setup/project.rb, line 111
def find(glob, flags=0)
  case flags
  when :casefold
    flags = File::FNM_CASEFOLD
  else
    flags = flags.to_i
  end      
  Dir.glob(File.join(rootdir, glob), flags).first
end
rootdir() click to toggle source

Locate project root.

# File lib/setup/project.rb, line 73
def rootdir
  @rootdir ||= (
    root = Dir.glob(File.join(Dir.pwd, ROOT_MARKER), File::FNM_CASEFOLD).first
    if !root
      raise Error, "not a project directory"
    else
      Dir.pwd
    end
  )
end
yardopts() click to toggle source
# File lib/setup/project.rb, line 101
def yardopts
  Dir.glob(File.join(rootdir, '.yardopts')).first
end