Class: Setup::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/setup/base.rb

Overview

Common base class for all Setup build classes.

Direct Known Subclasses

Compiler, Documentor, Installer, Tester, Uninstaller

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, configuration, options = {}) ⇒ Base

Returns a new instance of Base.



32
33
34
35
36
37
38
39
40
41
# File 'lib/setup/base.rb', line 32

def initialize(project, configuration, options={})
  @project = project
  @config  = configuration

  initialize_hooks

  options.each do |k,v|
    __send__("#{k}=", v) if respond_to?("#{k}=")
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/setup/base.rb', line 14

def config
  @config
end

#forceObject

Returns the value of attribute force.



26
27
28
# File 'lib/setup/base.rb', line 26

def force
  @force
end

#ioObject

Returns the value of attribute io.



29
30
31
# File 'lib/setup/base.rb', line 29

def io
  @io
end

#projectObject (readonly)

Returns the value of attribute project.



11
12
13
# File 'lib/setup/base.rb', line 11

def project
  @project
end

#quietObject

Returns the value of attribute quiet.



23
24
25
# File 'lib/setup/base.rb', line 23

def quiet
  @quiet
end

#traceObject

Returns the value of attribute trace.



20
21
22
# File 'lib/setup/base.rb', line 20

def trace
  @trace
end

#trialObject

Returns the value of attribute trial.



17
18
19
# File 'lib/setup/base.rb', line 17

def trial
  @trial
end

Instance Method Details

#bash(*args) ⇒ Object Also known as: command

Shellout executation.



75
76
77
78
# File 'lib/setup/base.rb', line 75

def bash(*args)
  $stderr.puts args.join(' ') if trace?
  system(*args) or raise RuntimeError, "system(#{args.map{|a| a.inspect }.join(' ')}) failed"
end

#force?Boolean

Returns:

  • (Boolean)


67
# File 'lib/setup/base.rb', line 67

def force? ; @force ; end

#force_remove_file(path) ⇒ Object



116
117
118
119
120
121
# File 'lib/setup/base.rb', line 116

def force_remove_file(path)
  begin
    remove_file(path)
  rescue
  end
end

#initialize_hooksObject

Hooking into the setup process, use extension scripts according to the name of the class. For instance to augment the behavior of the Installer, use:

.setup/installer.rb


49
50
51
52
53
54
55
# File 'lib/setup/base.rb', line 49

def initialize_hooks
  file = META_EXTENSION_DIR + "/#{self.class.name.downcase}.rb"
  if File.exist?(file)
    script = File.read(file)
    (class << self; self; end).class_eval(script)
  end
end

#quiet?Boolean

Returns:

  • (Boolean)


64
# File 'lib/setup/base.rb', line 64

def quiet? ; @quiet ; end

#remove_file(path) ⇒ Object



124
125
126
127
# File 'lib/setup/base.rb', line 124

def remove_file(path)
  File.chmod 0777, path
  File.unlink(path)
end

#rm_f(path) ⇒ Object



109
110
111
112
113
# File 'lib/setup/base.rb', line 109

def rm_f(path)
  io.puts "rm -f #{path}" if trace? or trial?
  return if trial?
  force_remove_file(path)
end

#rmdir(path) ⇒ Object



130
131
132
133
134
# File 'lib/setup/base.rb', line 130

def rmdir(path)
  io.puts "rmdir #{path}" if trace? or trial?
  return if trial?
  Dir.rmdir(path)
end

#rootdirObject



70
71
72
# File 'lib/setup/base.rb', line 70

def rootdir
  project.rootdir
end

#ruby(*args) ⇒ Object

Shellout a ruby command.



84
85
86
# File 'lib/setup/base.rb', line 84

def ruby(*args)
  bash(config.rubyprog, *args)
end

#trace?Boolean

Returns:

  • (Boolean)


61
# File 'lib/setup/base.rb', line 61

def trace? ; @trace ; end

#trace_offObject

:yield:



97
98
99
100
101
102
103
104
# File 'lib/setup/base.rb', line 97

def trace_off #:yield:
  begin
    save, @trace = trace?, false
    yield
  ensure
    @trace = save
  end
end

#trial?Boolean

Returns:

  • (Boolean)


58
# File 'lib/setup/base.rb', line 58

def trial? ; @trial ; end