lib/inochi/init.rb in inochi-0.3.0 vs lib/inochi/init.rb in inochi-1.0.0
- old
+ new
@@ -1,8 +1,13 @@
+#--
+# Copyright 2008 Suraj N. Kurapati
+# See the LICENSE file for details.
+#++
+
require 'yaml'
-class << Inochi
+module Inochi
##
# Establishes your project in Ruby's runtime environment by defining
# the project module (which serves as a namespace for all code in the
# project) and providing a common configuration for the project module:
#
@@ -15,87 +20,102 @@
#
# This method must be invoked from immediately within (that is, not from
# within any of its descendant directories) the project lib/ directory.
# Ideally, this method would be invoked from the main project library.
#
- # @param [Symbol] project_symbol
+ # ==== Parameters
+ #
+ # [project_symbol]
# Name of the Ruby constant which serves
# as a namespace for the entire project.
#
- # @param [Hash] project_config
- # Project configuration parameters:
+ # [project_config]
+ # Optional hash of project configuration parameters:
#
- # [String] :project =>
+ # [:project]
# Name of the project.
#
# The default value is the value of the project_symbol parameter.
#
- # [String] :tagline =>
+ # [:tagline]
# An enticing, single line description of the project.
#
# The default value is an empty string.
#
- # [String] :website =>
+ # [:website]
# URL of the published project website.
#
# The default value is an empty string.
#
- # [String] :docsite =>
+ # [:docsite]
# URL of the published user manual.
#
# The default value is the same value as the :website parameter.
#
- # [String] :program =>
+ # [:program]
# Name of the main project executable.
#
# The default value is the value of the :project parameter
# in lowercase and CamelCase converted into snake_case.
#
- # [String] :version =>
+ # [:version]
# Version of the project.
#
# The default value is "0.0.0".
#
- # [String] :release =>
+ # [:release]
# Date when this version was released.
#
# The default value is the current time.
#
- # [String] :display =>
+ # [:display]
# How the project name should be displayed.
#
# The default value is the project name and version together.
#
- # [String] :install =>
+ # [:install]
# Path to the directory which contains the project.
#
# The default value is one directory above the parent
# directory of the file from which this method was called.
#
- # [Hash] :require =>
- # The names and version constraints of ruby gems required by
- # this project. This information must be expressed as follows:
+ # [:require]
+ # Hash containing the names and version constraints of RubyGems required
+ # to run this project. This information must be expressed as follows:
#
# * Each hash key must be the name of a ruby gem.
#
# * Each hash value must be either +nil+, a single version number
# requirement string (see Gem::Requirement) or an Array thereof.
#
# The default value is an empty Hash.
#
- # @return [Module] The newly configured project module.
+ # [:develop]
+ # Hash containing the names and version constraints of RubyGems required
+ # to build this project. This information must be expressed as follows:
#
- def init project_symbol, project_config = {}
+ # * Each hash key must be the name of a ruby gem.
+ #
+ # * Each hash value must be either +nil+, a single version number
+ # requirement string (see Gem::Requirement) or an Array thereof.
+ #
+ # The default value is an empty Hash.
+ #
+ # ==== Returns
+ #
+ # The newly configured project module.
+ #
+ def Inochi.init project_symbol, project_config = {}
project_module = fetch_project_module(project_symbol)
# this method is not re-entrant
@already_seen ||= []
return project_module if @already_seen.include? project_module
@already_seen << project_module
# put project on Ruby load path
- project_file = File.expand_path(first_caller_file)
+ project_file = first_caller_file
project_libs = File.dirname(project_file)
$LOAD_PATH << project_libs unless $LOAD_PATH.include? project_libs
# supply configuration defaults
project_config[:project] ||= project_symbol.to_s
@@ -106,21 +126,18 @@
project_config[:docsite] ||= project_config[:website]
project_config[:display] ||= "#{project_config[:project]} #{project_config[:version]}"
project_config[:program] ||= calc_program_name(project_symbol)
project_config[:install] ||= File.dirname(project_libs)
project_config[:require] ||= {}
+ project_config[:develop] ||= {}
# establish gem version dependencies and
# sanitize the values while we're at it
src = project_config[:require].dup
dst = project_config[:require].clear
src.each_pair do |gem_name, version_reqs|
- gem_name = gem_name.to_s
- version_reqs = [version_reqs].flatten.compact
-
- dst[gem_name] = version_reqs
- gem gem_name, *version_reqs
+ dst[gem_name] = require_gem_version(gem_name, version_reqs)
end
# make configuration parameters available as constants
project_config[:inochi] = project_config
project_config[:phrases] = Phrases.new project_config[:install]