ore 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +4 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +31 -0
- data/GemspecYML.md +252 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/Rakefile +9 -0
- data/bin/mine +12 -0
- data/bin/ore +12 -0
- data/data/ore/templates/base/.document +3 -0
- data/data/ore/templates/base/.gitignore.erb +3 -0
- data/data/ore/templates/base/:name:.gemspec.erb +10 -0
- data/data/ore/templates/base/ChangeLog.md.erb +4 -0
- data/data/ore/templates/base/ChangeLog.rdoc.erb +4 -0
- data/data/ore/templates/base/ChangeLog.tt.erb +4 -0
- data/data/ore/templates/base/LICENSE.txt.erb +20 -0
- data/data/ore/templates/base/README.md.erb +42 -0
- data/data/ore/templates/base/README.rdoc.erb +38 -0
- data/data/ore/templates/base/README.tt.erb +44 -0
- data/data/ore/templates/base/Rakefile.erb +23 -0
- data/data/ore/templates/base/gemspec.yml.erb +23 -0
- data/data/ore/templates/base/lib/:namespace_dir:.rb.erb +1 -0
- data/data/ore/templates/base/lib/:namespace_dir:/version.rb.erb +8 -0
- data/data/ore/templates/bundler/Gemfile.erb +20 -0
- data/data/ore/templates/bundler/_dependencies.erb +1 -0
- data/data/ore/templates/jeweler_tasks/_dependencies.erb +3 -0
- data/data/ore/templates/jeweler_tasks/_tasks.erb +17 -0
- data/data/ore/templates/ore_tasks/_dependencies.erb +1 -0
- data/data/ore/templates/ore_tasks/_tasks.erb +12 -0
- data/data/ore/templates/rdoc/_tasks.erb +6 -0
- data/data/ore/templates/rspec/.rspec +1 -0
- data/data/ore/templates/rspec/_dependencies.erb +3 -0
- data/data/ore/templates/rspec/_tasks.erb +14 -0
- data/data/ore/templates/rspec/spec/:namespace_dir:_spec.rb.erb +8 -0
- data/data/ore/templates/rspec/spec/spec_helper.rb.erb +7 -0
- data/data/ore/templates/test_unit/test/helper.rb.erb +24 -0
- data/data/ore/templates/test_unit/test/test_:name:.rb.erb +5 -0
- data/data/ore/templates/yard/.yardopts.erb +1 -0
- data/data/ore/templates/yard/_dependencies.erb +1 -0
- data/data/ore/templates/yard/_gem.erb +1 -0
- data/data/ore/templates/yard/_tasks.erb +13 -0
- data/gemspec.yml +21 -0
- data/lib/ore.rb +3 -0
- data/lib/ore/checks.rb +85 -0
- data/lib/ore/cli.rb +120 -0
- data/lib/ore/config.rb +52 -0
- data/lib/ore/defaults.rb +137 -0
- data/lib/ore/dependency.rb +62 -0
- data/lib/ore/document_file.rb +118 -0
- data/lib/ore/exceptions.rb +3 -0
- data/lib/ore/exceptions/exception.rb +4 -0
- data/lib/ore/exceptions/invalid_metadata.rb +6 -0
- data/lib/ore/exceptions/project_not_found.rb +6 -0
- data/lib/ore/generator.rb +247 -0
- data/lib/ore/naming.rb +95 -0
- data/lib/ore/paths.rb +143 -0
- data/lib/ore/project.rb +568 -0
- data/lib/ore/settings.rb +236 -0
- data/lib/ore/specification.rb +29 -0
- data/lib/ore/template.rb +3 -0
- data/lib/ore/template/directory.rb +179 -0
- data/lib/ore/template/helpers.rb +144 -0
- data/lib/ore/template/interpolations.rb +31 -0
- data/lib/ore/versions.rb +3 -0
- data/lib/ore/versions/exceptions.rb +1 -0
- data/lib/ore/versions/exceptions/invalid_version.rb +8 -0
- data/lib/ore/versions/version.rb +75 -0
- data/lib/ore/versions/version_constant.rb +126 -0
- data/lib/ore/versions/version_file.rb +66 -0
- data/lib/rubygems_plugin.rb +40 -0
- data/ore.gemspec +6 -0
- data/spec/dependency_spec.rb +36 -0
- data/spec/document_file_spec.rb +29 -0
- data/spec/helpers/files.rb +7 -0
- data/spec/helpers/files/.document +5 -0
- data/spec/helpers/files/VERSION +1 -0
- data/spec/helpers/files/VERSION.yml +5 -0
- data/spec/helpers/projects.rb +13 -0
- data/spec/helpers/projects/dm-plugin/Gemfile +3 -0
- data/spec/helpers/projects/dm-plugin/VERSION +1 -0
- data/spec/helpers/projects/dm-plugin/dm-plugin.gemspec +10 -0
- data/spec/helpers/projects/dm-plugin/gemspec.yml +7 -0
- data/spec/helpers/projects/dm-plugin/lib/dm-plugin.rb +1 -0
- data/spec/helpers/projects/explicit/gemspec.yml +10 -0
- data/spec/helpers/projects/explicit/lib/explicit/version.rb +15 -0
- data/spec/helpers/projects/ffi-binding/gemspec.yml +7 -0
- data/spec/helpers/projects/ffi-binding/lib/ffi/binding/version.rb +5 -0
- data/spec/helpers/projects/jewelery/VERSION +1 -0
- data/spec/helpers/projects/jewelery/bin/jewelery +3 -0
- data/spec/helpers/projects/jewelery/gemspec.yml +4 -0
- data/spec/helpers/projects/jewelery/jewelery.gemspec +10 -0
- data/spec/helpers/projects/jewelery/lib/jewelery.rb +4 -0
- data/spec/helpers/projects/jewelery/lib/jewelery/rubies.rb +4 -0
- data/spec/helpers/projects/minimal/gemspec.yml +4 -0
- data/spec/helpers/projects/minimal/lib/minimal.rb +2 -0
- data/spec/naming_spec.rb +48 -0
- data/spec/projects/dm_plugin_project_spec.rb +29 -0
- data/spec/projects/explicit_project_spec.rb +33 -0
- data/spec/projects/ffi_binding_project_spec.rb +21 -0
- data/spec/projects/jeweler_project_spec.rb +17 -0
- data/spec/projects/minimal_project_spec.rb +17 -0
- data/spec/projects/project_examples.rb +34 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/versions/version_file_spec.rb +28 -0
- data/spec/versions/version_spec.rb +53 -0
- metadata +226 -0
data/lib/ore/paths.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'ore/naming'
|
2
|
+
|
3
|
+
module Ore
|
4
|
+
module Paths
|
5
|
+
include Naming
|
6
|
+
|
7
|
+
#
|
8
|
+
# Builds a path relative to the project.
|
9
|
+
#
|
10
|
+
# @param [Array] names
|
11
|
+
# The directory names of the path.
|
12
|
+
#
|
13
|
+
# @return [Pathname]
|
14
|
+
# The new path.
|
15
|
+
#
|
16
|
+
def path(*names)
|
17
|
+
@root.join(*names)
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# The `bin/` directory of the project.
|
22
|
+
#
|
23
|
+
# @return [Pathname]
|
24
|
+
# The path to the `bin/` directory.
|
25
|
+
#
|
26
|
+
def bin_dir
|
27
|
+
@root.join(@@lib_dir)
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# The `lib/` directory of the project.
|
32
|
+
#
|
33
|
+
# @return [Pathname]
|
34
|
+
# The path to the `lib/` directory.
|
35
|
+
#
|
36
|
+
def lib_dir
|
37
|
+
@root.join(@@lib_dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# The `pkg/` directory of the project.
|
42
|
+
#
|
43
|
+
# @return [Pathname]
|
44
|
+
# The path to the `pkg/` directory.
|
45
|
+
#
|
46
|
+
def pkg_dir
|
47
|
+
@root.join(@@pkg_dir)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Builds a path relative to the `lib/` directory.
|
52
|
+
#
|
53
|
+
# @param [Array] names
|
54
|
+
# The directory names of the path.
|
55
|
+
#
|
56
|
+
# @return [Pathname]
|
57
|
+
# The new path.
|
58
|
+
#
|
59
|
+
def lib_path(*names)
|
60
|
+
path(@@lib_dir,*names)
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Builds a relative path into the `pkg/` directory for the `.gem` file.
|
65
|
+
#
|
66
|
+
# @return [String]
|
67
|
+
# The path of a `.gem` file for the project.
|
68
|
+
#
|
69
|
+
def pkg_file
|
70
|
+
File.join(@@pkg_dir,"#{@name}-#{@version}.gem")
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Determines if a directory exists within the project.
|
75
|
+
#
|
76
|
+
# @param [String] path
|
77
|
+
# The path of the directory, relative to the project.
|
78
|
+
#
|
79
|
+
# @return [Boolean]
|
80
|
+
# Specifies whether the directory exists in the project.
|
81
|
+
#
|
82
|
+
def directory?(path)
|
83
|
+
@root.join(path).directory?
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Determines if a file exists within the project.
|
88
|
+
#
|
89
|
+
# @param [String] path
|
90
|
+
# The path of the file, relative to the project.
|
91
|
+
#
|
92
|
+
# @return [Boolean]
|
93
|
+
# Specifies whether the file exists in the project.
|
94
|
+
#
|
95
|
+
def file?(path)
|
96
|
+
@project_files.include?(path)
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Determines if a directory exists within the `lib/` directory of the
|
101
|
+
# project.
|
102
|
+
#
|
103
|
+
# @return [Boolean]
|
104
|
+
# Specifies that the directory exists within the `lib/` directory.
|
105
|
+
#
|
106
|
+
def lib_directory?(path)
|
107
|
+
directory?(File.join(@@lib_dir,path))
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# Determines if a file exists within the `lib/` directory of the
|
112
|
+
# project.
|
113
|
+
#
|
114
|
+
# @return [Boolean]
|
115
|
+
# Specifies that the file exists within the `lib/` directory.
|
116
|
+
#
|
117
|
+
def lib_file?(path)
|
118
|
+
file?(File.join(@@lib_dir,path))
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
# Finds paths within the project that match a glob pattern.
|
123
|
+
#
|
124
|
+
# @param [String] pattern
|
125
|
+
# The glob pattern.
|
126
|
+
#
|
127
|
+
# @yield [path]
|
128
|
+
# The given block will be passed matching paths.
|
129
|
+
#
|
130
|
+
# @yieldparam [String] path
|
131
|
+
# A path relative to the root directory of the project.
|
132
|
+
#
|
133
|
+
def glob(pattern)
|
134
|
+
within do
|
135
|
+
Dir.glob(pattern) do |path|
|
136
|
+
if (@project_files.include?(path) || File.directory?(path))
|
137
|
+
yield path
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/lib/ore/project.rb
ADDED
@@ -0,0 +1,568 @@
|
|
1
|
+
require 'ore/exceptions/project_not_found'
|
2
|
+
require 'ore/exceptions/invalid_metadata'
|
3
|
+
require 'ore/naming'
|
4
|
+
require 'ore/paths'
|
5
|
+
require 'ore/checks'
|
6
|
+
require 'ore/defaults'
|
7
|
+
require 'ore/settings'
|
8
|
+
require 'ore/document_file'
|
9
|
+
|
10
|
+
require 'pathname'
|
11
|
+
require 'yaml'
|
12
|
+
require 'find'
|
13
|
+
require 'fileutils'
|
14
|
+
|
15
|
+
module Ore
|
16
|
+
class Project
|
17
|
+
|
18
|
+
include Naming
|
19
|
+
include Paths
|
20
|
+
include Checks
|
21
|
+
include Defaults
|
22
|
+
include Settings
|
23
|
+
|
24
|
+
# The project metadata file
|
25
|
+
@@metadata_file = 'gemspec.yml'
|
26
|
+
|
27
|
+
# The SCM which the project is currently under
|
28
|
+
attr_reader :scm
|
29
|
+
|
30
|
+
# The files of the project
|
31
|
+
attr_reader :project_files
|
32
|
+
|
33
|
+
# The fully-qualified namespace of the project
|
34
|
+
attr_reader :namespace
|
35
|
+
|
36
|
+
# The infered namespace modules of the project
|
37
|
+
attr_reader :namespace_modules
|
38
|
+
|
39
|
+
# The directory contain the project code.
|
40
|
+
attr_reader :namespace_dir
|
41
|
+
|
42
|
+
# The name of the project
|
43
|
+
attr_reader :name
|
44
|
+
|
45
|
+
# The version of the project
|
46
|
+
attr_reader :version
|
47
|
+
|
48
|
+
# The project summary
|
49
|
+
attr_reader :summary
|
50
|
+
|
51
|
+
# The project description
|
52
|
+
attr_reader :description
|
53
|
+
|
54
|
+
# The licenses of the project
|
55
|
+
attr_reader :licenses
|
56
|
+
|
57
|
+
# The authors of the project
|
58
|
+
attr_reader :authors
|
59
|
+
|
60
|
+
# The homepage for the project
|
61
|
+
attr_reader :homepage
|
62
|
+
|
63
|
+
# The email contact for the project
|
64
|
+
attr_reader :email
|
65
|
+
|
66
|
+
# The build date for any project gems
|
67
|
+
attr_reader :date
|
68
|
+
|
69
|
+
# The parsed `.document` file
|
70
|
+
attr_reader :document
|
71
|
+
|
72
|
+
# The directories to search within the project when requiring files
|
73
|
+
attr_reader :require_paths
|
74
|
+
|
75
|
+
# The names of the executable scripts
|
76
|
+
attr_reader :executables
|
77
|
+
|
78
|
+
# The default executable
|
79
|
+
attr_reader :default_executable
|
80
|
+
|
81
|
+
# The documentation of the project
|
82
|
+
attr_reader :documentation
|
83
|
+
|
84
|
+
# Any extra files to include in the project documentation
|
85
|
+
attr_reader :extra_doc_files
|
86
|
+
|
87
|
+
# The files of the project
|
88
|
+
attr_reader :files
|
89
|
+
|
90
|
+
# The test files for the project
|
91
|
+
attr_reader :test_files
|
92
|
+
|
93
|
+
# The version of Ruby required by the project
|
94
|
+
attr_reader :required_ruby_version
|
95
|
+
|
96
|
+
# The version of RubyGems required by the project
|
97
|
+
attr_reader :required_rubygems_version
|
98
|
+
|
99
|
+
# The dependencies of the project
|
100
|
+
attr_reader :dependencies
|
101
|
+
|
102
|
+
# The runtime-dependencies of the project
|
103
|
+
attr_reader :runtime_dependencies
|
104
|
+
|
105
|
+
# The development-dependencies of the project
|
106
|
+
attr_reader :development_dependencies
|
107
|
+
|
108
|
+
#
|
109
|
+
# Creates a new {Project}.
|
110
|
+
#
|
111
|
+
# @param [String] root
|
112
|
+
# The root directory of the project.
|
113
|
+
#
|
114
|
+
def initialize(root)
|
115
|
+
@root = Pathname.new(root).expand_path
|
116
|
+
|
117
|
+
unless @root.directory?
|
118
|
+
raise(ProjectNotFound,"#{@root} is not a directory")
|
119
|
+
end
|
120
|
+
|
121
|
+
infer_scm!
|
122
|
+
infer_project_files!
|
123
|
+
|
124
|
+
metadata_file = @root.join(@@metadata_file)
|
125
|
+
|
126
|
+
unless metadata_file.file?
|
127
|
+
raise(ProjectNotFound,"#{@root} does not contain #{@@metadata_file}")
|
128
|
+
end
|
129
|
+
|
130
|
+
metadata = YAML.load_file(metadata_file)
|
131
|
+
|
132
|
+
unless metadata.kind_of?(Hash)
|
133
|
+
raise(InvalidMetadata,"#{metadata_file} did not contain valid metadata")
|
134
|
+
end
|
135
|
+
|
136
|
+
if metadata['name']
|
137
|
+
@name = metadata['name'].to_s
|
138
|
+
else
|
139
|
+
default_name!
|
140
|
+
end
|
141
|
+
|
142
|
+
# infer the namespace from the project name
|
143
|
+
infer_namespace!
|
144
|
+
|
145
|
+
if metadata['version']
|
146
|
+
set_version! metadata['version']
|
147
|
+
else
|
148
|
+
default_version!
|
149
|
+
end
|
150
|
+
|
151
|
+
@summary = (metadata['summary'] || metadata['description'])
|
152
|
+
@description = (metadata['description'] || metadata['summary'])
|
153
|
+
|
154
|
+
@licenses = []
|
155
|
+
|
156
|
+
if metadata['license']
|
157
|
+
set_license!(metadata['license'])
|
158
|
+
end
|
159
|
+
|
160
|
+
@authors = []
|
161
|
+
|
162
|
+
if metadata['authors']
|
163
|
+
set_authors! metadata['authors']
|
164
|
+
end
|
165
|
+
|
166
|
+
@homepage = metadata['homepage']
|
167
|
+
@email = metadata['email']
|
168
|
+
|
169
|
+
if metadata['date']
|
170
|
+
set_date! metadata['date']
|
171
|
+
else
|
172
|
+
default_date!
|
173
|
+
end
|
174
|
+
|
175
|
+
@document = DocumentFile.find(self)
|
176
|
+
|
177
|
+
@require_paths = []
|
178
|
+
|
179
|
+
if metadata['require_paths']
|
180
|
+
set_require_paths! metadata['require_paths']
|
181
|
+
else
|
182
|
+
default_require_paths!
|
183
|
+
end
|
184
|
+
|
185
|
+
@executables = []
|
186
|
+
|
187
|
+
if metadata['executables']
|
188
|
+
set_executables! metadata['executables']
|
189
|
+
else
|
190
|
+
default_executables!
|
191
|
+
end
|
192
|
+
|
193
|
+
@default_executable = nil
|
194
|
+
|
195
|
+
if metadata['default_executable']
|
196
|
+
set_default_executable! metadata['default_executable']
|
197
|
+
else
|
198
|
+
default_executable!
|
199
|
+
end
|
200
|
+
|
201
|
+
if metadata['has_yard']
|
202
|
+
@documentation = :yard
|
203
|
+
elsif metadata.has_key?('has_rdoc')
|
204
|
+
@documentation = if metadata['has_rdoc']
|
205
|
+
:rdoc
|
206
|
+
end
|
207
|
+
else
|
208
|
+
default_documentation!
|
209
|
+
end
|
210
|
+
|
211
|
+
@extra_doc_files = []
|
212
|
+
|
213
|
+
if metadata['extra_doc_files']
|
214
|
+
set_extra_doc_files! metadata['extra_doc_files']
|
215
|
+
else
|
216
|
+
default_extra_doc_files!
|
217
|
+
end
|
218
|
+
|
219
|
+
@files = []
|
220
|
+
|
221
|
+
if metadata['files']
|
222
|
+
set_files! metadata['files']
|
223
|
+
else
|
224
|
+
default_files!
|
225
|
+
end
|
226
|
+
|
227
|
+
@test_files = []
|
228
|
+
|
229
|
+
if metadata['test_files']
|
230
|
+
set_test_files! metadata['test_files']
|
231
|
+
else
|
232
|
+
default_test_files!
|
233
|
+
end
|
234
|
+
|
235
|
+
if metadata['required_ruby_version']
|
236
|
+
set_required_ruby_version! metadata['required_ruby_version']
|
237
|
+
end
|
238
|
+
|
239
|
+
if metadata['required_rubygems_version']
|
240
|
+
set_required_rubygems_version! metadata['required_rubygems_version']
|
241
|
+
else
|
242
|
+
default_required_rubygems_version!
|
243
|
+
end
|
244
|
+
|
245
|
+
@dependencies = []
|
246
|
+
|
247
|
+
if metadata['dependencies']
|
248
|
+
set_dependencies! metadata['dependencies']
|
249
|
+
end
|
250
|
+
|
251
|
+
@runtime_dependencies = []
|
252
|
+
|
253
|
+
if metadata['runtime_dependencies']
|
254
|
+
set_runtime_dependencies! metadata['runtime_dependencies']
|
255
|
+
end
|
256
|
+
|
257
|
+
@development_dependencies = []
|
258
|
+
|
259
|
+
if metadata['development_dependencies']
|
260
|
+
set_development_dependencies! metadata['development_dependencies']
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
# Finds the project metadata file and creates a new {Project} object.
|
266
|
+
#
|
267
|
+
# @param [String] dir (Dir.pwd)
|
268
|
+
# The directory to start searching upward from.
|
269
|
+
#
|
270
|
+
# @return [Project]
|
271
|
+
# The found project.
|
272
|
+
#
|
273
|
+
# @raise [ProjectNotFound]
|
274
|
+
# No project metadata file could be found.
|
275
|
+
#
|
276
|
+
def self.find(dir=Dir.pwd)
|
277
|
+
Pathname.new(dir).ascend do |root|
|
278
|
+
return self.new(root) if root.join(@@metadata_file).file?
|
279
|
+
end
|
280
|
+
|
281
|
+
raise(ProjectNotFound,"could not find #{@@metadata_file}")
|
282
|
+
end
|
283
|
+
|
284
|
+
#
|
285
|
+
# Executes code within the project.
|
286
|
+
#
|
287
|
+
# @param [String] sub_dir
|
288
|
+
# An optional sub-directory within the project to execute from.
|
289
|
+
#
|
290
|
+
# @yield []
|
291
|
+
# The given block will be called once the current working-directory
|
292
|
+
# has been switched. Once the block finishes executing, the current
|
293
|
+
# working-directory will be switched back.
|
294
|
+
#
|
295
|
+
# @see http://ruby-doc.org/core/classes/Dir.html#M002314
|
296
|
+
#
|
297
|
+
def within(sub_dir=nil,&block)
|
298
|
+
dir = if sub_dir
|
299
|
+
@root.join(sub_dir)
|
300
|
+
else
|
301
|
+
@root
|
302
|
+
end
|
303
|
+
|
304
|
+
Dir.chdir(dir,&block)
|
305
|
+
end
|
306
|
+
|
307
|
+
#
|
308
|
+
# The primary license of the project.
|
309
|
+
#
|
310
|
+
# @return [String, nil]
|
311
|
+
# The primary license for the project.
|
312
|
+
#
|
313
|
+
def license
|
314
|
+
@licenses.first
|
315
|
+
end
|
316
|
+
|
317
|
+
#
|
318
|
+
# Determines whether the project uses Bundler.
|
319
|
+
#
|
320
|
+
# @return [Boolean]
|
321
|
+
# Specifies whether the project uses Bundler.
|
322
|
+
#
|
323
|
+
def bundler?
|
324
|
+
file?('Gemfile')
|
325
|
+
end
|
326
|
+
|
327
|
+
#
|
328
|
+
# Determines whether the project has been bundled using Bundler.
|
329
|
+
#
|
330
|
+
# @return [Boolean]
|
331
|
+
# Specifies whether the project has been bundled.
|
332
|
+
#
|
333
|
+
def bundled?
|
334
|
+
file?('Gemfile.lock')
|
335
|
+
end
|
336
|
+
|
337
|
+
#
|
338
|
+
# Determines if the project contains RDoc documentation.
|
339
|
+
#
|
340
|
+
# @return [Boolean]
|
341
|
+
# Specifies whether the project has RDoc documentation.
|
342
|
+
#
|
343
|
+
def has_rdoc
|
344
|
+
@documentation == :rdoc
|
345
|
+
end
|
346
|
+
|
347
|
+
#
|
348
|
+
# Determines if the project contains YARD documentation.
|
349
|
+
#
|
350
|
+
# @return [Boolean]
|
351
|
+
# Specifies whether the project has YARD documentation.
|
352
|
+
#
|
353
|
+
def has_yard
|
354
|
+
@documentation == :yard
|
355
|
+
end
|
356
|
+
|
357
|
+
#
|
358
|
+
# Populates a Gem Specification using the metadata of the project.
|
359
|
+
#
|
360
|
+
# @yield [gemspec]
|
361
|
+
# The given block will be passed the populated Gem Specification
|
362
|
+
# object.
|
363
|
+
#
|
364
|
+
# @yieldparam [Gem::Specification] gemspec
|
365
|
+
# The newly created Gem Specification.
|
366
|
+
#
|
367
|
+
# @return [Gem::Specification]
|
368
|
+
# The Gem Specification.
|
369
|
+
#
|
370
|
+
# @see http://rubygems.rubyforge.org/rdoc/Gem/Specification.html
|
371
|
+
#
|
372
|
+
def to_gemspec
|
373
|
+
Gem::Specification.new do |gemspec|
|
374
|
+
gemspec.name = @name.to_s
|
375
|
+
gemspec.version = @version.to_s
|
376
|
+
gemspec.summary = @summary.to_s
|
377
|
+
gemspec.description = @description.to_s
|
378
|
+
gemspec.licenses = @licenses
|
379
|
+
gemspec.authors = @authors
|
380
|
+
gemspec.homepage = @homepage
|
381
|
+
gemspec.email = @email
|
382
|
+
gemspec.date = @date
|
383
|
+
|
384
|
+
@require_paths.each do |path|
|
385
|
+
unless gemspec.require_paths.include?(path)
|
386
|
+
gemspec.require_paths << path
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
gemspec.executables = @executables
|
391
|
+
gemspec.default_executable = @default_executable
|
392
|
+
|
393
|
+
gemspec.has_rdoc = if has_yard
|
394
|
+
'yard'
|
395
|
+
elsif has_rdoc
|
396
|
+
true
|
397
|
+
end
|
398
|
+
|
399
|
+
gemspec.extra_rdoc_files = @extra_doc_files
|
400
|
+
gemspec.files = @files
|
401
|
+
gemspec.test_files = @test_files
|
402
|
+
|
403
|
+
if gemspec.respond_to?(:required_ruby_version=)
|
404
|
+
gemspec.required_ruby_version = @required_ruby_version
|
405
|
+
end
|
406
|
+
|
407
|
+
if gemspec.respond_to?(:required_rubygems_version=)
|
408
|
+
gemspec.required_rubygems_version = @required_rubygems_version
|
409
|
+
end
|
410
|
+
|
411
|
+
@dependencies.each do |dep|
|
412
|
+
gemspec.add_dependency(dep.name,*dep.versions)
|
413
|
+
end
|
414
|
+
|
415
|
+
if gemspec.respond_to?(:add_runtime_dependency)
|
416
|
+
@runtime_dependencies.each do |dep|
|
417
|
+
gemspec.add_runtime_dependency(dep.name,*dep.versions)
|
418
|
+
end
|
419
|
+
else
|
420
|
+
@runtime_dependencies.each do |dep|
|
421
|
+
gemspec.add_dependency(dep.name,*dep.versions)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
if gemspec.respond_to?(:add_development_dependency)
|
426
|
+
@development_dependencies.each do |dep|
|
427
|
+
gemspec.add_development_dependency(dep.name,*dep.versions)
|
428
|
+
end
|
429
|
+
else
|
430
|
+
@development_dependencies.each do |dep|
|
431
|
+
gemspec.add_dependency(dep.name,*dep.versions)
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
yield gemspec if block_given?
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
#
|
440
|
+
# Builds a gem for the project.
|
441
|
+
#
|
442
|
+
# @return [Pathname]
|
443
|
+
# The path to the built gem file within the `pkg/` directory.
|
444
|
+
#
|
445
|
+
def build!
|
446
|
+
pkg_dir = @root.join(@@pkg_dir)
|
447
|
+
FileUtils.mkdir_p(pkg_dir)
|
448
|
+
|
449
|
+
gem_file = Gem::Builder.new(self.to_gemspec).build
|
450
|
+
pkg_path = @root.join(pkg_file)
|
451
|
+
|
452
|
+
FileUtils.mv(gem_file,pkg_path)
|
453
|
+
return pkg_path
|
454
|
+
end
|
455
|
+
|
456
|
+
protected
|
457
|
+
|
458
|
+
#
|
459
|
+
# Prints multiple warning messages.
|
460
|
+
#
|
461
|
+
# @param [Array] messages
|
462
|
+
# The messages to print.
|
463
|
+
#
|
464
|
+
def warn(*messages)
|
465
|
+
messages.each { |mesg| STDERR.puts("WARNING: #{mesg}") }
|
466
|
+
end
|
467
|
+
|
468
|
+
#
|
469
|
+
# Infers the Source Code Management used by the project.
|
470
|
+
#
|
471
|
+
def infer_scm!
|
472
|
+
if @root.join('.git').directory?
|
473
|
+
@scm = :git
|
474
|
+
else
|
475
|
+
@scm = nil
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
#
|
480
|
+
# Infers the project files.
|
481
|
+
#
|
482
|
+
def infer_project_files!
|
483
|
+
@project_files = Set[]
|
484
|
+
|
485
|
+
filter_path = lambda { |path|
|
486
|
+
check_readable(path) { |file| @project_files << file }
|
487
|
+
}
|
488
|
+
|
489
|
+
within do
|
490
|
+
case @scm
|
491
|
+
when :git
|
492
|
+
`git ls-files -z`.split("\0").each(&filter_path)
|
493
|
+
else
|
494
|
+
within { Dir.glob('{**/}*',&filter_path) }
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
#
|
500
|
+
# Infers the namespace of the project based on the project name.
|
501
|
+
#
|
502
|
+
def infer_namespace!
|
503
|
+
@namespace_modules = modules_of(@name)
|
504
|
+
@namespace = namespace_of(@name)
|
505
|
+
|
506
|
+
dir = namespace_path_of(@name)
|
507
|
+
|
508
|
+
@namespace_dir = if lib_directory?(dir)
|
509
|
+
dir
|
510
|
+
elsif lib_directory?(@name)
|
511
|
+
@name
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
#
|
516
|
+
# Adds a require-path to the project.
|
517
|
+
#
|
518
|
+
# @param [String] path
|
519
|
+
# A directory path relative to the project.
|
520
|
+
#
|
521
|
+
def add_require_path(path)
|
522
|
+
check_directory(path) { |dir| @require_paths << dir }
|
523
|
+
end
|
524
|
+
|
525
|
+
#
|
526
|
+
# Adds an executable to the project.
|
527
|
+
#
|
528
|
+
# @param [String] name
|
529
|
+
# The name of the executable.
|
530
|
+
#
|
531
|
+
def add_executable(name)
|
532
|
+
path = File.join(@@bin_dir,name)
|
533
|
+
|
534
|
+
check_executable(path) { |exe| @executables << exe }
|
535
|
+
end
|
536
|
+
|
537
|
+
#
|
538
|
+
# Adds an extra documentation file to the project.
|
539
|
+
#
|
540
|
+
# @param [String] path
|
541
|
+
# The path to the file, relative to the project.
|
542
|
+
#
|
543
|
+
def add_extra_doc_file(path)
|
544
|
+
check_file(path) { |file| @extra_doc_files << file }
|
545
|
+
end
|
546
|
+
|
547
|
+
#
|
548
|
+
# Adds a file to the project.
|
549
|
+
#
|
550
|
+
# @param [String] path
|
551
|
+
# The path to the file, relative to the project.
|
552
|
+
#
|
553
|
+
def add_file(path)
|
554
|
+
check_file(path) { |file| @files << file }
|
555
|
+
end
|
556
|
+
|
557
|
+
#
|
558
|
+
# Adds a testing-file to the project.
|
559
|
+
#
|
560
|
+
# @param [String] path
|
561
|
+
# The path to the testing-file, relative to the project.
|
562
|
+
#
|
563
|
+
def add_test_file(path)
|
564
|
+
check_file(path) { |file| @test_files << file }
|
565
|
+
end
|
566
|
+
|
567
|
+
end
|
568
|
+
end
|