Module: Reap::TaskUtils

Included in:
Announce, Doap, ExTest, Filer, Manifest, Package, Publish, RDoc, Test, TaskSpace, Tasks
Defined in:
lib/reap/taskutils.rb

Overview

Support module for task development.

Instance Method Summary collapse

Instance Method Details

#ask(question, answers = nil) ⇒ Object

Conveniene method to get simple console reply.



96
97
98
99
100
101
# File 'lib/reap/taskutils.rb', line 96

def ask( question, answers=nil )
  print "#{question}"
  print " [#{answers}] " if answers
  until inp = $stdin.gets[0,1] ; sleep 1 ; end ; puts
  inp
end

#initialize(data = {}) ⇒ Object

Useful for populating a class. Maybe this should have a different name –perhaps just use Facets #set_with.



53
54
55
56
57
# File 'lib/reap/taskutils.rb', line 53

def initialize( data={} )
  data.each do |k,v|
    send( "#{k}=", v ) if respond_to?("#{k}=")
  end
end

#masterObject

OpenCascade interface to teh ProjectInfo file.



61
62
63
# File 'lib/reap/taskutils.rb', line 61

def master
  @taskutils_master ||= ProjectInfo.instance.to_opencascade
end

#preq_from_name(name) ⇒ Object

If name is a hash this will split the name => preq parameter into [name, preq], otherwise it just return name. Teh hash is expected to have only one element.



69
70
71
72
73
74
75
76
# File 'lib/reap/taskutils.rb', line 69

def preq_from_name( name )
  if Hash === name
    #a = [name.keys, name.values].flatten
    return *(name.to_a.flatten)
  else
    name
  end
end

#provide_setup_rb(trunk = '.') ⇒ Object

Makes sure there is a setup.rb file in the project directory.



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/reap/taskutils.rb', line 106

def provide_setup_rb( trunk='.' )
  setup_rb_file = File.join( trunk, 'setup.rb' )
  return true if File.exists?( setup_rb_file )
  if dir = Gem.gempath('reap')
    src = File.join( dir, 'data', 'reap', 'setup.rb' )
  else
    src = File.join( Config::CONFIG['datadir'], 'reap', 'setup.rb' )
  end
  if File.exists?( src )
    FileUtils.cp( src, trunk )
    true
  end
end

#sh(arg) ⇒ Object

Output and then shellout a command. Doesn’t actually shellout if $PRETEND is set.



81
82
83
84
# File 'lib/reap/taskutils.rb', line 81

def sh( arg )
  tell arg
  system arg unless $PRETEND
end

#tell(statement) ⇒ Object

Convenience method for puts. Using this instead of puts may help beautify or redirect output in future versions.



90
91
92
# File 'lib/reap/taskutils.rb', line 90

def tell( statement )
  puts statement
end