inventory 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README +211 -4
- data/Rakefile +8 -2
- data/lib/inventory-1.0.rb +139 -12
- data/lib/inventory-1.0/dependencies.rb +102 -0
- data/lib/inventory-1.0/dependencies/development.rb +22 -0
- data/lib/inventory-1.0/dependencies/optional.rb +14 -0
- data/lib/inventory-1.0/dependencies/runtime.rb +8 -0
- data/lib/inventory-1.0/dependency.rb +85 -0
- data/lib/inventory-1.0/extension.rb +82 -0
- data/lib/inventory-1.0/version.rb +23 -0
- data/test/unit/inventory-1.0.rb +8 -0
- data/test/unit/{inventory → inventory-1.0}/dependencies.rb +0 -0
- data/test/unit/{inventory → inventory-1.0}/dependencies/development.rb +0 -0
- data/test/unit/{inventory → inventory-1.0}/dependencies/optional.rb +0 -0
- data/test/unit/{inventory → inventory-1.0}/dependencies/runtime.rb +0 -0
- data/test/unit/{inventory → inventory-1.0}/dependency.rb +0 -0
- data/test/unit/{inventory/version.rb → inventory-1.0/extension.rb} +0 -0
- data/test/unit/inventory-1.0/version.rb +4 -0
- metadata +262 -40
- data/lib/inventory/dependencies.rb +0 -54
- data/lib/inventory/dependencies/development.rb +0 -14
- data/lib/inventory/dependencies/optional.rb +0 -9
- data/lib/inventory/dependencies/runtime.rb +0 -5
- data/lib/inventory/dependency.rb +0 -30
- data/lib/inventory/version.rb +0 -24
@@ -0,0 +1,102 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# Contains zero or more {Dependency dependencies} of the project. Dependencies
|
4
|
+
# can be {#+ added}, {#require}d, {#each enumerated}, and
|
5
|
+
# {#add_to_gem_specification added to Gem specifications}. Dependencies are
|
6
|
+
# set up by passing a block to {#initialize} and calling {#development},
|
7
|
+
# {#runtime}, and {#optional} inside it.
|
8
|
+
#
|
9
|
+
# @example Creating a List of Dependencies
|
10
|
+
# Dependencies.new{
|
11
|
+
# development 'inventory-rake', 1, 3, 0
|
12
|
+
# runtime 'bar', 1, 6, 0
|
13
|
+
# }
|
14
|
+
class Inventory::Dependencies
|
15
|
+
include Enumerable
|
16
|
+
|
17
|
+
# Creates a new list of DEPENDENCIES and allows more to be added in the
|
18
|
+
# optionally #instance_exec’d block by calling {#development}, {#runtime},
|
19
|
+
# and {#optional} inside it.
|
20
|
+
#
|
21
|
+
# @param [Array<Dependency>] dependencies
|
22
|
+
# @yield [?]
|
23
|
+
def initialize(*dependencies)
|
24
|
+
@dependencies = dependencies
|
25
|
+
instance_exec(&Proc.new) if block_given?
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Add a {Development} dependency on project NAME, version MAJOR, MINOR,
|
31
|
+
# PATCH, along with any OPTIONS.
|
32
|
+
#
|
33
|
+
# @param (see Inventory::Dependency#initialize)
|
34
|
+
# @option (see Inventory::Dependency#initialize)
|
35
|
+
def development(name, major, minor, patch, options = {})
|
36
|
+
dependencies << Development.new(name, major, minor, patch, options)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Add a {Runtime} dependency on project NAME, version MAJOR, MINOR, PATCH,
|
41
|
+
# along with any OPTIONS.
|
42
|
+
#
|
43
|
+
# @param (see Inventory::Dependency#initialize)
|
44
|
+
# @option (see Inventory::Dependency#initialize)
|
45
|
+
def runtime(name, major, minor, patch, options = {})
|
46
|
+
dependencies << Runtime.new(name, major, minor, patch, options)
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add an {Optional} dependency on project NAME, version MAJOR, MINOR, PATCH,
|
51
|
+
# along with any OPTIONS.
|
52
|
+
#
|
53
|
+
# @param (see Inventory::Dependency#initialize)
|
54
|
+
# @option (see Inventory::Dependency#initialize)
|
55
|
+
def optional(name, major, minor, patch, options = {})
|
56
|
+
dependencies << Optional.new(name, major, minor, patch, options)
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
public
|
61
|
+
|
62
|
+
# @return [Dependencies] The dependencies of the receiver and those of OTHER
|
63
|
+
def +(other)
|
64
|
+
self.class.new(*(dependencies + other.dependencies))
|
65
|
+
end
|
66
|
+
|
67
|
+
# @overload
|
68
|
+
# Enumerates the dependencies.
|
69
|
+
#
|
70
|
+
# @yieldparam [Dependency] dependency
|
71
|
+
# @overload
|
72
|
+
# @return [Enumerator<Dependency>] An Enumerator over the dependencies
|
73
|
+
def each
|
74
|
+
return enum_for(__method__) unless block_given?
|
75
|
+
dependencies.each do |dependency|
|
76
|
+
yield dependency
|
77
|
+
end
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
# {Dependency#require Require} each dependency in turn.
|
82
|
+
# @return [self]
|
83
|
+
def require
|
84
|
+
map{ |dependency| dependency.require }
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
# {Dependency#add_to_gem_specification Add} each dependency to a Gem
|
89
|
+
# specification.
|
90
|
+
# @param [Gem::Specification] specification
|
91
|
+
# @return [self]
|
92
|
+
def add_to_gem_specification(specification)
|
93
|
+
each do |dependency|
|
94
|
+
dependency.add_to_gem_specification specification
|
95
|
+
end
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
|
101
|
+
attr_reader :dependencies
|
102
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# A development dependency is one that’s needed during development of a
|
4
|
+
# project. It won’t be required when the library is loaded, but it will be
|
5
|
+
# added to a Gem specification as a development dependency.
|
6
|
+
class Inventory::Dependencies::Development
|
7
|
+
include Inventory::Dependency
|
8
|
+
|
9
|
+
# Do nothing.
|
10
|
+
# @return [nil]
|
11
|
+
def require
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
# Add the receiver as a development dependency to SPECIFICATION.
|
16
|
+
# @param [Gem::Specification] specification
|
17
|
+
# @return [self]
|
18
|
+
def add_to_gem_specification(specification)
|
19
|
+
specification.add_development_dependency name, gem_requirement
|
20
|
+
self
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# An optional dependency is one that may or may not be needed during runtime.
|
4
|
+
# It won’t be required when the library is loaded, but it will be added to a
|
5
|
+
# Gem specification as a runtime dependency.
|
6
|
+
class Inventory::Dependencies::Optional
|
7
|
+
include Inventory::Dependency
|
8
|
+
|
9
|
+
# Do nothing.
|
10
|
+
# @return [nil]
|
11
|
+
def require
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# A runtime dependency is one that’s needed during runtime. It’ll be required
|
4
|
+
# when the library is loaded and added to a Gem specification as a runtime
|
5
|
+
# dependency.
|
6
|
+
class Inventory::Dependencies::Runtime
|
7
|
+
include Inventory::Dependency
|
8
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# Some form of dependency of this project. A dependency can be {#require}d,
|
4
|
+
# {#add_to_gem_specification added to a gem specification}, and has various
|
5
|
+
# information associated with it: {#name}, {#major}, {#minor}, {#patch}, and
|
6
|
+
# {#feature}.
|
7
|
+
module Inventory::Dependency
|
8
|
+
# Sets up a dependency on project NAME, version MAJOR, MINOR, PATCH, along
|
9
|
+
# with any OPTIONS. Any methods may be overridden on the instance in the
|
10
|
+
# optionally #instance_exec’d block, if a dependency has any non-standard
|
11
|
+
# requirements.
|
12
|
+
#
|
13
|
+
# @param [String] name
|
14
|
+
# @param [Integer] major
|
15
|
+
# @param [Integer] minor
|
16
|
+
# @param [Integer] patch
|
17
|
+
# @param [Hash] options
|
18
|
+
# @option options [String] :feature ('%s-%s.0' % [name.gsub('-', '/'),
|
19
|
+
# major]) The name of the feature to load
|
20
|
+
def initialize(name, major, minor, patch, options = {})
|
21
|
+
@name, @major, @minor, @patch = name, major, minor, patch
|
22
|
+
@altfeature = nil
|
23
|
+
@feature = options.fetch(:feature){
|
24
|
+
@altfeature = '%s-%d.0' % [name.gsub('-', '/'), major]
|
25
|
+
'%s-%d.0' % [name, major]
|
26
|
+
}
|
27
|
+
instance_exec(&Proc.new) if block_given?
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean] The result of requiring {#feature}
|
31
|
+
def require
|
32
|
+
super feature
|
33
|
+
rescue LoadError => e
|
34
|
+
if not e.respond_to? :path or e.path.end_with? feature
|
35
|
+
begin
|
36
|
+
super @altfeature
|
37
|
+
rescue LoadError
|
38
|
+
raise e
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Add the receiver as a runtime dependency to SPECIFICATION.
|
44
|
+
# @param [Gem::Specification] specification
|
45
|
+
# @return [self]
|
46
|
+
def add_to_gem_specification(specification)
|
47
|
+
specification.add_runtime_dependency name, gem_requirement
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [String] The version atoms on the form {#major}.{#minor}.{#patch}
|
52
|
+
def to_s
|
53
|
+
[major, minor, patch].join('.')
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [String] The name of the project that this dependency pertains to
|
57
|
+
attr_reader :name
|
58
|
+
|
59
|
+
# @return [Integer] The major version atom of the dependency
|
60
|
+
attr_reader :major
|
61
|
+
|
62
|
+
# @return [Integer] The minor version atom of the dependency
|
63
|
+
attr_reader :minor
|
64
|
+
|
65
|
+
# @return [Integer] The patch version atom of the dependency
|
66
|
+
attr_reader :patch
|
67
|
+
|
68
|
+
# @return [String] The name of the feature to {#require}
|
69
|
+
attr_reader :feature
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
# Returns the version range to use in {#add_to_gem_specification}. The
|
74
|
+
# default is to use `~>` {#major}.{#minor} if {#major} > 0 and `~>`
|
75
|
+
# {#major}.{#minor}.{#patch} otherwise. The reasoning here is that the
|
76
|
+
# version numbers are using [semantic versioning](http://semver.org) with the
|
77
|
+
# unfortunate use of minor and patch as a fake major/minor combination when
|
78
|
+
# major is 0, which is most often the case for Ruby projects. Start your
|
79
|
+
# major versions at 1 and you’ll avoid this misuse of version numbers.
|
80
|
+
#
|
81
|
+
# @return [String]
|
82
|
+
def gem_requirement
|
83
|
+
'~> %s' % (major > 0 ? '%d.%d' % [major, minor] : to_s)
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# An extension represents a sub-directory under the “ext” directory in the
|
4
|
+
# project. Such a directory contains source files, usually written in C, that
|
5
|
+
# interface with the underlying Ruby implementation, and possibly other
|
6
|
+
# low-level systems, that aren’t otherwise available to Ruby code.
|
7
|
+
#
|
8
|
+
# For an inventory, an extension is a set of files that should be included in
|
9
|
+
# the project and can contain multiple extensions.
|
10
|
+
# [Inventory-Rake](http://disu.se/software/inventory-rake/) uses information
|
11
|
+
# found in these extensions to compile them for use from Ruby code.
|
12
|
+
class Inventory::Extension
|
13
|
+
# Creates an extension named NAME. A block may be given that’ll be
|
14
|
+
# \#instance_exec’d in the extension being created so that various methods may
|
15
|
+
# be overridden to suit the extension being created.
|
16
|
+
#
|
17
|
+
# @param [String] name
|
18
|
+
# @yield [?]
|
19
|
+
def initialize(name)
|
20
|
+
@name = name
|
21
|
+
instance_exec(&Proc.new) if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] The sub-directory into the project that contains the
|
25
|
+
# extension, the default being `ext/{#name}`
|
26
|
+
def directory
|
27
|
+
'ext/%s' % name
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String] The path into the project that contains the “extconf.rb”
|
31
|
+
# file for the extension, the default being `{#directory}/extconf.rb`
|
32
|
+
def extconf
|
33
|
+
'%s/extconf.rb' % directory
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String] The path into the project that contains the “depend”
|
37
|
+
# file for the extension, the default being `{#directory}/depend`
|
38
|
+
# @note This file is usually created by hand by invoking `gcc -MM *.c >
|
39
|
+
# depend`
|
40
|
+
def depend
|
41
|
+
'%s/depend' % directory
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Array<String>] The source files that make up the extension, the
|
45
|
+
# default being empty
|
46
|
+
def sources
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Array<String>] The complete paths of {#sources} inside the package
|
51
|
+
def source_files
|
52
|
+
sources.map{ |e| '%s/%s' % [directory, e] }
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Array<String>] The complete paths to any additional files
|
56
|
+
def additional_files
|
57
|
+
[]
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Array<String>] All files included in the package, that is
|
61
|
+
# [{#extconf}, {#depend}] + {#source_files} + {#additional_files}
|
62
|
+
def files
|
63
|
+
[extconf, depend] + source_files + additional_files
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Array<String>] Whatever {#files} returns
|
67
|
+
def to_a
|
68
|
+
files
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [String] The receiver’s {#name}
|
72
|
+
def to_s
|
73
|
+
name
|
74
|
+
end
|
75
|
+
|
76
|
+
def inspect
|
77
|
+
'#<%s: %s %s>' % [self.class, name, directory]
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [String] The receiver’s {#name}
|
81
|
+
attr_reader :name
|
82
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class Inventory
|
4
|
+
Version = Inventory.new(1, 4, 0){
|
5
|
+
def dependencies
|
6
|
+
Dependencies.new{
|
7
|
+
development 'inventory-rake', 1, 4, 0
|
8
|
+
development 'lookout', 3, 0, 0
|
9
|
+
development 'lookout-rake', 3, 0, 0
|
10
|
+
development 'yard', 0, 8, 5
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def package_libs
|
15
|
+
%w[dependency.rb
|
16
|
+
dependencies.rb
|
17
|
+
dependencies/development.rb
|
18
|
+
dependencies/optional.rb
|
19
|
+
dependencies/runtime.rb
|
20
|
+
extension.rb]
|
21
|
+
end
|
22
|
+
}
|
23
|
+
end
|
data/test/unit/inventory-1.0.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
Expectations do
|
4
|
+
expect 'a/lib/a/version.rb' do
|
5
|
+
Inventory.new(1, 0, 0, 'a/lib/a/version.rb').path
|
6
|
+
end
|
7
|
+
|
8
|
+
expect 'a' do
|
9
|
+
Inventory.new(1, 0, 0, 'a/lib/a/version.rb').package_path
|
10
|
+
end
|
11
|
+
|
4
12
|
expect 'a' do
|
5
13
|
Inventory.new(1, 0, 0, 'a/lib/a/version.rb').package
|
6
14
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,107 +1,329 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inventory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nikolai Weibull
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: inventory-rake
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '1.
|
19
|
+
version: '1.4'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: lookout
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ~>
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '3.0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: lookout-rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
45
|
- - ~>
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '3.0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: yard
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
59
|
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.8.
|
61
|
+
version: 0.8.5
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.5
|
69
|
+
description: |2
|
70
|
+
Inventory
|
71
|
+
|
72
|
+
Inventory keeps track of the contents of your Ruby¹ projects. Such an
|
73
|
+
inventory can be used to load the project, create gem specifications and
|
74
|
+
gems, run unit tests, compile extensions, and verify that the project’s
|
75
|
+
content is what you think it is.
|
76
|
+
|
77
|
+
¹ See http://ruby-lang.org/
|
78
|
+
|
79
|
+
§ Usage
|
80
|
+
|
81
|
+
Let’s begin by discussing the project structure that Inventory expects you
|
82
|
+
to use. It’s pretty much exactly the same as the standard Ruby project
|
83
|
+
structure¹:
|
84
|
+
|
85
|
+
├── README
|
86
|
+
├── Rakefile
|
87
|
+
├── lib
|
88
|
+
│ ├── foo-1.0
|
89
|
+
│ │ ├── bar.rb
|
90
|
+
│ │ └── version.rb
|
91
|
+
│ └── foo-1.0.rb
|
92
|
+
└── test
|
93
|
+
└── unit
|
94
|
+
├── foo-1.0
|
95
|
+
│ ├── bar.rb
|
96
|
+
│ └── version.rb
|
97
|
+
└── foo-1.0.rb
|
98
|
+
|
99
|
+
Here you see a simplified version of a project called “Foo”’s project
|
100
|
+
structure. The only real difference from the standard is that the main
|
101
|
+
entry point into the library is named “foo-1.0.rb” instead of “foo.rb” and
|
102
|
+
that the root sub-directory of “lib” is similarly named “foo-1.0” instead
|
103
|
+
of “foo”. The difference is the inclusion of the API version. This must
|
104
|
+
be the major version of the project followed by a constant “.0”. The
|
105
|
+
reason for this is that it allows concurrent installations of different
|
106
|
+
major versions of the project and means that the wrong version will never
|
107
|
+
accidentally be loaded with require.
|
108
|
+
|
109
|
+
There’s a bigger difference in the content of the files.
|
110
|
+
‹Lib/foo-1.0/version.rb› will contain our inventory instead of a String:
|
111
|
+
|
112
|
+
require 'inventory-1.0'
|
113
|
+
|
114
|
+
class Foo
|
115
|
+
Version = Foo.new(1, 4, 0){
|
116
|
+
def dependencies
|
117
|
+
super + Dependencies.new{
|
118
|
+
development 'baz', 1, 3, 0
|
119
|
+
runtime 'goo', 2, 0, 0
|
120
|
+
optional 'roo-loo', 3, 0, 0, :feature => 'roo-loo'
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def package_libs
|
125
|
+
%w[bar.rb]
|
126
|
+
end
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
We’re introducing quite a few concepts at once, and we’ll look into each in
|
131
|
+
greater detail, but we begin by setting the ‹Version› constant to a new
|
132
|
+
instance of an Inventory with major, minor, and patch version atoms 1, 4,
|
133
|
+
and 0. Then we add a couple of dependencies and list the library files
|
134
|
+
that are included in this project.
|
135
|
+
|
136
|
+
The version numbers shouldn’t come as a surprise. These track the version
|
137
|
+
of the API that we’re shipping using {semantic versioning}². They also
|
138
|
+
allow the Inventory#to_s method to act as if you’d defined Version as
|
139
|
+
‹'1.4.0'›.
|
140
|
+
|
141
|
+
We then extend the definition of ‹dependencies› by adding another set of
|
142
|
+
dependencies to ‹super›. ‹Super› includes a dependency on the version of
|
143
|
+
the inventory project that’s being used with this project, so you’ll never
|
144
|
+
have to list that yourself. The other three dependencies are all of
|
145
|
+
different kinds: development, runtime, and optional. A development
|
146
|
+
dependency is one that’s required while developing the project, for
|
147
|
+
example, a unit-testing framework, a documentation generator, and so on.
|
148
|
+
Runtime dependencies are requirements of the project to be able to run,
|
149
|
+
both during development and when installed. Finally, optional dependencies
|
150
|
+
are runtime dependencies that may or may not be required during execution.
|
151
|
+
The difference between runtime and optional is that the inventory won’t try
|
152
|
+
to automatically load an optional dependency, instead leaving that up to
|
153
|
+
you to do when and if it becomes necessary. By that logic, runtime
|
154
|
+
dependencies will be automatically loaded, which is a good reason for
|
155
|
+
having dependency information available at runtime.
|
156
|
+
|
157
|
+
The version numbers of dependencies also use semantic versioning, but note
|
158
|
+
that the patch atom is ignored unless the major atom is 0. You should
|
159
|
+
always only depend on the major and minor atoms.
|
160
|
+
|
161
|
+
As mentioned, runtime dependencies will be automatically loaded and the
|
162
|
+
feature they try to load is based on the name of the dependency with a
|
163
|
+
“-X.0” tacked on the end, where ‘X’ is the major version of the dependency.
|
164
|
+
Sometimes, this isn’t correct, in which case the :feature option may be
|
165
|
+
given to specify the name of the feature.
|
166
|
+
|
167
|
+
You may also override other parts of a dependency by passing in a block to
|
168
|
+
the dependency, much like we’re doing for inventories.
|
169
|
+
|
170
|
+
The rest of an inventory will list the various files included in the
|
171
|
+
project. This project only consists of one additional file to those that
|
172
|
+
an inventory automatically include (Rakefile, README, the main entry point,
|
173
|
+
and the version.rb file that defines the inventory itself), namely the
|
174
|
+
library file ‹bar.rb›. Library files will be loaded automatically when the
|
175
|
+
main entry point file loads the inventory. Library files that shouldn’t be
|
176
|
+
loaded may be listed under a different heading, namely “additional_libs”.
|
177
|
+
Both these sets of files will be used to generate a list of unit test files
|
178
|
+
automatically, so each library file will have a corresponding unit test
|
179
|
+
file in the inventory. We’ll discuss the different headings of an
|
180
|
+
inventory in more detail later on.
|
181
|
+
|
182
|
+
Now that we’ve written our inventory, let’s set it up so that it’s content
|
183
|
+
gets loaded when our main entry point gets loaded. We add the following
|
184
|
+
piece of code to ‹lib/foo-1.0.rb›:
|
185
|
+
|
186
|
+
module Foo
|
187
|
+
load File.expand_path('../foo-1.0/version.rb', __FILE__)
|
188
|
+
Version.load
|
189
|
+
end
|
190
|
+
|
191
|
+
That’s all there’s to it.
|
192
|
+
|
193
|
+
The inventory can also be used to great effect from a Rakefile using a
|
194
|
+
separate project called Inventory-Rake³. Using it’ll give us tasks for
|
195
|
+
cleaning up our project, compiling extensions, installing dependencies,
|
196
|
+
installing and uninstalling the project itself, and creating and pushing
|
197
|
+
distribution files to distribution points.
|
198
|
+
|
199
|
+
require 'inventory-rake-1.0'
|
200
|
+
|
201
|
+
load File.expand_path('../lib/foo-1.0/version.rb', __FILE__)
|
202
|
+
|
203
|
+
Inventory::Rake::Tasks.define Foo::Version, :gem => proc{ |_, s|
|
204
|
+
s.author = 'Your Name'
|
205
|
+
s.email = 'you@example.com'
|
206
|
+
s.homepage = 'https://example.com/'
|
207
|
+
}
|
208
|
+
|
209
|
+
Inventory::Rake::Tasks.unless_installing_dependencies do
|
210
|
+
require 'lookout-rake-3.0'
|
211
|
+
Lookout::Rake::Tasks::Test.new
|
212
|
+
end
|
213
|
+
|
214
|
+
It’s ‹Inventory::Rake::Tasks.define› that does the heavy lifting. It takes
|
215
|
+
our inventory and sets up the tasks mentioned above. We also do some
|
216
|
+
additional customization of the gem specification.
|
217
|
+
|
218
|
+
As we want to be able to use our Rakefile to install our dependencies for
|
219
|
+
us, the rest of the Rakefile is inside the conditional
|
220
|
+
#unless_installing_dependencies, which, as the name certainly implies,
|
221
|
+
executes its block unless the task being run is the one that installs our
|
222
|
+
dependencies. This becomes relevant when we set up Travis⁴ integration
|
223
|
+
next. The only conditional set-up we do in our Rakefile is creating our
|
224
|
+
test task via Lookout-Rake⁵, which also uses our inventory to find the unit
|
225
|
+
tests to run when executed.
|
226
|
+
|
227
|
+
Travis integration is straightforward. Simply put
|
228
|
+
|
229
|
+
before_script:
|
230
|
+
- gem install inventory-rake -v '~> VERSION' --no-rdoc --no-ri
|
231
|
+
- rake gem:deps:install
|
232
|
+
|
233
|
+
in the project’s ‹.travis.yml› file, replacing ‹VERSION› with the version
|
234
|
+
of Inventory-Rake that you require. This’ll make sure that Travis installs
|
235
|
+
all development, runtime, and optional dependencies that you’ve listed in
|
236
|
+
your inventory before running any tests.
|
237
|
+
|
238
|
+
You might also need to put
|
239
|
+
|
240
|
+
env:
|
241
|
+
- RUBYOPT=rubygems
|
242
|
+
|
243
|
+
in your ‹.travis.yml› file, depending on how things are set up.
|
244
|
+
|
245
|
+
¹ Ruby project structure: http://guides.rubygems.org/make-your-own-gem/
|
246
|
+
² Semantic versioning: http://semver.org/
|
247
|
+
³ Inventory-Rake: http://disu.se/software/inventory-rake/
|
248
|
+
⁴ Travis: http://travis-ci.org/
|
249
|
+
⁵ Lookout-Rake: http://disu.se/software/lookout-rake/
|
250
|
+
|
251
|
+
§ API
|
252
|
+
|
253
|
+
If the guide above doesn’t provide you with all the answers you seek, you
|
254
|
+
may refer to the API¹ for more answers.
|
255
|
+
|
256
|
+
¹ See http://disu.se/software/inventory/api/inventory/
|
257
|
+
|
258
|
+
§ Financing
|
259
|
+
|
260
|
+
Currently, most of my time is spent at my day job and in my rather busy
|
261
|
+
private life. Please motivate me to spend time on this piece of software
|
262
|
+
by donating some of your money to this project. Yeah, I realize that
|
263
|
+
requesting money to develop software is a bit, well, capitalistic of me.
|
264
|
+
But please realize that I live in a capitalistic society and I need money
|
265
|
+
to have other people give me the things that I need to continue living
|
266
|
+
under the rules of said society. So, if you feel that this piece of
|
267
|
+
software has helped you out enough to warrant a reward, please PayPal a
|
268
|
+
donation to now@disu.se¹. Thanks! Your support won’t go unnoticed!
|
269
|
+
|
270
|
+
¹ Send a donation:
|
271
|
+
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=now%40disu%2ese&item_name=Nikolai%20Weibull%20Software%20Services
|
272
|
+
|
273
|
+
§ Reporting Bugs
|
274
|
+
|
275
|
+
Please report any bugs that you encounter to the {issue tracker}¹.
|
276
|
+
|
277
|
+
¹ See https://github.com/now/inventory/issues
|
278
|
+
|
279
|
+
§ Authors
|
280
|
+
|
281
|
+
Nikolai Weibull wrote the code, the tests, the documentation, and this
|
282
|
+
README.
|
62
283
|
email: now@bitwi.se
|
63
284
|
executables: []
|
64
285
|
extensions: []
|
65
286
|
extra_rdoc_files: []
|
66
287
|
files:
|
67
|
-
- lib/inventory/dependency.rb
|
68
|
-
- lib/inventory/dependencies.rb
|
69
|
-
- lib/inventory/dependencies/development.rb
|
70
|
-
- lib/inventory/dependencies/optional.rb
|
71
|
-
- lib/inventory/dependencies/runtime.rb
|
288
|
+
- lib/inventory-1.0/dependency.rb
|
289
|
+
- lib/inventory-1.0/dependencies.rb
|
290
|
+
- lib/inventory-1.0/dependencies/development.rb
|
291
|
+
- lib/inventory-1.0/dependencies/optional.rb
|
292
|
+
- lib/inventory-1.0/dependencies/runtime.rb
|
293
|
+
- lib/inventory-1.0/extension.rb
|
72
294
|
- lib/inventory-1.0.rb
|
73
|
-
- lib/inventory/version.rb
|
74
|
-
- test/unit/inventory/dependency.rb
|
75
|
-
- test/unit/inventory/dependencies.rb
|
76
|
-
- test/unit/inventory/dependencies/development.rb
|
77
|
-
- test/unit/inventory/dependencies/optional.rb
|
78
|
-
- test/unit/inventory/dependencies/runtime.rb
|
295
|
+
- lib/inventory-1.0/version.rb
|
296
|
+
- test/unit/inventory-1.0/dependency.rb
|
297
|
+
- test/unit/inventory-1.0/dependencies.rb
|
298
|
+
- test/unit/inventory-1.0/dependencies/development.rb
|
299
|
+
- test/unit/inventory-1.0/dependencies/optional.rb
|
300
|
+
- test/unit/inventory-1.0/dependencies/runtime.rb
|
301
|
+
- test/unit/inventory-1.0/extension.rb
|
79
302
|
- test/unit/inventory-1.0.rb
|
80
|
-
- test/unit/inventory/version.rb
|
303
|
+
- test/unit/inventory-1.0/version.rb
|
81
304
|
- README
|
82
305
|
- Rakefile
|
83
306
|
homepage: https://github.com/now/inventory
|
84
307
|
licenses: []
|
308
|
+
metadata: {}
|
85
309
|
post_install_message:
|
86
310
|
rdoc_options: []
|
87
311
|
require_paths:
|
88
312
|
- lib
|
89
313
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
314
|
requirements:
|
92
|
-
- -
|
315
|
+
- - '>='
|
93
316
|
- !ruby/object:Gem::Version
|
94
317
|
version: '0'
|
95
318
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
319
|
requirements:
|
98
|
-
- -
|
320
|
+
- - '>='
|
99
321
|
- !ruby/object:Gem::Version
|
100
322
|
version: '0'
|
101
323
|
requirements: []
|
102
324
|
rubyforge_project:
|
103
|
-
rubygems_version:
|
325
|
+
rubygems_version: 2.0.0
|
104
326
|
signing_key:
|
105
|
-
specification_version:
|
106
|
-
summary: Inventory
|
327
|
+
specification_version: 4
|
328
|
+
summary: Inventory keeps track of the contents of your Ruby¹ projects.
|
107
329
|
test_files: []
|