inventory 0.1.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,6 @@
1
+ Inventory
2
+
3
+ Inventory allows you to create inventories of your Ruby projects. These
4
+ inventories can then be used to load the project, create gem specifications
5
+ and gems, run unit tests, and verify that the project’s content is what you
6
+ think it is.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'lookout/rake/tasks'
5
+ require 'inventory/rake/tasks'
6
+ require 'inventory/version'
7
+
8
+ Inventory::Rake::Tasks.define Inventory::Version, :gem => proc{ |_, s|
9
+ s.author = 'Nikolai Weibull'
10
+ s.email = 'now@bitwi.se'
11
+ s.homepage = 'https://github.com/now/inventory'
12
+ }
13
+ Lookout::Rake::Tasks::Test.new
data/lib/inventory.rb ADDED
@@ -0,0 +1,107 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Inventory
4
+ def initialize(major, minor, patch,
5
+ path = (m = /\A(.*):\d+(?::in .*)?\z/.match(caller.first) and m[1]),
6
+ &block)
7
+ @major, @minor, @patch = major, minor, patch
8
+ raise ArgumentError, 'default value of path argument could not be calculated' unless path
9
+ @path = path
10
+ @srcdir, _, @package_require = File.dirname(File.expand_path(path)).rpartition('/lib/')
11
+ raise ArgumentError,
12
+ 'path is not of the form PATH/lib/PACKAGE/version.rb: %s' % path if
13
+ @path.empty?
14
+ instance_exec(&block) if block
15
+ end
16
+
17
+ def package
18
+ package_require.gsub('/', '-')
19
+ end
20
+
21
+ def version_require
22
+ File.join(package_require, 'version')
23
+ end
24
+
25
+ def lib_directories
26
+ %w'lib'
27
+ end
28
+
29
+ def load
30
+ requires.each do |requirement|
31
+ require requirement
32
+ end
33
+ loads.each do |load|
34
+ Kernel.load File.expand_path('lib/%s' % load, srcdir)
35
+ end
36
+ self
37
+ end
38
+
39
+ def requires
40
+ []
41
+ end
42
+
43
+ def loads
44
+ libs
45
+ end
46
+
47
+ def libs
48
+ []
49
+ end
50
+
51
+ def additional_libs
52
+ [package_require, version_require].map{ |e| '%s.rb' % e }
53
+ end
54
+
55
+ def all_libs
56
+ libs + additional_libs
57
+ end
58
+
59
+ def lib_files
60
+ all_libs.map{ |e| 'lib/%s' % e }
61
+ end
62
+
63
+ def unit_tests
64
+ all_libs
65
+ end
66
+
67
+ def additional_unit_tests
68
+ []
69
+ end
70
+
71
+ def all_unit_tests
72
+ unit_tests + additional_unit_tests
73
+ end
74
+
75
+ def unit_test_files
76
+ all_unit_tests.map{ |e| 'test/unit/%s' % e }
77
+ end
78
+
79
+ def test_files
80
+ unit_test_files
81
+ end
82
+
83
+ def additional_files
84
+ %w'
85
+ README
86
+ Rakefile
87
+ '
88
+ end
89
+
90
+ def files
91
+ lib_files + test_files + additional_files
92
+ end
93
+
94
+ def to_a
95
+ files
96
+ end
97
+
98
+ def to_s
99
+ '%d.%d.%d' % [major, minor, patch]
100
+ end
101
+
102
+ def inspect
103
+ '#<%s: %s %s>' % [self.class, package, self]
104
+ end
105
+
106
+ attr_reader :major, :minor, :patch, :path, :srcdir, :package_require
107
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rake'
4
+
5
+ class Inventory; module Rake end end
6
+
7
+ module Inventory::Rake::Tasks
8
+ %w'check clean gem inventory'.each do |file|
9
+ load File.expand_path('../tasks/%s.rb' % file, __FILE__)
10
+ end
11
+
12
+ @mostlycleanfiles, @cleanfiles, @distcleanfiles = [], [], []
13
+
14
+ class << self
15
+ attr_accessor :inventory
16
+
17
+ attr_reader :mostlycleanfiles, :cleanfiles, :distcleanfiles
18
+
19
+ def define(inventory, options = {})
20
+ self.inventory = inventory
21
+ Clean.define
22
+ Inventory.new(:inventory => inventory)
23
+ Gem.new(:inventory => inventory, &(options.fetch(:gem, proc{ })))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ desc 'Check that the package meets its expecatations'
4
+ task :check
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Inventory::Rake::Tasks::Clean
4
+ include Rake::DSL
5
+
6
+ class << self
7
+ include Rake::DSL
8
+
9
+ def define
10
+ desc 'Delete targets built by rake that are often rebuilt'
11
+ new :mostlyclean, Inventory::Rake::Tasks.mostlycleanfiles
12
+
13
+ desc 'Delete targets built by rake'
14
+ new :clean, Inventory::Rake::Tasks.cleanfiles
15
+ task :clean => :mostlyclean
16
+
17
+ desc 'Delete targets built by extconf.rb'
18
+ new :distclean, Inventory::Rake::Tasks.distcleanfiles
19
+ task :distclean => :clean
20
+ end
21
+ end
22
+
23
+ def initialize(name, files = [])
24
+ @name, @files = name, files
25
+ define
26
+ end
27
+
28
+ def define
29
+ task name do
30
+ rm files, :force => true
31
+ end
32
+ end
33
+
34
+ attr_accessor :name, :files
35
+ end
@@ -0,0 +1,154 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Inventory::Rake::Tasks::Gem
4
+ include Rake::DSL
5
+
6
+ def initialize(options = {})
7
+ self.inventory = options.fetch(:inventory, Inventory::Rake::Tasks.inventory)
8
+ self.specification = options.fetch(:specification,
9
+ Gem::Specification.new{ |s|
10
+ next unless @inventory
11
+
12
+ s.name = @inventory.package
13
+ s.version = @inventory.to_s # TODO: We could probably skip #to_s
14
+
15
+ s.description = IO.read('README')
16
+ s.summary = s.description[/^.*?\./].lstrip
17
+
18
+ s.files = @inventory.files # TODO: We can skip #files and rely on #to_a
19
+
20
+ s.require_paths = @inventory.lib_directories
21
+ })
22
+ yield self, @specification if block_given?
23
+ define
24
+ end
25
+
26
+ def define
27
+ desc 'Create specifications' unless Rake::Task.task_defined? :spec
28
+ task :spec => :'gem:spec'
29
+
30
+ gemspec = '%s.gemspec' % @specification.name
31
+ Inventory::Rake::Tasks.cleanfiles << gemspec
32
+
33
+ desc 'Create gem specification' unless Rake::Task.task_defined? :'gem:spec'
34
+ task :'gem:spec' => gemspec
35
+
36
+ file gemspec => %w'Rakefile README' + [@inventory.path] do |t|
37
+ tmp = '%s.tmp' % t.name
38
+ rm([t.name, tmp], :force => true)
39
+ puts 'gem specification --ruby %s > %s' %
40
+ [@specification.name, tmp] if verbose
41
+ File.open(tmp, 'wb') do |f|
42
+ f.write @specification.to_ruby
43
+ end
44
+ chmod File.stat(tmp).mode & ~0222, tmp
45
+ mv tmp, t.name
46
+ end
47
+
48
+ desc 'Create files for distribution' unless Rake::Task.task_defined? :dist
49
+ task :dist => :'gem:dist'
50
+
51
+ desc 'Create %s for distribution' % @specification.file_name
52
+ task :'gem:dist' => [:'inventory:check', @specification.file_name]
53
+ file @specification.file_name => @specification.files do
54
+ require 'rubygems' unless defined? Gem
55
+ puts 'gem build %s' % gemspec if verbose
56
+ Gem::Builder.new(@specification).build
57
+ end
58
+
59
+ desc 'Check files before distribution' unless
60
+ Rake::Task.task_defined? :'dist:check'
61
+ task :'dist:check' => [:dist, :'gem:dist:check']
62
+
63
+ desc 'Check %s before distribution' % @specification.file_name
64
+ task :'gem:dist:check' => :'gem:dist' do
65
+ require 'rubygems' unless defined? Gem
66
+ require 'rubygems/installer' unless defined? Gem::Installer
67
+ checkdir = @specification.full_name
68
+ puts 'gem unpack %s --target %s' %
69
+ [@specification.file_name, checkdir] if verbose
70
+ Gem::Installer.new(@specification.file_name, :unpack => true).
71
+ unpack File.expand_path(checkdir)
72
+ chdir checkdir do
73
+ sh '%s %sinventory:check check' %
74
+ [Rake.application.name, Rake.application.options.silent ? '-s ' : '']
75
+ end
76
+ rm_r checkdir
77
+ end
78
+
79
+ desc 'Install distribution files on the local system' unless
80
+ Rake::Task.task_defined? :install
81
+ task :install => :'gem:install'
82
+
83
+ desc 'Install %s and its dependencies in ruby gem directory' %
84
+ @specification.file_name
85
+ task :'gem:install' => :'gem:dist' do |t|
86
+ require 'rubygems' unless defined? Gem
87
+ require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
88
+ puts 'gem install %s' % @specification.file_name if verbose
89
+ Gem::DependencyInstaller.new.install @specification.file_name
90
+ end
91
+
92
+ desc 'Install distribution files for the current user' unless
93
+ Rake::Task.task_defined? :'install:user'
94
+ task :'install:user' => :'gem:install:user'
95
+
96
+ desc 'Install %s and its dependencies in user gem directory' %
97
+ @specification.file_name
98
+ task :'gem:install:user' => :'gem:dist' do
99
+ require 'rubygems' unless defined? Gem
100
+ require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
101
+ puts 'gem install --user-install --bindir %s %s' %
102
+ [Gem.bindir(Gem.user_dir), @specification.file_name] if verbose
103
+ Gem::DependencyInstaller.
104
+ new(:user_install => true,
105
+ :bindir => Gem.bindir(Gem.user_dir)).
106
+ install @specification.file_name
107
+ end
108
+
109
+ desc 'Delete all files installed on the local system' unless
110
+ Rake::Task.task_defined? :uninstall
111
+ task :uninstall => :'gem:uninstall'
112
+
113
+ desc 'Uninstall %s from ruby gem directory' % @specification.file_name
114
+ task :'gem:uninstall' do
115
+ require 'rubygems' unless defined? Gem
116
+ # TODO: I have absolutely no idea why this is needed, but it is.
117
+ require 'rubygems/user_interaction' unless defined? Gem::UserInteraction
118
+ require 'rubygems/uninstaller' unless defined? Gem::Uninstaller
119
+ puts 'gem uninstall --executables %s' % @specification.name if verbose
120
+ Gem::Uninstaller.new(@specification.name,
121
+ :executables => true,
122
+ :version => @specification.version).uninstall
123
+ end
124
+
125
+ desc 'Delete all files installed for current user' unless
126
+ Rake::Task.task_defined? :'uninstall:user'
127
+ task :'uninstall:user' => :'gem:uninstall:user'
128
+
129
+ desc 'Uninstall %s from user gem directory' % @specification.file_name
130
+ task :'gem:uninstall:user' do
131
+ require 'rubygems' unless defined? Gem
132
+ # TODO: I have absolutely no idea why this is needed, but it is.
133
+ require 'rubygems/user_interaction' unless defined? Gem::UserInteraction
134
+ require 'rubygems/uninstaller' unless defined? Gem::Uninstaller
135
+ puts 'gem uninstall --executables --install-dir %s %s' %
136
+ [Gem.user_dir, @specification.name] if verbose
137
+ Gem::Uninstaller.new(@specification.name,
138
+ :executables => true,
139
+ :install_dir => Gem.user_dir,
140
+ :version => @specification.version).uninstall
141
+ end
142
+
143
+ desc 'Push distribution files to distribution hubs' unless
144
+ Rake::Task.task_defined? :push
145
+ task :push => :'gem:push'
146
+
147
+ desc 'Push %s to rubygems.org' % @specification.file_name
148
+ task :'gem:push' => :'gem:dist:check' do
149
+ sh 'gem push -%s-verbose %s' % [verbose ? '' : '-no', @specification.file_name]
150
+ end
151
+ end
152
+
153
+ attr_writer :inventory, :specification
154
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class Inventory::Rake::Tasks::Inventory
4
+ include Rake::DSL
5
+
6
+ def initialize(options = {})
7
+ self.inventory = options.fetch(:inventory, Inventory::Rake::Tasks.inventory)
8
+ yield self if block_given?
9
+ define
10
+ end
11
+
12
+ def define
13
+ desc 'Check that the inventory is correct'
14
+ task :'inventory:check' do
15
+ # TODO: Use directories from Inventory instead of hard-coding lib and
16
+ # test/unit. We want to check ext too?
17
+ diff = ((Dir['{lib,test/unit}/**/*.rb'] -
18
+ @inventory.lib_files -
19
+ @inventory.unit_test_files).map{ |e| 'file not listed in inventory: %s' % e } +
20
+ @inventory.files.reject{ |e| File.exist? e }.map{ |e| 'file listed in inventory does not exist: %s' % e })
21
+ fail diff.join("\n") unless diff.empty?
22
+ # TODO: puts 'inventory checks out' if verbose
23
+ end
24
+ end
25
+
26
+ attr_writer :inventory
27
+ end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'inventory'
4
+
5
+ class Inventory
6
+ Version = Inventory.new(0, 2, 2){
7
+ def additional_libs
8
+ super + %w'
9
+ inventory/rake/tasks.rb
10
+ inventory/rake/tasks/check.rb
11
+ inventory/rake/tasks/clean.rb
12
+ inventory/rake/tasks/gem.rb
13
+ inventory/rake/tasks/inventory.rb
14
+ '
15
+ end
16
+ }
17
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Expectations do
4
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inventory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,14 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-04 00:00:00.000000000 Z
12
+ date: 2012-03-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Inventory allows you to create inventories of your Ruby projects.
14
+ description: ! " Inventory\n\n Inventory allows
15
+ you to create inventories of your Ruby projects. These\n inventories can then
16
+ be used to load the project, create gem specifications\n and gems, run unit tests,
17
+ and verify that the project’s content is what you\n think it is.\n"
15
18
  email: now@bitwi.se
16
19
  executables: []
17
20
  extensions: []
18
21
  extra_rdoc_files: []
19
- files: []
22
+ files:
23
+ - lib/inventory.rb
24
+ - lib/inventory/version.rb
25
+ - lib/inventory/rake/tasks.rb
26
+ - lib/inventory/rake/tasks/check.rb
27
+ - lib/inventory/rake/tasks/clean.rb
28
+ - lib/inventory/rake/tasks/gem.rb
29
+ - lib/inventory/rake/tasks/inventory.rb
30
+ - test/unit/inventory.rb
31
+ - test/unit/inventory/version.rb
32
+ - test/unit/inventory/rake/tasks.rb
33
+ - test/unit/inventory/rake/tasks/check.rb
34
+ - test/unit/inventory/rake/tasks/clean.rb
35
+ - test/unit/inventory/rake/tasks/gem.rb
36
+ - test/unit/inventory/rake/tasks/inventory.rb
37
+ - README
38
+ - Rakefile
20
39
  homepage: https://github.com/now/inventory
21
40
  licenses: []
22
41
  post_install_message:
@@ -42,4 +61,3 @@ signing_key:
42
61
  specification_version: 3
43
62
  summary: Inventory allows you to create inventories of your Ruby projects.
44
63
  test_files: []
45
- has_rdoc: