Top Level Namespace
Defined Under Namespace
Modules: Bones Classes: Object, OpenStruct
Constant Summary collapse
- PROJ =
TODO: make my own openstruct type object that includes descriptions TODO: use the descriptions to output help on the available bones options
OpenStruct.new( # Project Defaults :name => nil, :summary => nil, :description => nil, :changes => nil, :authors => nil, :email => nil, :url => "\000", :version => ENV['VERSION'] || '0.0.0', :exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/), :release_name => ENV['RELEASE'], # System Defaults :ruby_opts => %w(-w), :libs => [], :history_file => 'History.txt', :readme_file => 'README.txt', :ignore_file => '.bnsignore', # Announce :ann => OpenStruct.new( :file => 'announcement.txt', :text => nil, :paragraphs => [], :email => { :from => nil, :to => %w([email protected]), :server => 'localhost', :port => 25, :domain => ENV['HOSTNAME'], :acct => nil, :passwd => nil, :authtype => :plain } ), # Gem Packaging :gem => OpenStruct.new( :dependencies => [], :development_dependencies => [], :executables => nil, :extensions => FileList['ext/**/extconf.rb'], :files => nil, :need_tar => true, :need_zip => false, :extras => {} ), # File Annotations :notes => OpenStruct.new( :exclude => %w(^tasks/setup\.rb$), :extensions => %w(.txt .rb .erb .rdoc) << '', :tags => %w(FIXME OPTIMIZE TODO) ), # Rcov :rcov => OpenStruct.new( :dir => 'coverage', :opts => %w[--sort coverage -T], :threshold => 90.0, :threshold_exact => false ), # Rdoc :rdoc => OpenStruct.new( :opts => [], :include => %w(^lib/ ^bin/ ^ext/ \.txt$ \.rdoc$), :exclude => %w(extconf\.rb$), :main => nil, :dir => 'doc', :remote_dir => nil ), # Rubyforge :rubyforge => OpenStruct.new( :name => "\000" ), # Rspec :spec => OpenStruct.new( :files => FileList['spec/**/*_spec.rb'], :opts => [] ), # Subversion Repository :svn => OpenStruct.new( :root => nil, :path => '', :trunk => 'trunk', :tags => 'tags', :branches => 'branches' ), # Test::Unit :test => OpenStruct.new( :files => FileList['test/**/test_*.rb'], :file => 'test/all.rb', :opts => [] ) )
- DEV_NULL =
Setup some constants
File.exist?('/dev/null') ? '/dev/null' : 'NUL:'
- DIFF =
if system("gdiff '#{__FILE__}' '#{__FILE__}' > #{DEV_NULL} 2>&1") then 'gdiff' else 'diff' end
- SUDO =
if system("which sudo > #{DEV_NULL} 2>&1") then 'sudo' else '' end
- RCOV =
"#{RUBY} -S rcov"- RDOC =
"#{RUBY} -S rdoc"- GEM =
"#{RUBY} -S gem"- HAVE_SVN =
(Dir.entries(Dir.pwd).include?('.svn') and system("svn --version 2>&1 > #{DEV_NULL}"))
- HAVE_GIT =
(Dir.entries(Dir.pwd).include?('.git') and system("git --version 2>&1 > #{DEV_NULL}"))
Instance Method Summary collapse
-
#depend_on(name, version = nil) ⇒ Object
Adds the given gem name to the current project’s dependency list.
-
#ensure_in_path(*args) ⇒ Object
Adds the given arguments to the include path if they are not already there.
-
#in_directory(dir, &block) ⇒ Object
Change working directories to dir, call the block of code, and then change back to the original working directory (the current directory when this method was called).
-
#manifest ⇒ Object
Scans the current working directory and creates a list of files that are candidates to be in the manifest.
-
#paragraphs_of(path, *paragraphs) ⇒ Object
Reads a file at
pathand spits out an array of theparagraphsspecified. - #quiet(&block) ⇒ Object
-
#remove_desc_for_task(names) ⇒ Object
Find a rake task using the task name and remove any description text.
Instance Method Details
#depend_on(name, version = nil) ⇒ Object
Adds the given gem name to the current project’s dependency list. An optional gem version can be given. If omitted, the newest gem version will be used.
203 204 205 206 207 208 209 210 211 |
# File 'lib/bones/tasks/setup.rb', line 203 def depend_on( name, version = nil ) spec = Gem.source_index.find_name(name).last version = spec.version.to_s if version.nil? and !spec.nil? PROJ.gem.dependencies << case version when nil; [name] when %r/^\d/; [name, ">= #{version}"] else [name, version] end end |
#ensure_in_path(*args) ⇒ Object
Adds the given arguments to the include path if they are not already there
215 216 217 218 219 220 |
# File 'lib/bones/tasks/setup.rb', line 215 def ensure_in_path( *args ) args.each do |path| path = File.(path) $:.unshift(path) if test(?d, path) and not $:.include?(path) end end |
#in_directory(dir, &block) ⇒ Object
Change working directories to dir, call the block of code, and then change back to the original working directory (the current directory when this method was called).
237 238 239 240 241 242 243 244 245 |
# File 'lib/bones/tasks/setup.rb', line 237 def in_directory( dir, &block ) curdir = pwd begin cd dir return block.call ensure cd curdir end end |
#manifest ⇒ Object
Scans the current working directory and creates a list of files that are candidates to be in the manifest.
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 |
# File 'lib/bones/tasks/setup.rb', line 250 def manifest files = [] exclude = PROJ.exclude.dup comment = %r/^\s*#/ # process the ignore file and add the items there to the exclude list if test(?f, PROJ.ignore_file) ary = [] File.readlines(PROJ.ignore_file).each do |line| next if line =~ comment line.chomp! line.strip! next if line.nil? or line.empty? glob = line =~ %r/\*\./ ? File.join('**', line) : line Dir.glob(glob).each {|fn| ary << "^#{Regexp.escape(fn)}"} end exclude.concat ary end # generate a regular expression from the exclude list exclude = Regexp.new(exclude.join('|')) Find.find '.' do |path| path.sub! %r/^(\.\/|\/)/o, '' next unless test ?f, path next if path =~ exclude files << path end files.sort! end |
#paragraphs_of(path, *paragraphs) ⇒ Object
Reads a file at path and spits out an array of the paragraphs specified.
changes = paragraphs_of('History.txt', 0..1).join("\n\n")
summary, *description = paragraphs_of('README.txt', 3, 3..8)
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/bones/tasks/setup.rb', line 175 def paragraphs_of( path, *paragraphs ) title = String === paragraphs.first ? paragraphs.shift : nil ary = File.read(path).delete("\r").split(/\n\n+/) result = if title tmp, matching = [], false rgxp = %r/^=+\s*#{Regexp.escape(title)}/i paragraphs << (0..-1) if paragraphs.empty? ary.each do |val| if val =~ rgxp break if matching matching = true rgxp = %r/^=+/i elsif matching tmp << val end end tmp else ary end result.values_at(*paragraphs) end |
#quiet(&block) ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/bones/tasks/setup.rb', line 129 def quiet( &block ) io = [STDOUT.dup, STDERR.dup] STDOUT.reopen DEV_NULL STDERR.reopen DEV_NULL block.call ensure STDOUT.reopen io.first STDERR.reopen io.last $stdout, $stderr = STDOUT, STDERR end |
#remove_desc_for_task(names) ⇒ Object
Find a rake task using the task name and remove any description text. This will prevent the task from being displayed in the list of available tasks.
225 226 227 228 229 230 231 |
# File 'lib/bones/tasks/setup.rb', line 225 def remove_desc_for_task( names ) Array(names).each do |task_name| task = Rake.application.tasks.find {|t| t.name == task_name} next if task.nil? task.instance_variable_set :@comment, nil end end |