Class: ProjectInfo
- Inherits:
-
Object
- Object
- ProjectInfo
- Defined in:
- lib/reap/projectinfo.rb
Overview
– NOTE At some point get past the use of the global variable perhaps? ++
Defined Under Namespace
Classes: HashBuilder
Constant Summary collapse
- INFO_FILES =
[ 'ProjectInfo', 'ReapFile', 'projectinfo', 'reapfile' ]
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#info_dir ⇒ Object
readonly
Returns the value of attribute info_dir.
-
#info_file ⇒ Object
readonly
Returns the value of attribute info_file.
-
#info_stream ⇒ Object
readonly
Returns the value of attribute info_stream.
Class Method Summary collapse
-
.find ⇒ Object
Find project information file.
-
.load(fpath = nil, report = false) ⇒ Object
Load the project information from a file.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Information fetch.
-
#[]=(name, x) ⇒ Object
Information sore.
-
#defaults ⇒ Object
Project information defaults.
-
#define(&block) ⇒ Object
Define project information programmatically.
-
#exists? ⇒ Boolean
Project information file exists? (may need to change to info exists?).
-
#initialize(&block) ⇒ ProjectInfo
constructor
A new instance of ProjectInfo.
-
#read(fpath, report = true) ⇒ Object
Load project information from YAML file.
-
#to_h ⇒ Object
Information to hash.
-
#update(info = nil, &block) ⇒ Object
Update project information.
-
#validate ⇒ Object
Validate project information.
Constructor Details
#initialize(&block) ⇒ ProjectInfo
Returns a new instance of ProjectInfo.
59 60 61 62 63 64 65 66 |
# File 'lib/reap/projectinfo.rb', line 59 def initialize( &block ) @info = {} @info_stream = nil define( &block ) if block_given? $PROJECT_INFO = self end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
57 58 59 |
# File 'lib/reap/projectinfo.rb', line 57 def info @info end |
#info_dir ⇒ Object (readonly)
Returns the value of attribute info_dir.
57 58 59 |
# File 'lib/reap/projectinfo.rb', line 57 def info_dir @info_dir end |
#info_file ⇒ Object (readonly)
Returns the value of attribute info_file.
57 58 59 |
# File 'lib/reap/projectinfo.rb', line 57 def info_file @info_file end |
#info_stream ⇒ Object (readonly)
Returns the value of attribute info_stream.
57 58 59 |
# File 'lib/reap/projectinfo.rb', line 57 def info_stream @info_stream end |
Class Method Details
.find ⇒ Object
Find project information file.
41 42 43 44 45 46 47 48 |
# File 'lib/reap/projectinfo.rb', line 41 def find info_dir, info_file = nil, nil Dir.ascend(Dir.pwd) do |info_dir| info_file = INFO_FILES.find{ |f| File.file?( File.join( info_dir, f ) ) } break if info_file end return File.join( info_dir, info_file ) end |
.load(fpath = nil, report = false) ⇒ Object
Load the project information from a file. Generally no file needs to be specified; the file will be found by ascending up the current path until a default file name is found (eg. ProjectInfo or Reapfile).
31 32 33 34 35 36 37 |
# File 'lib/reap/projectinfo.rb', line 31 def load( fpath=nil, report=false ) if fpath new.read( fpath, report ) else new.read( find, report ) end end |
Instance Method Details
#[](name) ⇒ Object
Information fetch.
150 151 152 |
# File 'lib/reap/projectinfo.rb', line 150 def [](name) info[name] end |
#[]=(name, x) ⇒ Object
Information sore.
156 157 158 |
# File 'lib/reap/projectinfo.rb', line 156 def []=(name, x) info[name] = x end |
#defaults ⇒ Object
Project information defaults.
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/reap/projectinfo.rb', line 135 def defaults self['title'] ||= self['name'].capitalize self['series'] ||= '1' self['date'] ||= Time.now.strftime("%Y-%m-%d") self['author'] ||= "Anonymous" self['maintainer'] ||= self['author'] self['arch'] ||= 'Any' self['license'] ||= 'Ruby/GPL' self['status'] ||= 'Beta' self['project'] ||= self['rubyforge'] ? self['rubyforge']['project'] : nil self['homepage'] ||= self['rubyforge'] ? self['rubyforge']['homepage'] : nil end |
#define(&block) ⇒ Object
Define project information programmatically.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/reap/projectinfo.rb', line 70 def define( &block ) return unless block @info = HashBuilder.new( &block ).to_h @info_stream = @info.to_yaml validate defaults self end |
#exists? ⇒ Boolean
Project information file exists? (may need to change to info exists?)
122 123 124 |
# File 'lib/reap/projectinfo.rb', line 122 def exists? @info_file end |
#read(fpath, report = true) ⇒ Object
Load project information from YAML file.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/reap/projectinfo.rb', line 84 def read( fpath, report=true ) return unless fpath @info_dir = File.dirname( fpath ) @info_file = fpath #File.basename( fpath ) @info_stream = File.read( fpath ).strip @info = YAML::load( info_stream ).traverse{ |k,v| [k.to_s.downcase, v] } Dir.chdir(@info_dir) if report puts "(in #{Dir.pwd})" #unless dir == Dir.pwd end validate defaults self end |
#to_h ⇒ Object
Information to hash.
162 163 164 |
# File 'lib/reap/projectinfo.rb', line 162 def to_h @info end |
#update(info = nil, &block) ⇒ Object
Update project information.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/reap/projectinfo.rb', line 105 def update( info=nil, &block ) if info @info.update( info.traverse{ |k,v| [k.to_s.downcase, v] } ) end if block_given? @info.update( HashBuilder.new( &block ).to_h ) end @info_stream = @info.to_yaml validate defaults self end |
#validate ⇒ Object
Validate project information.
128 129 130 131 |
# File 'lib/reap/projectinfo.rb', line 128 def validate raise "NAME is a required piece of information" unless info['name'] raise "VERSION is a required piece of informatiomn" unless info['version'] end |