Class: Ore::Project
- Inherits:
-
Object
- Object
- Ore::Project
- Includes:
- Checks, Inferences, Naming, Paths, Settings
- Defined in:
- lib/ore/project.rb
Overview
Combines the metadata from the gemspec.yml file and the inferred
information from the project directory.
Constant Summary collapse
- @@metadata_file =
The project metadata file
'gemspec.yml'
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
The authors of the project.
-
#date ⇒ Object
readonly
The build date for any project gems.
-
#default_executable ⇒ Object
readonly
The default executable.
-
#dependencies ⇒ Object
readonly
The dependencies of the project.
-
#description ⇒ Object
readonly
The project description.
-
#development_dependencies ⇒ Object
readonly
The development-dependencies of the project.
-
#document ⇒ Object
readonly
The parsed
.documentfile. -
#documentation ⇒ Object
readonly
The documentation of the project.
-
#email ⇒ Object
readonly
The email contact for the project.
-
#executables ⇒ Object
readonly
The names of the executable scripts.
-
#extra_doc_files ⇒ Object
readonly
Any extra files to include in the project documentation.
-
#files ⇒ Object
readonly
The files of the project.
-
#homepage ⇒ Object
readonly
The homepage for the project.
-
#licenses ⇒ Object
readonly
The licenses of the project.
-
#name ⇒ Object
readonly
The name of the project.
-
#namespace ⇒ Object
readonly
The fully-qualified namespace of the project.
-
#namespace_dir ⇒ Object
readonly
The directory contain the project code.
-
#namespace_modules ⇒ Object
readonly
The inferred namespace modules of the project.
-
#post_install_message ⇒ Object
readonly
The post-installation message.
-
#project_files ⇒ Object
readonly
The files of the project.
-
#require_paths ⇒ Object
readonly
The directories to search within the project when requiring files.
-
#required_ruby_version ⇒ Object
readonly
The version of Ruby required by the project.
-
#required_rubygems_version ⇒ Object
readonly
The version of RubyGems required by the project.
-
#requirements ⇒ Object
readonly
Any external requirements needed by the project.
-
#root ⇒ Object
readonly
The root directory of the project.
-
#runtime_dependencies ⇒ Object
readonly
The runtime-dependencies of the project.
-
#scm ⇒ Object
readonly
The SCM which the project is currently under.
-
#summary ⇒ Object
readonly
The project summary.
-
#test_files ⇒ Object
readonly
The test files for the project.
-
#version ⇒ Object
readonly
The version of the project.
Class Method Summary collapse
-
.find(dir = Dir.pwd) ⇒ Project
Finds the project metadata file and creates a new Project object.
Instance Method Summary collapse
-
#add_executable(name) ⇒ Object
protected
Adds an executable to the project.
-
#add_extra_doc_file(path) ⇒ Object
protected
Adds an extra documentation file to the project.
-
#add_file(path) ⇒ Object
protected
Adds a file to the project.
-
#add_require_path(path) ⇒ Object
protected
Adds a require-path to the project.
-
#add_test_file(path) ⇒ Object
protected
Adds a testing-file to the project.
-
#build! ⇒ Pathname
Builds a gem for the project.
-
#bundled? ⇒ Boolean
Determines whether the project has been bundled using Bundler.
-
#bundler? ⇒ Boolean
Determines whether the project uses Bundler.
-
#has_rdoc ⇒ Boolean
(also: #has_rdoc?)
Determines if the project contains RDoc documentation.
-
#has_yard ⇒ Boolean
(also: #has_yard?)
Determines if the project contains YARD documentation.
-
#initialize(root = Dir.pwd) ⇒ Project
constructor
Creates a new Project.
-
#license ⇒ String?
The primary license of the project.
-
#rvm? ⇒ Boolean
Determines whether the project prefers using RVM.
-
#to_gemspec {|gemspec| ... } ⇒ Gem::Specification
Populates a Gem Specification using the metadata of the project.
-
#warn(*messages) ⇒ Object
protected
Prints multiple warning messages.
-
#within(sub_dir = nil) { ... } ⇒ Object
Executes code within the project.
Methods included from Settings
#set_authors!, #set_date!, #set_default_executable!, #set_dependencies!, #set_development_dependencies!, #set_executables!, #set_extra_doc_files!, #set_files!, #set_license!, #set_post_install_message!, #set_require_paths!, #set_required_ruby_version!, #set_required_rubygems_version!, #set_requirements!, #set_runtime_dependencies!, #set_test_files!, #set_version!
Methods included from Inferences
#infer_date!, #infer_default_executable!, #infer_documentation!, #infer_executables!, #infer_extra_doc_files!, #infer_files!, #infer_name!, #infer_namespace!, #infer_project_files!, #infer_require_paths!, #infer_required_rubygems_version!, #infer_scm!, #infer_test_files!, #infer_version!
Methods included from Naming
#module_of, #modules_of, #names_in, #namespace_dirs_of, #namespace_of, #namespace_path_of, #underscore
Methods included from Checks
#check_directory, #check_executable, #check_file, #check_readable
Methods included from Paths
#bin_dir, #directory?, #file?, #glob, #lib_dir, #lib_directory?, #lib_file?, #lib_path, #path, #pkg_dir, #pkg_file
Constructor Details
#initialize(root = Dir.pwd) ⇒ Project
Creates a new Ore::Project.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/ore/project.rb', line 129 def initialize(root=Dir.pwd) @root = Pathname.new(root). unless @root.directory? raise(ProjectNotFound,"#{@root} is not a directory") end infer_scm! infer_project_files! = @root.join(@@metadata_file) unless .file? raise(ProjectNotFound,"#{@root} does not contain #{@@metadata_file}") end = YAML.load_file() unless .kind_of?(Hash) raise(InvalidMetadata,"#{} did not contain valid metadata") end if ['name'] @name = ['name'].to_s else infer_name! end # infer the namespace from the project name infer_namespace! if ['version'] set_version! ['version'] else infer_version! end @summary = (['summary'] || ['description']) @description = (['description'] || ['summary']) @licenses = [] if ['license'] set_license!(['license']) end @authors = [] if ['authors'] ['authors'] end @homepage = ['homepage'] @email = ['email'] if ['date'] set_date! ['date'] else infer_date! end @document = DocumentFile.find(self) @require_paths = [] if ['require_paths'] set_require_paths! ['require_paths'] else infer_require_paths! end @executables = [] if ['executables'] set_executables! ['executables'] else infer_executables! end @default_executable = nil if ['default_executable'] set_default_executable! ['default_executable'] else infer_default_executable! end if ['has_yard'] @documentation = :yard elsif .has_key?('has_rdoc') @documentation = if ['has_rdoc'] :rdoc end else infer_documentation! end @extra_doc_files = [] if ['extra_doc_files'] set_extra_doc_files! ['extra_doc_files'] else infer_extra_doc_files! end @files = [] if ['files'] set_files! ['files'] else infer_files! end @test_files = [] if ['test_files'] set_test_files! ['test_files'] else infer_test_files! end if ['post_install_message'] ['post_install_message'] end @requirements = [] if ['requirements'] set_requirements! ['requirements'] end if ['required_ruby_version'] set_required_ruby_version! ['required_ruby_version'] end if ['required_rubygems_version'] set_required_rubygems_version! ['required_rubygems_version'] else infer_required_rubygems_version! end @dependencies = [] if ['dependencies'] set_dependencies! ['dependencies'] end @runtime_dependencies = [] if ['runtime_dependencies'] set_runtime_dependencies! ['runtime_dependencies'] end @development_dependencies = [] if ['development_dependencies'] set_development_dependencies! ['development_dependencies'] end end |
Instance Attribute Details
#authors ⇒ Object (readonly)
The authors of the project
67 68 69 |
# File 'lib/ore/project.rb', line 67 def @authors end |
#date ⇒ Object (readonly)
The build date for any project gems
76 77 78 |
# File 'lib/ore/project.rb', line 76 def date @date end |
#default_executable ⇒ Object (readonly)
The default executable
88 89 90 |
# File 'lib/ore/project.rb', line 88 def default_executable @default_executable end |
#dependencies ⇒ Object (readonly)
The dependencies of the project
112 113 114 |
# File 'lib/ore/project.rb', line 112 def dependencies @dependencies end |
#description ⇒ Object (readonly)
The project description
61 62 63 |
# File 'lib/ore/project.rb', line 61 def description @description end |
#development_dependencies ⇒ Object (readonly)
The development-dependencies of the project
118 119 120 |
# File 'lib/ore/project.rb', line 118 def development_dependencies @development_dependencies end |
#document ⇒ Object (readonly)
The parsed .document file
79 80 81 |
# File 'lib/ore/project.rb', line 79 def document @document end |
#documentation ⇒ Object (readonly)
The documentation of the project
91 92 93 |
# File 'lib/ore/project.rb', line 91 def documentation @documentation end |
#email ⇒ Object (readonly)
The email contact for the project
73 74 75 |
# File 'lib/ore/project.rb', line 73 def email @email end |
#executables ⇒ Object (readonly)
The names of the executable scripts
85 86 87 |
# File 'lib/ore/project.rb', line 85 def executables @executables end |
#extra_doc_files ⇒ Object (readonly)
Any extra files to include in the project documentation
94 95 96 |
# File 'lib/ore/project.rb', line 94 def extra_doc_files @extra_doc_files end |
#files ⇒ Object (readonly)
The files of the project
97 98 99 |
# File 'lib/ore/project.rb', line 97 def files @files end |
#homepage ⇒ Object (readonly)
The homepage for the project
70 71 72 |
# File 'lib/ore/project.rb', line 70 def homepage @homepage end |
#licenses ⇒ Object (readonly)
The licenses of the project
64 65 66 |
# File 'lib/ore/project.rb', line 64 def licenses @licenses end |
#name ⇒ Object (readonly)
The name of the project
52 53 54 |
# File 'lib/ore/project.rb', line 52 def name @name end |
#namespace ⇒ Object (readonly)
The fully-qualified namespace of the project
43 44 45 |
# File 'lib/ore/project.rb', line 43 def namespace @namespace end |
#namespace_dir ⇒ Object (readonly)
The directory contain the project code.
49 50 51 |
# File 'lib/ore/project.rb', line 49 def namespace_dir @namespace_dir end |
#namespace_modules ⇒ Object (readonly)
The inferred namespace modules of the project
46 47 48 |
# File 'lib/ore/project.rb', line 46 def namespace_modules @namespace_modules end |
#post_install_message ⇒ Object (readonly)
The post-installation message
121 122 123 |
# File 'lib/ore/project.rb', line 121 def @post_install_message end |
#project_files ⇒ Object (readonly)
The files of the project
40 41 42 |
# File 'lib/ore/project.rb', line 40 def project_files @project_files end |
#require_paths ⇒ Object (readonly)
The directories to search within the project when requiring files
82 83 84 |
# File 'lib/ore/project.rb', line 82 def require_paths @require_paths end |
#required_ruby_version ⇒ Object (readonly)
The version of Ruby required by the project
106 107 108 |
# File 'lib/ore/project.rb', line 106 def required_ruby_version @required_ruby_version end |
#required_rubygems_version ⇒ Object (readonly)
The version of RubyGems required by the project
109 110 111 |
# File 'lib/ore/project.rb', line 109 def required_rubygems_version @required_rubygems_version end |
#requirements ⇒ Object (readonly)
Any external requirements needed by the project
103 104 105 |
# File 'lib/ore/project.rb', line 103 def requirements @requirements end |
#root ⇒ Object (readonly)
The root directory of the project
34 35 36 |
# File 'lib/ore/project.rb', line 34 def root @root end |
#runtime_dependencies ⇒ Object (readonly)
The runtime-dependencies of the project
115 116 117 |
# File 'lib/ore/project.rb', line 115 def runtime_dependencies @runtime_dependencies end |
#scm ⇒ Object (readonly)
The SCM which the project is currently under
37 38 39 |
# File 'lib/ore/project.rb', line 37 def scm @scm end |
#summary ⇒ Object (readonly)
The project summary
58 59 60 |
# File 'lib/ore/project.rb', line 58 def summary @summary end |
#test_files ⇒ Object (readonly)
The test files for the project
100 101 102 |
# File 'lib/ore/project.rb', line 100 def test_files @test_files end |
#version ⇒ Object (readonly)
The version of the project
55 56 57 |
# File 'lib/ore/project.rb', line 55 def version @version end |
Class Method Details
.find(dir = Dir.pwd) ⇒ Project
Finds the project metadata file and creates a new Ore::Project object.
301 302 303 304 305 306 307 |
# File 'lib/ore/project.rb', line 301 def self.find(dir=Dir.pwd) Pathname.new(dir).ascend do |root| return self.new(root) if root.join(@@metadata_file).file? end raise(ProjectNotFound,"could not find #{@@metadata_file}") end |
Instance Method Details
#add_executable(name) ⇒ Object (protected)
Adds an executable to the project.
532 533 534 535 536 |
# File 'lib/ore/project.rb', line 532 def add_executable(name) path = File.join(@@bin_dir,name) check_executable(path) { |exe| @executables << exe } end |
#add_extra_doc_file(path) ⇒ Object (protected)
Adds an extra documentation file to the project.
544 545 546 |
# File 'lib/ore/project.rb', line 544 def add_extra_doc_file(path) check_file(path) { |file| @extra_doc_files << file } end |
#add_file(path) ⇒ Object (protected)
Adds a file to the project.
554 555 556 |
# File 'lib/ore/project.rb', line 554 def add_file(path) check_file(path) { |file| @files << file } end |
#add_require_path(path) ⇒ Object (protected)
Adds a require-path to the project.
522 523 524 |
# File 'lib/ore/project.rb', line 522 def add_require_path(path) check_directory(path) { |dir| @require_paths << dir } end |
#add_test_file(path) ⇒ Object (protected)
Adds a testing-file to the project.
564 565 566 |
# File 'lib/ore/project.rb', line 564 def add_test_file(path) check_file(path) { |file| @test_files << file } end |
#build! ⇒ Pathname
Builds a gem for the project.
493 494 495 496 497 498 499 500 501 502 |
# File 'lib/ore/project.rb', line 493 def build! pkg_dir = @root.join(@@pkg_dir) FileUtils.mkdir_p(pkg_dir) gem_file = Gem::Builder.new(self.to_gemspec).build pkg_path = @root.join(pkg_file) FileUtils.mv(gem_file,pkg_path) return pkg_path end |
#bundled? ⇒ Boolean
Determines whether the project has been bundled using Bundler.
371 372 373 |
# File 'lib/ore/project.rb', line 371 def bundled? file?('Gemfile.lock') end |
#bundler? ⇒ Boolean
Determines whether the project uses Bundler.
361 362 363 |
# File 'lib/ore/project.rb', line 361 def bundler? file?('Gemfile') end |
#has_rdoc ⇒ Boolean Also known as: has_rdoc?
Determines if the project contains RDoc documentation.
381 382 383 |
# File 'lib/ore/project.rb', line 381 def has_rdoc @documentation == :rdoc end |
#has_yard ⇒ Boolean Also known as: has_yard?
Determines if the project contains YARD documentation.
393 394 395 |
# File 'lib/ore/project.rb', line 393 def has_yard @documentation == :yard end |
#license ⇒ String?
The primary license of the project.
338 339 340 |
# File 'lib/ore/project.rb', line 338 def license @licenses.first end |
#rvm? ⇒ Boolean
Determines whether the project prefers using RVM.
351 352 353 |
# File 'lib/ore/project.rb', line 351 def rvm? file?('.rvmrc') end |
#to_gemspec {|gemspec| ... } ⇒ Gem::Specification
Populates a Gem Specification using the metadata of the project.
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/ore/project.rb', line 414 def to_gemspec Gem::Specification.new do |gemspec| gemspec.name = @name.to_s gemspec.version = @version.to_s gemspec.summary = @summary.to_s gemspec.description = @description.to_s gemspec.licenses = @licenses gemspec. = @authors gemspec.homepage = @homepage gemspec.email = @email gemspec.date = @date @require_paths.each do |path| unless gemspec.require_paths.include?(path) gemspec.require_paths << path end end gemspec.executables = @executables gemspec.default_executable = @default_executable if has_yard gemspec.has_rdoc = 'yard' end gemspec.extra_rdoc_files = @extra_doc_files gemspec.files = @files gemspec.test_files = @test_files gemspec. = @post_install_message gemspec.requirements = @requirements if gemspec.respond_to?(:required_ruby_version=) gemspec.required_ruby_version = @required_ruby_version end if gemspec.respond_to?(:required_rubygems_version=) gemspec.required_rubygems_version = @required_rubygems_version end @dependencies.each do |dep| gemspec.add_dependency(dep.name,*dep.versions) end if gemspec.respond_to?(:add_runtime_dependency) @runtime_dependencies.each do |dep| gemspec.add_runtime_dependency(dep.name,*dep.versions) end else @runtime_dependencies.each do |dep| gemspec.add_dependency(dep.name,*dep.versions) end end if gemspec.respond_to?(:add_development_dependency) @development_dependencies.each do |dep| gemspec.add_development_dependency(dep.name,*dep.versions) end else @development_dependencies.each do |dep| gemspec.add_dependency(dep.name,*dep.versions) end end # legacy information if gemspec.respond_to?(:rubyforge_project=) gemspec.rubyforge_project = gemspec.name end yield gemspec if block_given? end end |
#warn(*messages) ⇒ Object (protected)
Prints multiple warning messages.
512 513 514 |
# File 'lib/ore/project.rb', line 512 def warn(*) .each { |mesg| STDERR.puts("WARNING: #{mesg}") } end |
#within(sub_dir = nil) { ... } ⇒ Object
Executes code within the project.
322 323 324 325 326 327 328 329 330 |
# File 'lib/ore/project.rb', line 322 def within(sub_dir=nil,&block) dir = if sub_dir @root.join(sub_dir) else @root end Dir.chdir(dir,&block) end |