Class: Setup::Project
- Inherits:
-
Object
- Object
- Setup::Project
- Defined in:
- lib/setup/project.rb
Overview
The Project class encapsulates information about the project/package setup is handling.
Setup.rb can use information about your project to provide additional features.
To inform Setup.rb of the project’s name, version and load path you can create a file in you project’s root directory called ‘.index`. This is a YAML file with minimum entries of:
---
name: foo
version: 1.0.0
paths:
load: [lib]
See [Indexer](github.com/rubyworks/indexer) for more information about this file and how to easily maintain it.
If a ‘.index` file is not found Setup.rb will look for `.setup/name`, `.setup/version` and `.setup/loadpath` files for this information.
As of v5.1.0, Setup.rb no longer recognizes the VERSION file
Constant Summary collapse
- ROOT_MARKER =
Match used to determine the root dir of a project.
'{.index,setup.rb,.setup,lib/}'
Instance Attribute Summary collapse
-
#dotindex ⇒ Object
readonly
Returns the value of attribute dotindex.
-
#loadpath ⇒ Object
(also: #load_path)
readonly
Returns the value of attribute loadpath.
-
#name ⇒ Object
readonly
The name of the package, used to install docs in system doc/ruby-#name/ location.
-
#version ⇒ Object
readonly
Current version number of project.
Instance Method Summary collapse
- #compiles? ⇒ Boolean
- #document ⇒ Object
-
#extconfs ⇒ Object
Setup.rb uses ‘ext/**/extconf.rb` as convention for the location of compiled scripts.
- #extensions ⇒ Object
-
#find(glob, flags = 0) ⇒ Object
Find a file relative to project’s root directory.
-
#initialize ⇒ Project
constructor
A new instance of Project.
-
#rootdir ⇒ Object
Locate project root.
- #yardopts ⇒ Object
Constructor Details
#initialize ⇒ Project
Returns a new instance of Project.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/setup/project.rb', line 33 def initialize @dotindex_file = find('.index') @dotindex = YAML.load_file(@dotindex_file) if @dotindex_file @name = nil @version = nil @loadpath = ['lib'] if @dotindex @name = @dotindex['name'] @version = @dotindex['version'] @loadpath = (@dotindex['paths'] || {})['load'] else if file = find('.setup/name') @name = File.read(file).strip end if file = find('.setup/version') @version = File.read(file).strip end if file = find('.setup/loadpath') @loadpath = File.read(file).strip end end end |
Instance Attribute Details
#dotindex ⇒ Object (readonly)
Returns the value of attribute dotindex.
59 60 61 |
# File 'lib/setup/project.rb', line 59 def dotindex @dotindex end |
#loadpath ⇒ Object (readonly) Also known as: load_path
Returns the value of attribute loadpath.
68 69 70 |
# File 'lib/setup/project.rb', line 68 def loadpath @loadpath end |
#name ⇒ Object (readonly)
The name of the package, used to install docs in system doc/ruby-#name/ location.
62 63 64 |
# File 'lib/setup/project.rb', line 62 def name @name end |
#version ⇒ Object (readonly)
Current version number of project.
65 66 67 |
# File 'lib/setup/project.rb', line 65 def version @version end |
Instance Method Details
#compiles? ⇒ Boolean
96 97 98 |
# File 'lib/setup/project.rb', line 96 def compiles? !extensions.empty? end |
#document ⇒ Object
106 107 108 |
# File 'lib/setup/project.rb', line 106 def document Dir.glob(File.join(rootdir, '.document')).first end |
#extconfs ⇒ Object
Setup.rb uses ‘ext/**/extconf.rb` as convention for the location of compiled scripts.
86 87 88 |
# File 'lib/setup/project.rb', line 86 def extconfs @extconfs ||= Dir['ext/**/extconf.rb'] end |
#extensions ⇒ Object
91 92 93 |
# File 'lib/setup/project.rb', line 91 def extensions @extensions ||= extconfs.collect{ |f| File.dirname(f) } end |
#find(glob, flags = 0) ⇒ Object
Find a file relative to project’s root directory.
111 112 113 114 115 116 117 118 119 |
# File 'lib/setup/project.rb', line 111 def find(glob, flags=0) case flags when :casefold flags = File::FNM_CASEFOLD else flags = flags.to_i end Dir.glob(File.join(rootdir, glob), flags).first end |
#rootdir ⇒ Object
Locate project root.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/setup/project.rb', line 73 def rootdir @rootdir ||= ( root = Dir.glob(File.join(Dir.pwd, ROOT_MARKER), File::FNM_CASEFOLD).first if !root raise Error, "not a project directory" else Dir.pwd end ) end |
#yardopts ⇒ Object
101 102 103 |
# File 'lib/setup/project.rb', line 101 def yardopts Dir.glob(File.join(rootdir, '.yardopts')).first end |