disu.se

InventoryClass

Namespace

Top-level Namespace

Ancestors
  1. Object

An Inventory keeps track of your Ruby project’s version and its content. It also allows you to #load your project’s source files in a simple manner and track its #dependencies. Add-ons, such as Inventory-Rake and Inventory-Rake-Tasks-YARD, can also use this information to great effect.

The basic usage pattern is to set your project’s Version constant to an instance of this class, where you set the version information and override the relevant methods with the information relevant to your project. For example, almost all project will want to override the #package_libs method with a method that returns an Array of the files relevant to it.

Quite a few methods have definitions that you’ll want to extend, for example, #dependencies, in which case you simply call super and add your additions to its result.

The naming convention of methods is that any method named “X_files” will return an Array of complete paths to files of kind X inside the project, while any method named “X” will return an Array of paths relative to the sub-directory that the method is named after. For example, “lib_files” returns an Array of complete paths to files under the “lib” directory ([lib/foo-1.0.rb, …]), while “libs” returns an Array of paths relative to the “lib” directory ([foo-1.0.rb]).

See Dependencies for more information on managing dependencies.

See Extension for more information on adding extensions.

Example: Creating an Inventory
require 'inventory-1.0'

class Foo
  Version = Inventory.new(1, 2, 0){
    authors{
      author 'A. U. Thor', 'a.u.thor@example.org'
    }

    homepage 'http://example.org/'

    licenses{
      license 'LGPLv3+',
              'GNU Lesser General Public License, version 3 or later',
              'http://www.gnu.org/licenses/'
    }

    def dependencies
      super + Dependencies.new{
        development 'inventory-rake', 1, 3, 0
        runtime 'bar', 1, 6, 0
      }
    end

    def package_libs
      %w'a.rb
         b.rb
         b/c.rb'
    end
  }
end

Children

Author

An author of the project stored in the list of Authors in the inventory.

Authors

Contains zero or more authors of the project.

Dependencies

Contains zero or more dependencies of the project.

Dependency

Some form of dependency of this project.

Extension

An extension represents a sub-directory under the “ext” directory in the project.

License

A license used by the project stored in the list of Licenses in the inventory.

Licenses

Contains zero or more licenses of the project.

Constructor

initialize(majorString, minorString, patchString, pathString = (m = /\A(.*):\d+(?::in .*)?\z/.match(caller.first) and m[1]))#

Sets up an inventory for version major.minor.patch for a library whose lib/PACKAGE/version.rb is at path. Any block will be #instance_exec’d.

Raises
ArgumentError

If path’s default value can’t be calculated

ArgumentError

If path isn’t of the form lib/PACKAGE/version.rb

Instance Methods

loadself#

Requires all #requires, requires all #dependencies, and loads all #loads.

authors{ … }?Authors#

Sets, when given a block, the authors of the project, otherwise returns them. The block will be #instance_exec’d inside a new Authors object, allowing you to add one or more authors.

RaisesRuntimeError

If no block has been given and no authors have previously been set

homepage(valueString = nil)String#

Sets the project homepage to value, or returns it, if value is nil.

RaisesRuntimeError

If value is nil and no homepage has previously been set

licenses{ … }?Licenses#

Sets, when given a block, the licenses of the project, otherwise returns them. The block will be #instance_exec’d inside a new Licenses object, allowing you to add one or more licenses.

RaisesRuntimeError

If no block has been given and no licenses have previously been set

dependenciesDependencies#

Returns the dependencies of the package.

Note

The default list of dependencies is an optional dependency on the inventory package itself.

requiresArray<String>#

Returns the files to require when #loading, the default being empty.

loadsArray<String>#

Returns the files to load when #loading, the default being #libs.

extensionsArray<Extension>#

Returns the extensions included in the package, the default being empty.

package_libsArray<String>#

Returns the library files belonging to the package that will be loaded when #loading, the default being empty.

libsArray<String>#

Returns the library files to load when #loading, the default being #package_libs inside a directory with the same name as #package_require.

additional_libsArray<String>#

Returns any additional library files, the default being {#package_path}-{#major}.0.rb and {#package_path}/version.rb.

all_libsArray<String>#

Returns all library files, that is, #libs + #additional_libs.

lib_filesArray<String>#

Returns the complete paths of all library files inside the package.

unit_testsArray<String>#

Returns the unit tests included in the package, the default being #all_libs, meaning that there’s one unit test for each library file.

additional_unit_testsArray<String>#

Returns any additional unit tests, the default being empty.

all_unit_testsArray<String>#

Returns all unit tests, that is #unit_tests + #additional_unit_tests.

unit_test_filesArray<String>#

Returns the complete paths of all unit test files inside the package.

test_filesArray<String>#

Returns all test files included in the package, the default being #unit_test_files.

additional_filesArray<String>#

Returns any additional files included in the package, the default being README and Rakefile.

filesArray<String>#

Returns all files included in the package, that is #lib_files + #test_files + #additional_files + all files from #extensions.

to_aArray<String>#

Returns whatever #files returns.

to_sString#

Returns the version atoms formatted as #major.#minor.#patch.

packageString#

Returns the name of the package, as derived from the #package_path.

majorInteger#

Returns the major version atom of the package.

minorInteger#

Returns the minor version atom of the package.

patchInteger#

Returns the patch version atom of the package.

pathString#

Returns the path to the file containing the inventory.

srcdirString#

Returns the top-level path of the package.

package_pathString#

Returns the root sub-directory under the “lib” directory of the package of the package.

package_requireString#

Returns the feature to require for the package.