class Ore::Project

Combines the metadata from the ‘gemspec.yml` file and the inferred information from the project directory.

Attributes

authors[R]

The authors of the project

date[R]

The build date for any project gems

default_executable[R]

The default executable

dependencies[R]

The dependencies of the project

description[R]

The project description

development_dependencies[R]

The development-dependencies of the project

document[R]

The parsed ‘.document` file

documentation[R]

The documentation of the project

emails[R]

The email contacts for the project

executables[R]

The names of the executable scripts

extra_doc_files[R]

Any extra files to include in the project documentation

files[R]

The files of the project

homepage[R]

The homepage for the project

licenses[R]

The licenses of the project

name[R]

The name of the project

namespace[R]

The fully-qualified namespace of the project

namespace_dir[R]

The directory contain the project code.

namespace_modules[R]

The inferred namespace modules of the project

post_install_message[R]

The post-installation message

project_files[R]

The files of the project

require_paths[R]

The directories to search within the project when requiring files

required_ruby_version[R]

The version of Ruby required by the project

required_rubygems_version[R]

The version of RubyGems required by the project

requirements[R]

Any external requirements needed by the project

root[R]

The root directory of the project

runtime_dependencies[R]

The runtime-dependencies of the project

scm[R]

The SCM which the project is currently under

summary[R]

The project summary

test_files[R]

The test files for the project

version[R]

The version of the project

Public Class Methods

find(dir=Dir.pwd) click to toggle source

Finds the project metadata file and creates a new {Project} object.

@param [String] dir (Dir.pwd)

The directory to start searching upward from.

@return [Project]

The found project.

@raise [ProjectNotFound]

No project metadata file could be found.
# File lib/ore/project.rb, line 305
def self.find(dir=Dir.pwd)
  Pathname.new(dir).ascend do |root|
    return self.new(root) if root.join(@@metadata_file).file?
  end

  raise(ProjectNotFound,"could not find #{@@metadata_file}")
end
new(root=Dir.pwd) click to toggle source

Creates a new {Project}.

@param [String] root

The root directory of the project.
# File lib/ore/project.rb, line 129
def initialize(root=Dir.pwd)
  @root = Pathname.new(root).expand_path

  unless @root.directory?
    raise(ProjectNotFound,"#{@root} is not a directory")
  end

  infer_scm!
  infer_project_files!

  metadata_file = @root.join(@@metadata_file)

  unless metadata_file.file?
    raise(ProjectNotFound,"#{@root} does not contain #{@@metadata_file}")
  end

  metadata = YAML.load_file(metadata_file)

  unless metadata.kind_of?(Hash)
    raise(InvalidMetadata,"#{metadata_file} did not contain valid metadata")
  end

  if metadata['name']
    @name = metadata['name'].to_s
  else
    infer_name!
  end

  # infer the namespace from the project name
  infer_namespace!

  if metadata['version']
    set_version! metadata['version']
  else
    infer_version!
  end

  @summary = (metadata['summary'] || metadata['description'])
  @description = (metadata['description'] || metadata['summary'])

  @licenses = []

  if metadata['license']
    set_license!(metadata['license'])
  end

  @authors = []

  if metadata['authors']
    set_authors! metadata['authors']
  end

  @homepage = metadata['homepage']
  @emails = []
  
  if metadata['email']
    set_emails! metadata['email']
  end

  if metadata['date']
    set_date! metadata['date']
  else
    infer_date!
  end

  @document = DocumentFile.find(self)

  @require_paths = []

  if metadata['require_paths']
    set_require_paths! metadata['require_paths']
  else
    infer_require_paths!
  end

  @executables = []

  if metadata['executables']
    set_executables! metadata['executables']
  else
    infer_executables!
  end

  @default_executable = nil

  if metadata['default_executable']
    set_default_executable! metadata['default_executable']
  else
    infer_default_executable!
  end

  if metadata['has_yard']
    @documentation = :yard
  elsif metadata.has_key?('has_rdoc')
    @documentation = if metadata['has_rdoc']
                       :rdoc
                     end
  else
    infer_documentation!
  end

  @extra_doc_files = []

  if metadata['extra_doc_files']
    set_extra_doc_files! metadata['extra_doc_files']
  else
    infer_extra_doc_files!
  end

  @files = []

  if metadata['files']
    set_files! metadata['files']
  else
    infer_files!
  end

  @test_files = []

  if metadata['test_files']
    set_test_files! metadata['test_files']
  else
    infer_test_files!
  end

  if metadata['post_install_message']
    @post_install_message = metadata['post_install_message']
  end

  @requirements = []

  if metadata['requirements']
    set_requirements! metadata['requirements']
  end

  if metadata['required_ruby_version']
    @required_ruby_version = metadata['required_ruby_version']
  end

  if metadata['required_rubygems_version']
    @required_rubygems_version = metadata['required_rubygems_version']
  else
    infer_required_rubygems_version!
  end

  @dependencies = []

  if metadata['dependencies']
    set_dependencies! metadata['dependencies']
  end

  @runtime_dependencies = []

  if metadata['runtime_dependencies']
    set_runtime_dependencies! metadata['runtime_dependencies']
  end

  @development_dependencies = []

  if metadata['development_dependencies']
    set_development_dependencies! metadata['development_dependencies']
  end
end

Public Instance Methods

build!(package=:gem) click to toggle source

Builds a gem for the project.

@param [Symbol] package

The type of package to build.

@return [Pathname]

The path to the built gem file within the `pkg/` directory.

@raise [ArgumentError]

The given package type is not supported.
# File lib/ore/project.rb, line 427
def build!(package=:gem)
  if package == :gem
    to_gem
  else
    raise(ArgumentError,"unsupported package type #{package}")
  end
end
bundled?() click to toggle source

Determines whether the project has been bundled using Bundler.

@return [Boolean]

Specifies whether the project has been bundled.
# File lib/ore/project.rb, line 387
def bundled?
  file?('Gemfile.lock')
end
bundler?() click to toggle source

Determines whether the project uses Bundler.

@return [Boolean]

Specifies whether the project uses Bundler.
# File lib/ore/project.rb, line 377
def bundler?
  file?('Gemfile')
end
email() click to toggle source

The primary email address of the project.

@return [String, nil]

The primary email address for the project.

@since 0.1.3

# File lib/ore/project.rb, line 354
def email
  @emails.first
end
has_rdoc() click to toggle source

Determines if the project contains RDoc documentation.

@return [Boolean]

Specifies whether the project has RDoc documentation.
# File lib/ore/project.rb, line 397
def has_rdoc
  @documentation == :rdoc
end
Also aliased as: has_rdoc?
has_rdoc?()
Alias for: has_rdoc
has_yard() click to toggle source

Determines if the project contains YARD documentation.

@return [Boolean]

Specifies whether the project has YARD documentation.
# File lib/ore/project.rb, line 409
def has_yard
  @documentation == :yard
end
Also aliased as: has_yard?
has_yard?()
Alias for: has_yard
license() click to toggle source

The primary license of the project.

@return [String, nil]

The primary license for the project.
# File lib/ore/project.rb, line 342
def license
  @licenses.first
end
rvm?() click to toggle source

Determines whether the project prefers using [RVM](rvm.beginrescueend.com/).

@return [Boolean]

Specifies whether the project prefers being developed under RVM.

@since 0.1.2

# File lib/ore/project.rb, line 367
def rvm?
  file?('.rvmrc')
end
within(sub_dir=nil,&block) click to toggle source

Executes code within the project.

@param [String] sub_dir

An optional sub-directory within the project to execute from.

@yield []

The given block will be called once the current working-directory
has been switched. Once the block finishes executing, the current
working-directory will be switched back.

@see ruby-doc.org/core/classes/Dir.html#M002314

# File lib/ore/project.rb, line 326
def within(sub_dir=nil,&block)
  dir = if sub_dir
          @root.join(sub_dir)
        else
          @root
        end

  Dir.chdir(dir,&block)
end

Protected Instance Methods

add_executable(name) click to toggle source

Adds an executable to the project.

@param [String] name

The name of the executable.
# File lib/ore/project.rb, line 463
def add_executable(name)
  path = File.join(@@bin_dir,name)

  check_executable(path) { |exe| @executables << exe }
end
add_extra_doc_file(path) click to toggle source

Adds an extra documentation file to the project.

@param [String] path

The path to the file, relative to the project.
# File lib/ore/project.rb, line 475
def add_extra_doc_file(path)
  check_file(path) { |file| @extra_doc_files << file }
end
add_file(path) click to toggle source

Adds a file to the project.

@param [String] path

The path to the file, relative to the project.
# File lib/ore/project.rb, line 485
def add_file(path)
  check_file(path) { |file| @files << file }
end
add_require_path(path) click to toggle source

Adds a require-path to the project.

@param [String] path

A directory path relative to the project.
# File lib/ore/project.rb, line 453
def add_require_path(path)
  check_directory(path) { |dir| @require_paths << dir }
end
add_test_file(path) click to toggle source

Adds a testing-file to the project.

@param [String] path

The path to the testing-file, relative to the project.
# File lib/ore/project.rb, line 495
def add_test_file(path)
  check_file(path) { |file| @test_files << file }
end
warn(*messages) click to toggle source

Prints multiple warning messages.

@param [Array] messages

The messages to print.
# File lib/ore/project.rb, line 443
def warn(*messages)
  messages.each { |mesg| STDERR.puts("WARNING: #{mesg}") }
end